diff --git a/libraries/Desktop/Makefile.desktop b/libraries/Desktop/Makefile.desktop index 31d922b92f..8f30f70f13 100644 --- a/libraries/Desktop/Makefile.desktop +++ b/libraries/Desktop/Makefile.desktop @@ -12,7 +12,7 @@ nogps: make -f $(DESKTOP)/Makefile.desktop EXTRAFLAGS="-DGPS_PROTOCOL=GPS_PROTOCOL_NONE -DLOGGING_ENABLED=DISABLED" hil: - make -f $(DESKTOP)/Makefile.desktop EXTRAFLAGS="-DHIL_MODE=HIL_MODE_ATTITUDE -DCLI_ENABLED=DISABLED -DLOGGING_ENABLED=DISABLED" + make -f $(DESKTOP)/Makefile.desktop EXTRAFLAGS="-DHIL_MODE=HIL_MODE_ATTITUDE -DLOGGING_ENABLED=DISABLED" hilsen: make -f $(DESKTOP)/Makefile.desktop EXTRAFLAGS="-DHIL_MODE=HIL_MODE_SENSORS -DCLI_ENABLED=DISABLED -DLOGGING_ENABLED=DISABLED" diff --git a/libraries/Desktop/support/Arduino.cpp b/libraries/Desktop/support/Arduino.cpp index 60812ddb64..1726a0e295 100644 --- a/libraries/Desktop/support/Arduino.cpp +++ b/libraries/Desktop/support/Arduino.cpp @@ -5,6 +5,7 @@ #include "avr/pgmspace.h" #include #include +#include "desktop.h" extern "C" { @@ -21,20 +22,20 @@ void pinMode(uint8_t pin, uint8_t mode) long unsigned int millis(void) { - extern struct timeval sketch_start_time; struct timeval tp; gettimeofday(&tp,NULL); return 1.0e3*((tp.tv_sec + (tp.tv_usec*1.0e-6)) - - (sketch_start_time.tv_sec + (sketch_start_time.tv_usec*1.0e-6))); + (desktop_state.sketch_start_time.tv_sec + + (desktop_state.sketch_start_time.tv_usec*1.0e-6))); } long unsigned int micros(void) { - extern struct timeval sketch_start_time; struct timeval tp; gettimeofday(&tp,NULL); return 1.0e6*((tp.tv_sec + (tp.tv_usec*1.0e-6)) - - (sketch_start_time.tv_sec + (sketch_start_time.tv_usec*1.0e-6))); + (desktop_state.sketch_start_time.tv_sec + + (desktop_state.sketch_start_time.tv_usec*1.0e-6))); } void delay(long unsigned msec) diff --git a/libraries/Desktop/support/desktop.h b/libraries/Desktop/support/desktop.h index f34b93f895..aedcdf7d59 100644 --- a/libraries/Desktop/support/desktop.h +++ b/libraries/Desktop/support/desktop.h @@ -1,2 +1,10 @@ + +struct desktop_state { + bool slider; // slider switch state, True means CLI mode + struct timeval sketch_start_time; +}; + +extern struct desktop_state desktop_state; + void desktop_serial_select_setup(fd_set *fds, int *fd_high); diff --git a/libraries/Desktop/support/main.cpp b/libraries/Desktop/support/main.cpp index 9e16c1ff70..2e83642cf1 100644 --- a/libraries/Desktop/support/main.cpp +++ b/libraries/Desktop/support/main.cpp @@ -4,17 +4,43 @@ #include #include #include +#include #include "desktop.h" void setup(void); void loop(void); -struct timeval sketch_start_time; +// the state of the desktop simulation +struct desktop_state desktop_state; -int main(void) +static void usage(void) { - gettimeofday(&sketch_start_time, NULL); + printf("Options:\n"); + printf("\t-s enable CLI slider switch\n"); +} + +int main(int argc, char * const argv[]) +{ + int opt; + + // default state + desktop_state.slider = false; + gettimeofday(&desktop_state.sketch_start_time, NULL); + + while ((opt = getopt(argc, argv, "sh")) != -1) { + switch (opt) { + case 's': + desktop_state.slider = true; + break; + default: + usage(); + break; + } + } + + // run main setup() function from sketch setup(); + while (true) { struct timeval tv; fd_set fds;