Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependencies: C12832 MMA7660 mbed
Diff: main.cpp
- Revision:
- 5:614e3ac042df
- Parent:
- 1:2967eac08981
- Child:
- 9:35c816293400
--- a/main.cpp Wed Mar 07 10:57:16 2018 +0000
+++ b/main.cpp Wed Mar 14 11:15:31 2018 +0000
@@ -3,7 +3,8 @@
#include "commands.h"
-extern COMMAND_DEFINE *commandList[];
+extern COMMAND_DEFINE *commandList[];
+extern COMMAND_DEFINE Command_null;
BusIn joy(p15,p12,p13,p16);
DigitalIn fire(p14);
@@ -15,33 +16,38 @@
lcd.locate(0,3);
lcd.printf("mbed Switches application");
- for(int index = 0; commandList[index] != NULL; index++) {
+ for(int index = 0; commandList[index]->trigger != 0x00; index++) {
commandList[index]->initialize();
}
-
+
+ COMMAND_DEFINE *current = &Command_null;
while(true) {
- COMMAND_DEFINE *command = NULL;
+ COMMAND_DEFINE *request = NULL;
int trigger = fire ? 0xff : joy;
-/*
- switch (joy) {
- case JOY_UP: {message = "Up!"; SoundProcess(); SoundFinalize(); break;}
- case JOY_DOWN: {message = "Down!"; AccelProcess(); break;}
- case JOY_LEFT: {message = "Left!"; ColorProcess(); ColorFinalize(); break;}
- case JOY_RIGHT: {message = "Right!"; LinerProcess(); break;}
- default: {message = NULL; break;}
- }
-*/
- for(int index = 0; commandList[index] != NULL; index++) {
+ for(int index = 0; commandList[index]->trigger != 0x00; index++) {
if (trigger == commandList[index]->trigger) {
- command = commandList[index];
+ request = commandList[index];
}
}
- if (command != NULL) {
- lcd.locate(0,15);
- lcd.printf(" ");
- lcd.locate(0,15);
- lcd.printf(command->name);
- command->process();
+ if (request != NULL && request != current) {
+ current->finalize();
+ current = &Command_null;
+ }
+ if (current->trigger == 0x00) {
+ if (request != NULL){
+ current = request;
+ lcd.locate(0,15);
+ lcd.printf(" ");
+ lcd.locate(0,15);
+ lcd.printf(current->name);
+ current->processInitialize();
+ }
+ } else {
+ current->processRunning();
+ if (! current->processIsContinue()){
+ current->finalize();
+ current = &Command_null;
+ }
}
}
}
\ No newline at end of file