Subversion Repositories HomeAutomation

Rev

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

Rev 1786 Rev 1806
Line 1... Line 1...
1
/* the display object who created the menu item */
1
/* the display object who created the menu item */
2
DtmfMenuItem.prototype.parentDisplay = null;
2
DtmfMenuItem.prototype.parentDisplay = null;
3
 
3
 
4
DtmfMenuItem.prototype.mode = 0;
4
DtmfMenuItem.prototype.mode = 0;
5
DtmfMenuItem.prototype.currentPhoneItem = 0;
5
DtmfMenuItem.prototype.currentPhoneItem = 0;
6
const numberOfItemsInPhonebook = 15;
6
DtmfMenuItem.prototype.numberOfItemsInPhonebook = 15;
7
DtmfMenuItem.prototype.PhoneNumberList = new Array();
7
DtmfMenuItem.prototype.PhoneNumberList = new Array();
-
 
8
DtmfMenuItem.prototype.PhoneNumberListKeys = new Array();
8
DtmfMenuItem.prototype.PhoneNumberListLatest = -1;
9
DtmfMenuItem.prototype.PhoneNumberListLatest = -1;
-
 
10
 
9
 
11
 
10
function DtmfMenuItem(parentDisplay, hd44789Object)
12
function DtmfMenuItem(parentDisplay, hd44789Object)
11
{
13
{
12
    var self = this;
14
    var self = this;
13
    this.parentDisplay = parentDisplay;
15
    this.parentDisplay = parentDisplay;
14
    this.display = hd44789Object;
16
    this.display = hd44789Object;
15
 
-
 
16
    if (!this.parentDisplay.myInitialArguments["SimpleDTMF"])
-
 
17
    {
-
 
18
        log(this.myName + ":" + this.myId + "> Failed to initialize, SimpleDTMF-config missing from config.\n");
-
 
19
        return;
-
 
20
    }
-
 
21
 
-
 
22
    this.myDTMFService = ServiceManager.getService("Can", "SimpleDTMF", this.parentDisplay.myInitialArguments["SimpleDTMF"]["Id"]);
-
 
23
    this.myDTMFService.registerEventCallback("newPhonenumber", function(args) { self.dtmfUpdate(args); });
-
 
24
    //this.myDTMFService.registerEventCallback("online", function(args) { self.dtmfOnline(); });
-
 
25
    this.dtmfOnline();
-
 
26
 
-
 
27
    this.myOnlinePhonebook = new OnlinePhonebook(function(phonenumber, persons) { self.phonebookLookupCallback(phonenumber, persons); });
-
 
28
 
-
 
29
    for (var i = 0; i <= numberOfItemsInPhonebook-1; i++)
-
 
30
    {
-
 
31
        this.PhoneNumberList[i] = new Array();
-
 
32
        this.PhoneNumberList[i]['time'] = "";
-
 
33
        this.PhoneNumberList[i]['number'] = "";
-
 
34
        this.PhoneNumberList[i]['persons'] = new Array();
-
 
35
    }
-
 
36
}
17
}
37
 
18
 
38
/* the display object who created the menu item */
19
/* the display object who created the menu item */
39
DtmfMenuItem.prototype.parentDisplay = null;
20
DtmfMenuItem.prototype.parentDisplay = null;
40
/* the display that we are writing to */
21
/* the display that we are writing to */
41
DtmfMenuItem.prototype.display = null;
22
DtmfMenuItem.prototype.display = null;
42
 
23
 
43
/* How often the display shall update [ms]*/
24
/* How often the display shall update [ms]*/
44
DtmfMenuItem.prototype.UpdateTime = 5000;
25
DtmfMenuItem.prototype.UpdateTime = 5000;
45
 
-
 
46
/* what DtmfMenuItem is left of this item, if used */
-
 
47
DtmfMenuItem.prototype.LeftItem = null;
-
 
48
/* what DtmfMenuItem is right of this item, if used */
-
 
49
DtmfMenuItem.prototype.RightItem = null;
-
 
50
/* what DtmfMenuItem is after of this item, if used */
-
 
51
DtmfMenuItem.prototype.PressEnterItem = null;
-
 
52
/* what DtmfMenuItem is before of this item, if used */
-
 
53
DtmfMenuItem.prototype.PressBackItem = null;
-
 
54
/* what DtmfMenuItem is below of this item, if used */
-
 
55
DtmfMenuItem.prototype.DownItem = null;
-
 
56
/* what DtmfMenuItem is abowe of this item, if used */
-
 
57
DtmfMenuItem.prototype.UpItem = null;
-
 
58
 
26
 
59
/*
27
/*
60
Standard events can be:
28
Standard events can be:
61
left, right, enter, back, up, down....
29
left, right, enter, back, up, down....
62
*/
30
*/
63
DtmfMenuItem.prototype.processEvent = function (event)
31
DtmfMenuItem.prototype.processEvent = function (event)
64
{
32
{
65
    switch (event)
33
    switch (event)
66
    {
34
    {
67
    case "left":
35
    case "left":
68
        if (this.mode == 0) {
36
        if (this.mode == 0) {
69
            this.parentDisplay.changeToLeft();
37
            this.parentDisplay.changeToLeft();
70
        } else {
38
        } else {
71
            this.currentPhoneItem--;
39
            this.currentPhoneItem--;
72
            if (this.currentPhoneItem < 0) {
40
            if (this.currentPhoneItem < 0) {
73
                this.currentPhoneItem = numberOfItemsInPhonebook-1;
41
                this.currentPhoneItem = this.numberOfItemsInPhonebook-1;
74
            }
-
 
75
for (n=0;0<=numberOfItemsInPhonebook;n++) {
-
 
76
if (this.PhoneNumberList[this.currentPhoneItem]['number'] != "")
-
 
77
break;
-
 
78
                this.currentPhoneItem--;
-
 
79
                if (this.currentPhoneItem < 0) {
-
 
80
                    this.currentPhoneItem = numberOfItemsInPhonebook-1;
-
 
81
                }              
-
 
82
            }
42
            }
83
        }
43
        }
84
        break;
44
        break;
85
 
45
 
86
    case "right":
46
    case "right":
87
        if (this.mode == 0) {
47
        if (this.mode == 0) {
88
            this.parentDisplay.changeToRight();
48
            this.parentDisplay.changeToRight();
89
        } else {
49
        } else {
90
            this.currentPhoneItem++;
50
            this.currentPhoneItem++;
91
            if (this.currentPhoneItem >= numberOfItemsInPhonebook) {
51
            if (this.currentPhoneItem >= this.numberOfItemsInPhonebook) {
92
                this.currentPhoneItem = 0;
-
 
93
            }
-
 
94
for (n=0;0<=numberOfItemsInPhonebook;n++) {
-
 
95
if (this.PhoneNumberList[this.currentPhoneItem]['number'] != "")
-
 
96
break;
-
 
97
            this.currentPhoneItem++;
-
 
98
                if (this.currentPhoneItem  >= numberOfItemsInPhonebook) {
-
 
99
                    this.currentPhoneItem = 0;
52
                this.currentPhoneItem = 0;
100
                }
-
 
101
            }
53
            }
102
        }
54
        }
103
        break;
55
        break;
104
   
56
   
105
    case "up":
57
    case "up":
106
        //parentDisplay.changeToUp();
58
        //parentDisplay.changeToUp();
107
        break;
59
        break;
108
   
60
   
109
    case "down":
61
    case "down":
110
        //parentDisplay.changeToDown();
62
        //parentDisplay.changeToDown();
111
        break;
63
        break;
112
   
64
   
113
    case "enter":
65
    case "enter":
114
 
-
 
-
 
66
        //Log("DTMF onEnter\n");
115
        if (this.mode == 0) {
67
        if (this.mode == 0) {
116
            if (this.PhoneNumberList[this.PhoneNumberListLatest] != null) {
-
 
117
                this.currentPhoneItem = this.PhoneNumberListLatest;
68
            this.currentPhoneItem = 0;
118
                this.mode = 1;
69
            this.mode = 1;
119
            }
-
 
120
        } else {
70
        } else {
121
            this.mode = 0;
71
            this.mode = 0;
122
        }
72
        }
123
        break;
73
        break;
124
   
74
   
125
    case "back":
75
    case "back":
126
        //parentDisplay.changeToBack();
76
        //parentDisplay.changeToBack();
127
        break;
77
        break;
128
    }
78
    }
129
}
79
}
130
 
80
 
131
DtmfMenuItem.prototype.onEnter = function ()
81
DtmfMenuItem.prototype.onEnter = function ()
132
{
82
{
-
 
83
    this.PhoneNumberList = Storage_GetParameters("PhoneCalls");
-
 
84
    if (this.PhoneNumberList)
-
 
85
    {
-
 
86
 
-
 
87
        for(k in this.PhoneNumberList)
-
 
88
        {
-
 
89
                this.PhoneNumberListKeys.push(k);
-
 
90
            //Log("hittade: "+k+"\n");
-
 
91
        }
-
 
92
        this.PhoneNumberListKeys.sort(function(a, b) {return b - a;});
-
 
93
        if (this.PhoneNumberListKeys.length > this.numberOfItemsInPhonebook) {
-
 
94
            this.PhoneNumberListKeys.slice(0, this.numberOfItemsInPhonebook-1);
-
 
95
        }              
-
 
96
    } else {
-
 
97
        //No calls found, clear list?
-
 
98
        Log("hittade inga nummer!\n");
-
 
99
    }
-
 
100
    this.currentPhoneItem = 0;
-
 
101
    this.numberOfItemsInPhonebook = this.PhoneNumberListKeys.length;
133
    this.display.clearScreen();
102
    Display_Clear(this.display);
-
 
103
    this.mode = 0;
134
}
104
}
135
DtmfMenuItem.prototype.update = function ()
105
DtmfMenuItem.prototype.update = function ()
136
{
106
{
137
    if (this.mode == 0) {
107
    if (this.mode == 0) {
138
        if (this.PhoneNumberList[this.PhoneNumberListLatest] != null) {
108
        if (this.PhoneNumberListKeys[0] != null) {
139
this.display.clearScreen();
109
            Display_Clear(this.display);
140
            this.display.printText(0, 0, this.parentDisplay.lcdCenterText("Senaste nummer:"));
110
            Display_Print(this.display, 0, 0,"Senaste nummer:");
-
 
111
            var numbers = {};
141
            this.display.printText(0, 1, this.parentDisplay.lcdCenterText(""+this.PhoneNumberList[this.PhoneNumberListLatest]['time']));
112
            numbers  = eval("(" + this.PhoneNumberList[this.PhoneNumberListKeys[0]] + ")");
142
            this.display.printText(0, 2, this.parentDisplay.lcdCenterText(""+this.PhoneNumberList[this.PhoneNumberListLatest]['number']));
113
            var date = new Date(parseInt(this.PhoneNumberListKeys[0])*1000);
143
if (this.PhoneNumberList[this.PhoneNumberListLatest]['persons'][0] != null) {          
114
            Display_Print(this.display, 0, 1,""+date.getDateFormated()+" "+date.getTimeShortFormated());
144
this.display.printText(0, 3, this.parentDisplay.lcdCenterText(""+this.PhoneNumberList[this.PhoneNumberListLatest]['persons'][0]));
115
            Display_Print(this.display, 0, 2,""+numbers["number"]);
145
}
-
 
146
        } else {
116
        } else {
147
this.display.clearScreen();
117
            Display_Clear(this.display);
148
            this.display.printText(0, 0, this.parentDisplay.lcdCenterText("Senaste nummer:"));
118
            Display_Print(this.display, 0, 0,"SenAste nummer:");
149
            this.display.printText(0, 2, this.parentDisplay.lcdCenterText("Inga nummer"));
119
            Display_Print(this.display, 0, 2,"IngA nummer");
150
            this.display.printText(0, 3, this.parentDisplay.lcdCenterText("i listan!"));
120
            Display_Print(this.display, 0, 3,"i liStan!");
151
        }
121
        }
152
    } else {
122
    } else {
153
this.display.clearScreen();
123
        Display_Clear(this.display);
154
        this.display.printText(0, 0,this.parentDisplay.lcdCenterText(""+this.PhoneNumberList[this.currentPhoneItem]['time']));
124
        var numbers = {};
155
        this.display.printText(0, 1, this.parentDisplay.lcdCenterText(""+this.PhoneNumberList[this.currentPhoneItem]['number']));
-
 
156
if (this.PhoneNumberList[this.PhoneNumberListLatest]['persons'][0] != null) {
125
        numbers  = eval("(" + this.PhoneNumberList[this.PhoneNumberListKeys[this.currentPhoneItem]] + ")");
157
        this.display.printText(0, 2, this.parentDisplay.lcdCenterText(""+this.PhoneNumberList[this.currentPhoneItem]['persons'][0]));
126
        var date = new Date(parseInt(this.PhoneNumberListKeys[this.currentPhoneItem])*1000);
158
}
127
 
159
if (this.PhoneNumberList[this.PhoneNumberListLatest]['persons'][1] != null) {
128
        Display_Print(this.display, 0, 0,""+date.getDateFormated()+" "+date.getTimeShortFormated());
160
        this.display.printText(0, 3, this.parentDisplay.lcdCenterText(""+this.PhoneNumberList[this.currentPhoneItem]['persons'][1]));
129
        Display_Print(this.display, 0, 1,""+numbers["number"]);
161
}
-
 
162
    }
130
    }
163
}
131
}
164
 
132
 
165
DtmfMenuItem.prototype.onExit = function ()
133
DtmfMenuItem.prototype.onExit = function ()
166
{
134
{
167
    this.mode = 0;
135
    this.mode = 0;
168
}
136
}
169
 
-
 
170
 
-
 
171
DtmfMenuItem.prototype.dtmfOnline = function()
-
 
172
{
-
 
173
}
-
 
174
 
-
 
175
DtmfMenuItem.prototype.dtmfUpdate = function(args)
-
 
176
{
-
 
177
    this.myOnlinePhonebook.lookup(this.myDTMFService.getLastPhonenumber());
-
 
178
}
-
 
179
 
137
 
180
DtmfMenuItem.prototype.phonebookLookupCallback = function(phonenumber, persons)
-
 
181
{
-
 
182
    // Update main dtmf menu
-
 
183
    var date = new Date();
-
 
184
    /* Get the current date time on the format YYYY-mm-dd HH.ii.ss */
-
 
185
    var dateAndTime = date.getDateTimeFormated();
-
 
186
this.PhoneNumberListLatest++;
-
 
187
if (this.PhoneNumberListLatest >= numberOfItemsInPhonebook) {
-
 
188
this.PhoneNumberListLatest=0;
-
 
189
}
-
 
190
 
138
 
191
this.PhoneNumberList[this.PhoneNumberListLatest]['time'] = dateAndTime;
-
 
192
this.PhoneNumberList[this.PhoneNumberListLatest]['number'] = phonenumber;
-
 
193
this.PhoneNumberList[this.PhoneNumberListLatest]['persons'] = persons; 
-
 
194
}
-