Subversion Repositories HomeAutomation

Rev

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

Rev 969 Rev 971
Line 12... Line 12...
12
 
12
 
13
/* Declaration of instance variables, for static variables remove prototype */
13
/* Declaration of instance variables, for static variables remove prototype */
14
SensorPrint.prototype.myLCDService = null;
14
SensorPrint.prototype.myLCDService = null;
15
SensorPrint.prototype.myTempService = null;
15
SensorPrint.prototype.myTempService = null;
16
SensorPrint.prototype.myVoltService = null;
16
SensorPrint.prototype.myVoltService = null;
17
SensorPrint.prototype.myTimeoutId = null;
17
SensorPrint.prototype.myInterval = null;
18
 
18
 
19
/* This function must always be declared, this is where all the startup code
19
/* This function must always be declared, this is where all the startup code
20
   should be placed. Gets called with arguments like what ids to use etc. */
20
   should be placed. Gets called with arguments like what ids to use etc. */
21
SensorPrint.prototype.initialize = function(initialArguments)
21
SensorPrint.prototype.initialize = function(initialArguments)
22
{
22
{
Line 30... Line 30...
30
    this.myLCDService = ServiceManager.getService("Can", "HD44789", this.myInitialArguments["HD44789"]["Id"]);
30
    this.myLCDService = ServiceManager.getService("Can", "HD44789", this.myInitialArguments["HD44789"]["Id"]);
31
    /* Add a callback for when the service goes online */
31
    /* Add a callback for when the service goes online */
32
    this.myLCDService.registerEventCallback("online", function(args) { self.lcdOnline(); });
32
    this.myLCDService.registerEventCallback("online", function(args) { self.lcdOnline(); });
33
    /* If the service is already online we should call the handler here */
33
    /* If the service is already online we should call the handler here */
34
    this.lcdOnline();
34
    this.lcdOnline();
-
 
35
    /* Add a callback for when the service goes offline */
-
 
36
    this.myLCDService.registerEventCallback("offline", function(args) { self.lcdOffline(); });
35
 
37
 
36
    /* Get the LCD service that we want from the ServiceManager, it takes type, service name, service id */
38
    /* Get the LCD service that we want from the ServiceManager, it takes type, service name, service id */
37
    this.myTempService = ServiceManager.getService("Can", "DS18x20", this.myInitialArguments["DS18x20"]["Id"]);
39
    this.myTempService = ServiceManager.getService("Can", "DS18x20", this.myInitialArguments["DS18x20"]["Id"]);
38
    /* Add a callback for when the sensor reports a new value */
40
    /* Add a callback for when the sensor reports a new value */
39
    this.myTempService.registerEventCallback("newValue", function(args) { self.temperatureUpdate(args); });
41
    this.myTempService.registerEventCallback("newValue", function(args) { self.temperatureUpdate(args); });
Line 48... Line 50...
48
    this.myVoltService.registerEventCallback("newValue", function(args) { self.voltageUpdate(args); });
50
    this.myVoltService.registerEventCallback("newValue", function(args) { self.voltageUpdate(args); });
49
    /* Add a callback for when the service goes online */
51
    /* Add a callback for when the service goes online */
50
    this.myVoltService.registerEventCallback("online", function(args) { self.voltOnline(); });
52
    this.myVoltService.registerEventCallback("online", function(args) { self.voltOnline(); });
51
    /* If the service is already online we should call the handler here */
53
    /* If the service is already online we should call the handler here */
52
    this.voltOnline();
54
    this.voltOnline();
53
}
-
 
54
 
-
 
55
/* This method is static */
-
 
56
SensorPrint.timerCallback = function(type, name, id)
-
 
57
{
-
 
58
    /* Get the service instance and call the timer update */
-
 
59
    var service = ServiceManager.getService(type, name, id);
-
 
60
    service.timerUpdate();
-
 
61
}
55
}
62
 
56
 
63
SensorPrint.prototype.lcdOnline = function()
57
SensorPrint.prototype.lcdOnline = function()
64
{
58
{
65
    /* If service is not online do nothing */
59
    /* If service is not online do nothing */
66
    if (this.myLCDService.isOnline())
60
    if (this.myLCDService.isOnline())
67
    {
61
    {
68
        /* Clear the LCD screen */
62
        /* Clear the LCD screen */
69
        this.myLCDService.clearScreen();
63
        this.myLCDService.clearScreen();
70
        /* Set backlight to max */
64
        /* Set backlight to max */
71
        this.myLCDService.setBacklight(255);
65
        this.myLCDService.setBacklight(255);
72
 
66
 
73
        /* If we have no interval timer running start it */
67
        /* If we have no interval timer running start it */
74
        if (this.myTimeoutId == null)
68
        if (this.myInterval == null)
75
        {
69
        {
-
 
70
            var self = this;
-
 
71
       
76
            /* Start interval timer for our printout. Arguments are expression and time in seconds */
72
            /* Start interval timer for our printout. Arguments are the callback function and time in seconds */
77
            this.myTimeoutId = setInterval("SensorPrint.timerCallback('Logic', '" + this.myName + "', " + this.myId + ");", 1000);
73
            this.myInterval = new Interval(function() { self.timerUpdate() }, 1000);
-
 
74
        }
-
 
75
       
-
 
76
        this.myInterval.start();
-
 
77
    }
78
        }
78
}
-
 
79
 
-
 
80
SensorPrint.prototype.lcdOffline = function()
-
 
81
{
-
 
82
    /* If we have no interval timer running do nothing */
-
 
83
    if (this.myInterval != null)
-
 
84
    {
-
 
85
        /* Stop the interval */
-
 
86
        this.myInterval.stop();
79
    }
87
    }
80
}
88
}
81
 
89
 
82
SensorPrint.prototype.tempOnline = function()
90
SensorPrint.prototype.tempOnline = function()
83
{
91
{
Line 130... Line 138...
130
SensorPrint.prototype.timerUpdate = function()
138
SensorPrint.prototype.timerUpdate = function()
131
{
139
{
132
    /* If LCD service is not online do nothing */
140
    /* If LCD service is not online do nothing */
133
    if (this.myLCDService.isOnline())
141
    if (this.myLCDService.isOnline())
134
    {
142
    {
-
 
143
        var date = new Date();
135
        /* Get the current date time on the format YYYY-mm-dd HH.ii.ss */
144
        /* Get the current date time on the format YYYY-mm-dd HH.ii.ss */
136
        var dateAndTime = formatDateTime();
145
        var dateAndTime = date.getDateTimeFormated();
137
        /* Print the text to the LCD */
146
        /* Print the text to the LCD */
138
        this.myLCDService.printText(0, 3, dateAndTime);
147
        this.myLCDService.printText(0, 3, dateAndTime);
139
        /* Print out what we are doing to the console */
148
        /* Print out what we are doing to the console */
140
        log(this.myName + ":" + this.myId + "> Trying to print " + dateAndTime + " to LCD\n");
149
        log(this.myName + ":" + this.myId + "> Trying to print " + dateAndTime + " to LCD\n");
141
    }
150
    }