BUG Community

Welcome! Log In

Forums Applications Adding loops to BaseDiagnostic app, Help a new guy out

Subscribe to Adding loops to BaseDiagnostic app, Help a new guy out  3 posts, 2 voices

Log in to reply to this topic
 
Jul 1, 2008 4:50pm
Img_missing_medium edgar1992 7 posts

My apologies if this is easy…

I would like to use the BaseDiagnostic as a starting off point for my application. I would like to use the hot keys to determine which of 3 loops to run. The loops would display and update the GPS position, speed and heading on the built in LCD. I haven’t been able to figure out how to use the hot keys to break back out of the loop.

Thanks,
Che.

Jul 2, 2008 10:41am
Medium Bug Labs team jconnolly 285 posts

edgar1992
My apologies if this is easy...

I would like to use the BaseDiagnostic as a starting off point for my application. I would like to use the hot keys to determine which of 3 loops to run. The loops would display and update the GPS position, speed and heading on the built in LCD. I haven't been able to figure out how to use the hot keys to break back out of the loop.

Thanks,
Che.


Hey there Che,

No prob, great that you're jumping in.... if you post some code I can help you specifically, but one way to do it is to set a global variable to true when buttonEvent(ButtonEvent event) is called:





private boolean hotkey1Pressed = false;
...

private void doStuff(){
while (!hotkey1Pressed){
System.out.println("I'm doing stuff....");
}
System.out.println("Outside of loop because hotkey1 was pressed...");
}

...
public void buttonEvent(ButtonEvent event){
if (event.getAction() == ButtonEvent.KEY_UP) {
System.out.println("In if...");
switch (event.getButton()) {
case (ButtonEvent.BUTTON_HOTKEY_1):
hotkey1Pressed = true;
break;
....
}
}
}





Give that a try and let me know if I can help further.
Jul 3, 2008 9:51am
Img_missing_medium edgar1992 7 posts

Thanks I guess I just needed to put the loop in the right place. I haven't gotten to the chapter in my book on events yet. In case anyone is interested here is the code in question...


public void doStart() {
System.out.println("Button_GPSServiceTracker: start 1");
buttonEventProvider = (IButtonEventProvider) getService(IButtonEventProvider.class);
baseControl = (IBUGBaseControl) getService(IBUGBaseControl.class);
buttonEventProvider.addListener(this);



while (CurrentButton != 4){// pressing button 4 should end the routine.
while (CurrentButton == 0){// enter all the stuff you want to happen before any button is pressed.
// Write a loop to get a fix
System.out.println("GPS has a fix...");
try
{
Thread.sleep(1000); // ask currently executing Thread to sleep for 1000ms
}// end try
catch(InterruptedException e) {
System.out.println("Sleep interrupted:"+e);
}// end catch
} // end what to do when no button has been pressed

while (CurrentButton == 1){
try
{
System.out.print("Current Location = ");
LCDDisplay ("TEST");
// System.out.println(position.getLatitudeLongitude());
Thread.sleep(100); // ask currently executing Thread to sleep for 1000ms
}// end try
catch(InterruptedException e) {
System.out.println("Sleep interrupted:"+e);
}// end catch

}// end while 1

while (CurrentButton == 2){
System.out.print("2 ");
try
{
Thread.sleep(100); // ask currently executing Thread to sleep for 1000ms
}// end try
catch(InterruptedException e) {
System.out.println("Sleep interrupted:"+e);
}// end catch

}// end while 2

while (CurrentButton == 3){
System.out.print("3 ");
try
{
Thread.sleep(100); // ask currently executing Thread to sleep for 1000ms
}// end try
catch(InterruptedException e) {
System.out.println("Sleep interrupted:"+e);
}//end catch

}// end while 3

}// end while != Button 4
CurrentButton = 0;// resets the current button var. If GPS is removed and re-installed it will reset the program
}// end doStart

public void buttonEvent(ButtonEvent event) {

if (event.getAction() == ButtonEvent.KEY_DOWN) {
/**
* input anything that you want to do on key-down
*
*/
}
if (event.getAction() == ButtonEvent.KEY_UP) {
System.out.println("In if...");
switch (event.getButton()) {
case (ButtonEvent.BUTTON_HOTKEY_1):
CurrentButton=1;
System.out.println("trackpoint" + CurrentButton);
break;
case (ButtonEvent.BUTTON_HOTKEY_2):
CurrentButton=2;
System.out.println("trackpoint" + CurrentButton);
break;
case (ButtonEvent.BUTTON_HOTKEY_3):
CurrentButton=3;
System.out.println("trackpoint" + CurrentButton);
break;
case (ButtonEvent.BUTTON_HOTKEY_4):
CurrentButton=4;
System.out.println("trackpoint" + CurrentButton);
break;
case (ButtonEvent.BUTTON_UP):
CurrentButton=5;
System.out.println("trackpoint" + CurrentButton);
System.out.println("trackpoint up");
break;
case (ButtonEvent.BUTTON_DOWN):
CurrentButton=6;
System.out.println("trackpoint" + CurrentButton);
System.out.println("trackpoint dn");
break;
case (ButtonEvent.BUTTON_LEFT):
CurrentButton=7;
System.out.println("trackpoint" + CurrentButton);
System.out.println("trackpoint L");
break;
case (ButtonEvent.BUTTON_RIGHT):
CurrentButton=8;
System.out.println("trackpoint" + CurrentButton);
System.out.println("trackpoint R");
break;
case (ButtonEvent.BUTTON_SELECT):
CurrentButton=9;
System.out.println("trackpoint" + CurrentButton);
System.out.println("trackpoint Sel");

} //end 'if (event.getAction() == ButtonEvent.KEY_UP)'
} // end 'switch (event.getButton())'
} //end 'public void buttonEvent(ButtonEvent event);'
Log in to reply to this topic
Forums Applications Adding loops to BaseDiagnostic app, Help a new guy out

Powered by Community Engine

Top
Login
Close
Bottom