Subversion Repositories HomeAutomation

Rev

Rev 1349 | Go to most recent revision | Show entire file | Regard whitespace | Details | Blame | Last modification | View Log | SVN | RSS feed

Rev 1349 Rev 1351
Line 1... Line -...
1
 
-
 
2
MainMenuItem.prototype.humidity = 0;
-
 
3
MainMenuItem.prototype.CurrentPower = 0;
1
MainMenuItem.prototype.CurrentPower = 0;
4
MainMenuItem.prototype.CurrentEnergy = 0;
2
MainMenuItem.prototype.CurrentEnergy = 0;
5
const humiditySensorId = 1;
-
 
6
 
3
 
7
function MainMenuItem(parentDisplay, hd44789Object)
4
function MainMenuItem(parentDisplay, hd44789Object)
8
{
5
{
9
    this.parentDisplay = parentDisplay;
6
    this.parentDisplay = parentDisplay;
10
    this.display = hd44789Object;
7
    this.display = hd44789Object;
11
    var self = this;
8
    var self = this;
12
    if (!this.parentDisplay.myInitialArguments["power"])
9
    if (!this.parentDisplay.myInitialArguments["power"])
13
    {
10
    {
14
        log(this.myName + ":" + this.myId + "> Failed to initialize, power-config missing from config.\n");
11
        log(this.myName + ":" + this.myId + "> Failed to initialize, power-config missing from config.\n");
15
        return;
12
        return;
16
    }
-
 
17
    if (!this.parentDisplay.myInitialArguments["FOST02"])
-
 
18
    {
-
 
19
        log(this.myName + ":" + this.myId + "> Failed to initialize, FOST02-config missing from config.\n");
-
 
20
        return;
-
 
21
    }
13
    }
-
 
14
   
22
    /* Get the PWM service that we want from the ServiceManager, it takes type, service name, service id */
15
    /* Get the PWM service that we want from the ServiceManager, it takes type, service name, service id */
23
    this.myPowerService = ServiceManager.getService("Can", "power", this.parentDisplay.myInitialArguments["power"]["Id"]);
16
    this.myPowerService = ServiceManager.getService("Can", "power", this.parentDisplay.myInitialArguments["power"]["Id"]);
24
    /* Add a callback for when the service goes online */
17
    /* Add a callback for when the service goes online */
25
    this.myPowerService.registerEventCallback("online", function(args) { self.PowerOnline(); });
18
    this.myPowerService.registerEventCallback("online", function(args) { self.PowerOnline(); });
26
    /* Add a callback for when the sensor reports a new value */
19
    /* Add a callback for when the sensor reports a new value */
27
    this.myPowerService.registerEventCallback("newValue", function(args) { self.powerUpdate(); });
20
    this.myPowerService.registerEventCallback("newValue", function(args) { self.powerUpdate(); });
28
    /* If the service is already online we should call the handler here */
21
    /* If the service is already online we should call the handler here */
29
    this.PowerOnline();
22
    this.PowerOnline();
30
 
23
 
31
    /* Get the LCD service that we want from the ServiceManager, it takes type, service name, service id */
-
 
32
    this.myHumiService = ServiceManager.getService("Can", "FOST02", this.parentDisplay.myInitialArguments["FOST02"]["Id"]);
-
 
33
    /* Add a callback for when the sensor reports a new value */
-
 
34
    this.myHumiService.registerEventCallback("newHumidityValue", function(args) { self.humidityUpdate(args); });
-
 
35
 
-
 
36
}
-
 
37
 
24
 
38
MainMenuItem.prototype.humidityUpdate = function(sensorId)
-
 
39
{
-
 
40
    if (sensorId == humiditySensorId) {
-
 
41
        this.humidity = this.myHumiService.getValueHumi(sensorId).toFixed(2).toString();
-
 
42
    }
25
}
43
}
26
 
44
 
27
 
45
MainMenuItem.prototype.PowerOnline = function()
28
MainMenuItem.prototype.PowerOnline = function()
46
{
29
{
47
    /* If service is not online do nothing */
30
    /* If service is not online do nothing */
48
    if (this.myPowerService.isOnline())
31
    if (this.myPowerService.isOnline())
Line 121... Line 104...
121
MainMenuItem.prototype.update = function ()
104
MainMenuItem.prototype.update = function ()
122
{
105
{
123
    var date = new Date();
106
    var date = new Date();
124
    /* Get the current date time on the format YYYY-mm-dd HH.ii.ss */
107
    /* Get the current date time on the format YYYY-mm-dd HH.ii.ss */
125
    var dateAndTime = date.getDateFormated()+" "+date.getTimeShortFormated();
108
    var dateAndTime = date.getDateFormated()+" "+date.getTimeShortFormated();
126
    this.display.printText(0, 1, this.parentDisplay.lcdCenterText(""+ getSensorValue('Veranda').toFixed(1).toString() + " C   " + getSensorValue('Matrum').toFixed(1).toString() + "C"));
109
    this.display.printText(0, 1, this.parentDisplay.lcdCenterText(""+ getSensorValue('Vardagsrumssensor').toFixed(1).toString() + " C   " + getSensorValue('Västersensor').toFixed(1).toString() + "C"));
127
    this.display.printText(0, 0, this.parentDisplay.lcdCenterText(""+dateAndTime));
110
    this.display.printText(0, 0, this.parentDisplay.lcdCenterText(""+dateAndTime));
128
 
111
 
129
this.display.printText(0, 2, this.parentDisplay.lcdCenterText(""+getSensorValue('Utetemperatur').toFixed(1).toString() + " C   " + this.humidity + "%"));
112
    this.display.printText(0, 2, this.parentDisplay.lcdCenterText(""+ getSensorValue('Sovrumssensor').toFixed(1).toString() + " C   " + getSensorValue('Ă–stersensor').toFixed(1).toString() + "C"));
130
 
113
 
131
    this.display.printText(0, 3, this.parentDisplay.lcdCenterText(""+this.CurrentPower.toString()+" W  "+(this.CurrentEnergy/1000).toString() + "kWh"));
114
    this.display.printText(0, 3, this.parentDisplay.lcdCenterText(""+this.CurrentPower.toString()+" W  "+(this.CurrentEnergy/1000).toString() + "kWh"));
132
}
115
}
133
MainMenuItem.prototype.onExit = function ()
116
MainMenuItem.prototype.onExit = function ()
134
{
117
{