diff --git a/speedclock.h b/speedclock.h index 26a368b..171d64c 100644 --- a/speedclock.h +++ b/speedclock.h @@ -7,19 +7,19 @@ #define STATION_SEL0 9 // this 9 for Nano #define STATION_SEL1 10 // this 10 for Nano -typedef enum {BASESTATION = 0, TOPSTATION} radio_type_e; +typedef enum {BASESTATION = 0, TOPSTATION} radio_type_e; #define RF24_CNS 7 // this is 7 for the Nano, D4 for the ESP #define RF24_CE 8 // this is 8 for the Nano, D3 for the ESP //--------------- defines for the I2C //#define SCL A5 // I2C clock pin -//#define SDA A4 // I2C data pin +//#define SDA A4 // I2C data pin //--------------- define the structure and type of data that sender and receiver will exchange ---------------- typedef struct transcv_struct{ - unsigned long topstationtime; // the top station sends its time (millis()) continously to the base station - unsigned long topbuttonpressedtime; // the top station sends the time in millis() when the button was pressed - this is already the calculated time + unsigned long topstationtime; // the top station sends its time (millis()) continously to the base station + unsigned long topbuttonpressedtime; // the top station sends the time in millis() when the button was pressed - this is already the calculated time }transcv_s; @@ -27,12 +27,13 @@ typedef struct transcv_struct{ #define STOPBUTTON_PRESSED LOW // this the signal level the top button will be at as soon as pressed #define MIN_DELAY_BETWEEN_PRESSED_MS 1000 // this defines the time in milliseconds before the button is expected to be pressed again. We do this to avaoid keybouncing #define MIN_DELAY_BETWEEN_SEND_MS 1000 // this defines the time in milliseconds before the next set of data will be send to the base station - except the button was pressed. +#define CONN_TIMEOUT 10000 #define STARTBUTTON_IN 4 // start button #define STARTBUTTON_PRESSED LOW #define CANCELBUTTON_IN 2 // chancle button #define CANCELBUTTON_PRESSED LOW -#define FAILSTARTBUTTON_IN 3 // fail start button +#define FAILSTARTBUTTON_IN 3 // fail start button #define FAILSTARTBUTTON_PRESSED LOW #define PIEZO_PIN 6 // piezo speaker @@ -52,10 +53,10 @@ typedef struct transcv_struct{ #define DISPLAY_I2C_ADDRESS 0x3C //Adress of the Display -typedef enum {TIMER_INIT = 0, TIMER_IDLE, TIMER_READY, TIMER_STARTED, TIMER_RUNNING , TIMER_CANCELLED, TIMER_STOPPED, TIMER_TIMEDOUT, TIMER_FAIL, TIMER_WAIT} timer_state_e; +typedef enum {TIMER_INIT = 0, TIMER_IDLE, TIMER_READY, TIMER_STARTED, TIMER_RUNNING , TIMER_CANCELLED, TIMER_STOPPED, TIMER_TIMEDOUT, TIMER_FAIL, TIMER_WAIT} timer_state_e; -// READY_LED, WARN_LED, RUN_LED, FAIL_LED -const float LEDStates[][3] = +// READY_LED, WARN_LED, RUN_LED, FAIL_LED +const float LEDStates[][3] = { [TIMER_INIT] = {READY_LED_OFF, RUN_LED_OFF, FAIL_LED_OFF}, [TIMER_IDLE] = {READY_LED_ON, RUN_LED_OFF, FAIL_LED_OFF}, @@ -71,7 +72,7 @@ const float LEDStates[][3] = #define MAX_DIFFERENCE_OFFSET_MS 100 // 0,001sec is the maximum offset we allow between the current offset and the mean offset. if it is more - restart offset calculation #define REQUIRED_NUMBER_MEANVALS 100 // we need at least this number of meanvalues to be ready to start a run -#define STARTSEQ_LENGTH_MS 3100 // the length of the start sequence from the time the button was pressed ... includes the 3 tones +#define STARTSEQ_LENGTH_MS 3100 // the length of the start sequence from the time the button was pressed ... includes the 3 tones #define STARTSEQ_STARTPAUSE_MS 1000 #define STARTSEQ_TONEPAUSE_MS 1000 #define STARTSEQ_TON_1_2_LENGTH_MS 200 @@ -95,5 +96,3 @@ void update_statemessage(timer_state_e timer_state); void failSequence(void); void wait(unsigned long ms); #endif - - diff --git a/speedclock.ino b/speedclock.ino index 621efe1..5dc6c37 100644 --- a/speedclock.ino +++ b/speedclock.ino @@ -30,9 +30,11 @@ unsigned long runner_start_time = 0; // this is the time the runner lef signed long runner_run_time = 0; // this is the time the runner really needed or the time started to early - depending on sign ... unsigned long run_time = 0; // if the timer is running this is that start time ... boolean warn_during_run = false; // will be set to true if there is a warning during the run - usually an offset sync error +unsigned long connection_established = 0; boolean topbuttonwaspressed = false; + timer_state_e timer_state = TIMER_WAIT; // timer needs to be initialized ... timer_state_e timer_new_state = TIMER_INIT; // timer needs to be initialized ... @@ -170,6 +172,7 @@ void loop(void) { // read data from TOP_STATION ... if( radio.available()){ // check if radio data is available - if so read the data + connection_established = millis(); while( radio.available(&pipeNo)){ // Read all available payloads radio.read( &radio_data, sizeof(radio_data) ); // Read the data the TOPSTATION sent } @@ -182,7 +185,6 @@ void loop(void) { Serial.println(current_time_offset); Serial.print(F(" Button was pressed last time on client in millis: ")); Serial.println(radio_data.topbuttonpressedtime); - } // offset calculation ... only needed if the variation is bigger than allowed or not enough values available already ... @@ -475,9 +477,20 @@ void update_screen(timer_state_e state){ display.setLetterSpacing(1); display.setCursor(64 - (display.strWidth(header_to_char) / 2), 0); display.print(header_to_char); + display.setCursor(1,0); + //check if there is a connection to the topstation + if(millis() - connection_established >= CONN_TIMEOUT || connection_established == 0){ + //if not remove the "Y" + display.print(" "); + } + else { + //if print the "Y" + display.print("Y"); + } display.setCursor(0,1); display.setLetterSpacing(0); display.print("----------------------------"); + //end of the Header //display.setLetterSpacing(1); display.set2X();