Added /interval <sec> command

This new command lets you change the interval in which the screens and
periods succeed each other.
This commit is contained in:
Kenneth van Ewijk
2014-10-29 15:19:15 +01:00
parent 9ac419c7cc
commit 589cb3afad
2 changed files with 75 additions and 34 deletions
Binary file not shown.
+75 -34
View File
@@ -24,9 +24,11 @@ public class Weerstation{
Timer starter; Timer starter;
Timer animator; Timer animator;
Timer mainTimer;
int currentScreen; int currentScreen;
int periodeNr; int periodeNr;
int interval;
boolean startup, startupState, load; boolean startup, startupState, load;
@@ -43,6 +45,7 @@ public class Weerstation{
starter = new Timer(); starter = new Timer();
startStartupAnimatie(); startStartupAnimatie();
Timer timer = new Timer(); Timer timer = new Timer();
mainTimer = new Timer();
createPeriods(); createPeriods();
backgroundLoader(); backgroundLoader();
@@ -52,7 +55,7 @@ public class Weerstation{
graphIsDisplayed = false; graphIsDisplayed = false;
console = true; console = true;
interval = 5;
//De thread die op de achtergrond alles laad //De thread die op de achtergrond alles laad
@@ -87,39 +90,7 @@ public class Weerstation{
console(); console();
//Screen switcher //Screen switcher
timer.scheduleAtFixedRate(new TimerTask() main();
{
public void run()
{
if(button2)
{
if(!graphIsDisplayed)
{
setScreen(currentScreen + 1);
if(currentScreen == 0 && button1)
{
setPeriod(periodeNr + 1);
}
}
}
else if(button1)
{
if(!graphIsDisplayed)
{
setPeriod(periodeNr + 1);
}
}
if(button3)
{
displayGraph();
}
else
{
displayMain();
}
}
}, 0, 5*1000);
//Update recent measurement every 60 seconds //Update recent measurement every 60 seconds
timer.scheduleAtFixedRate( new TimerTask() timer.scheduleAtFixedRate( new TimerTask()
@@ -186,6 +157,43 @@ public class Weerstation{
}, 0, 200); }, 0, 200);
} }
public void main()
{
mainTimer.scheduleAtFixedRate(new TimerTask()
{
public void run()
{
if(button2)
{
if(!graphIsDisplayed)
{
setScreen(currentScreen + 1);
if(currentScreen == 0 && button1)
{
setPeriod(periodeNr + 1);
}
}
}
else if(button1)
{
if(!graphIsDisplayed)
{
setPeriod(periodeNr + 1);
}
}
if(button3)
{
displayGraph();
}
else
{
displayMain();
}
}
}, 0, interval*1000);
}
public void setScreen(int screen) public void setScreen(int screen)
{ //Set the next screen { //Set the next screen
if (screen >= periodsScreens.get(periodeNr).size() || screen < 0) if (screen >= periodsScreens.get(periodeNr).size() || screen < 0)
@@ -277,6 +285,11 @@ public class Weerstation{
case "scherm": case "scherm":
case "s": case "s":
return scherm(parts[1]); return scherm(parts[1]);
case "time":
case "tijd":
case "t":
case "interval":
return interval(parts[1]);
} }
} }
@@ -319,6 +332,10 @@ public class Weerstation{
help += comS + "Exit" + comE help += comS + "Exit" + comE
+ "/exit" + tab + "/close" + "/exit" + tab + "/close"
+ desc + "Sluit de console permanent af"; + desc + "Sluit de console permanent af";
//exit
help += comS + "Interval" + comE
+ "/interval <sec>" + tab + "/time <sec>" + tab + "/tijd <sec>" + tab + "/t <sec>"
+ desc + "Veranderd de interval tussen schermen naar het opgegeven aantal seconden";
//periode //periode
help += comS + "Periode" + comE help += comS + "Periode" + comE
+ "/periode <num|name>" + tab + "/p <num|name>" + "/periode <num|name>" + tab + "/p <num|name>"
@@ -337,6 +354,30 @@ public class Weerstation{
return "Console is afgesloten.\nDe console kan alleen herstart worden door de applicatie opnieuw te starten."; return "Console is afgesloten.\nDe console kan alleen herstart worden door de applicatie opnieuw te starten.";
} }
public String interval(String param)
{
int param1=-1;
try
{
param1 = Integer.valueOf(param);
}
catch(NumberFormatException e)
{
return notFound(true);
}
if(param1 < 1)
{
return "De interval moet 1 seconde of langer zijn.";
}
mainTimer.cancel();
interval = param1;
mainTimer = new Timer();
main();
return "De interval is veranderd naar " + param + " seconden.";
}
public String periode(String param) public String periode(String param)
{ {
int param1 = -1; int param1 = -1;