/* the display object who created the menu item */
DimmerMenuItem.prototype.parentDisplay = null;
DimmerMenuItem.prototype.dimmers = null;
DimmerMenuItem.prototype.mode = 0;
DimmerMenuItem.prototype.currentDimmerItem = 0;
function DimmerMenuItem(parentDisplay, hd44789Object)
{
var self = this;
this.parentDisplay = parentDisplay;
this.display = hd44789Object;
}
/* the display object who created the menu item */
DimmerMenuItem.prototype.parentDisplay = null;
/* the display that we are writing to */
DimmerMenuItem.prototype.display = null;
/* How often the display shall update [ms]*/
DimmerMenuItem.prototype.UpdateTime = 5000;
/* what DimmerMenuItem is left of this item, if used */
DimmerMenuItem.prototype.LeftItem = null;
/* what DimmerMenuItem is right of this item, if used */
DimmerMenuItem.prototype.RightItem = null;
/* what DimmerMenuItem is after of this item, if used */
DimmerMenuItem.prototype.PressEnterItem = null;
/*
Standard events can be:
left, right, enter, back, up, down....
*/
DimmerMenuItem.prototype.processEvent = function (event)
{
switch (event)
{
case "right":
if (this.mode == 0) {
this.parentDisplay.changeToRight();
} else if (this.mode == 1){
this.currentDimmerItem--;
if (this.currentDimmerItem == -1) {
this.mode = 2;
}
} else if (this.mode == 3){
this.dimmers[this.currentDimmerItem]['service'].relFade(this.dimmers[this.currentDimmerItem]['channel'],132, "Decrease", 25);
} else {
this.mode = 1;
this.currentDimmerItem= this.dimmers.length-1;
}
break;
case "left":
if (this.mode == 0) {
this.parentDisplay.changeToLeft();
} else if (this.mode == 1){
this.currentDimmerItem++;
if (this.currentDimmerItem == this.dimmers.length) {
this.mode = 2;
}
} else if (this.mode == 3){
this.dimmers[this.currentDimmerItem]['service'].relFade(this.dimmers[this.currentDimmerItem]['channel'],132, "Increase", 25);
} else {
this.mode = 1;
this.currentDimmerItem=0;
}
break;
case "enter":
if (this.mode == 0) {
if (this.dimmers.length > 0) {
this.currentDimmerItem = 0;
this.mode = 1;
}
} else if (this.mode == 1){
this.mode = 3;
} else if (this.mode == 3) {
this.mode = 1;
} else {
this.mode = 0;
}
break;
}
}
DimmerMenuItem.prototype.onEnter = function ()
{
this.dimmers = getDimmerList();
this.mode = 0;
this.display.clearScreen();
}
DimmerMenuItem.prototype.update = function ()
{
this.display.clearScreen();
if (this.mode != 2) {
for (var i = 0; i < this.dimmers.length && i < 4; i++) {
if (this.mode == 1 && this.currentDimmerItem == i) {
this.display.printText(0, i, this.parentDisplay.lcdCenterText("-"+ this.dimmers[i]['name'] + " " +getDimmerValue(this.dimmers[i]['name'])+"."));
} else if (this.mode == 3 && this.currentDimmerItem == i) {
this.display.printText(0, i, this.parentDisplay.lcdCenterText("<>"+ this.dimmers[i]['name'] + " " +getDimmerValue(this.dimmers[i]['name'])+"."));
} else {
this.display.printText(0, i, this.parentDisplay.lcdCenterText(""+ this.dimmers[i]['name'] + " " +getDimmerValue(this.dimmers[i]['name'])+"."));
}
}
} else {
this.display.printText(0, i, this.parentDisplay.lcdCenterText("Tillbaka"));
}
}
DimmerMenuItem.prototype.onExit = function ()
{
this.mode = 0;
}