This repository has been archived on 2022-08-16. You can view files and clone it, but cannot push or open issues or pull requests.
speedclock/speedclock.h

104 lines
5.1 KiB
C
Raw Normal View History

2018-07-06 23:56:33 +02:00
#ifndef speedclock_H
#define speedclock_H
2018-07-06 23:56:33 +02:00
2018-07-07 18:47:18 +02:00
//-------------- defines for the radio devices NRF24 ---------------------------------------------------------
#define STATION_SEL0 9 // this 9 for Nano
#define STATION_SEL1 10 // this 10 for Nano
2018-07-06 23:56:33 +02:00
2018-07-08 13:44:57 +02:00
typedef enum {BASESTATION = 0, TOPSTATION} radio_type_e;
2018-07-06 23:56:33 +02:00
#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
#define RF24_PA_LEVEL RF24_PA_LOW // sending power level RF24_PA_LOW, ????
2018-07-06 23:56:33 +02:00
2018-07-07 18:47:18 +02:00
//--------------- defines for the I2C
//#define SCL A5 // I2C clock pin
2018-07-08 13:44:57 +02:00
//#define SDA A4 // I2C data pin
2018-07-07 18:47:18 +02:00
2018-07-06 23:56:33 +02:00
//--------------- define the structure and type of data that sender and receiver will exchange ----------------
typedef struct transcv_struct{
2018-07-08 13:44:57 +02:00
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
2018-07-06 23:56:33 +02:00
}transcv_s;
2018-07-07 18:47:18 +02:00
#define STOPBUTTON_IN 2 // this is the input for the button
2018-07-08 01:34:57 +02:00
#define STOPBUTTON_PRESSED LOW // this the signal level the top button will be at as soon as pressed
2018-07-06 23:56:33 +02:00
#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
2018-07-08 13:42:38 +02:00
#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 // if there was no data received from the TOPSTATION for that amount of time - the connection is flagged as lost
2018-07-06 23:56:33 +02:00
2018-07-07 18:47:18 +02:00
#define STARTBUTTON_IN 4 // start button
2018-07-06 23:56:33 +02:00
#define STARTBUTTON_PRESSED LOW
2018-07-07 18:47:18 +02:00
#define CANCELBUTTON_IN 2 // chancle button
#define CANCELBUTTON_PRESSED LOW
2018-07-08 13:44:57 +02:00
#define FAILSTARTBUTTON_IN 3 // fail start button
2018-07-06 23:56:33 +02:00
#define FAILSTARTBUTTON_PRESSED LOW
2018-07-07 18:47:18 +02:00
#define PIEZO_PIN 6 // piezo speaker
2018-07-06 23:56:33 +02:00
#define WARN_LED A1 // yellow warn LED
#define WARN_LED_ON HIGH
#define WARN_LED_OFF LOW
#define FAIL_LED A3 // red fail LED
#define FAIL_LED_ON HIGH
#define FAIL_LED_OFF LOW
#define READY_LED A2 // green ready LED
#define READY_LED_ON HIGH
#define READY_LED_OFF LOW
#define RUN_LED A0 // blue run LED
#define RUN_LED_ON HIGH
#define RUN_LED_OFF LOW
2018-07-07 19:27:47 +02:00
#define DISPLAY_I2C_ADDRESS 0x3C //Adress of the Display
2018-07-06 23:56:33 +02:00
typedef enum {TIMER_INIT = 0, TIMER_NOCONNECTION, TIMER_IDLE, TIMER_READY, TIMER_STARTED, TIMER_RUNNING , TIMER_CANCELLED, TIMER_STOPPED, TIMER_TIMEDOUT, TIMER_FAIL, TIMER_WAIT} timer_state_e;
typedef enum {MODE_COMPETE = 0, MODE_TRAINING, MODE_CALIBRATION} timer_mode_e; // compete - full mode with false start detector, training - no false start detection, calibration - parellel wired connection between top and base to kalibrate the offset calculation of the wireless connection
2018-07-06 23:56:33 +02:00
2018-07-08 13:44:57 +02:00
// READY_LED, WARN_LED, RUN_LED, FAIL_LED
const float LEDStates[][3] =
2018-07-06 23:56:33 +02:00
{
[TIMER_INIT] = {READY_LED_OFF, RUN_LED_OFF, FAIL_LED_OFF},
[TIMER_NOCONNECTION] = {READY_LED_OFF, RUN_LED_OFF, FAIL_LED_ON},
[TIMER_IDLE] = {READY_LED_ON, RUN_LED_OFF, FAIL_LED_OFF},
[TIMER_READY] = {READY_LED_ON, RUN_LED_OFF, FAIL_LED_OFF},
[TIMER_STARTED] = {READY_LED_ON, RUN_LED_ON, FAIL_LED_OFF},
[TIMER_RUNNING] = {READY_LED_OFF, RUN_LED_ON, FAIL_LED_OFF},
[TIMER_CANCELLED] = {READY_LED_OFF, RUN_LED_OFF, FAIL_LED_ON},
[TIMER_STOPPED] = {READY_LED_ON, RUN_LED_ON, FAIL_LED_OFF},
[TIMER_TIMEDOUT] = {READY_LED_OFF, RUN_LED_ON, FAIL_LED_ON},
[TIMER_FAIL] = {READY_LED_OFF, RUN_LED_OFF, FAIL_LED_ON}
2018-07-07 18:47:18 +02:00
};
2018-07-06 23:56:33 +02:00
2018-07-08 01:34:57 +02:00
#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 MAX_ALLOWED_FAILED_OFFSETS 3 // if more than this number of offsets are out of the specified MAX_DIFFERENCE_OFFSET_MS value, offset calcultion will be restarted
2018-07-07 18:47:18 +02:00
2018-07-08 13:44:57 +02:00
#define STARTSEQ_LENGTH_MS 3100 // the length of the start sequence from the time the button was pressed ... includes the 3 tones
2018-07-07 18:47:18 +02:00
#define STARTSEQ_STARTPAUSE_MS 1000
2018-07-07 21:41:53 +02:00
#define STARTSEQ_TONEPAUSE_MS 1000
2018-07-07 18:47:18 +02:00
#define STARTSEQ_TON_1_2_LENGTH_MS 200
#define STARTSEQ_TON_1_2_FREQUENCY NOTE_G4
#define STARTSEQ_TON_3_LENGTH_MS 100
#define STARTSEQ_TON_3_FREQUENCY NOTE_C6
#define FAILSEQ_TONEPAUSE_MS 400
#define FAILSEQ_TON_LENGTH_MS 300
#define FAILSEQ_TON_FREQUENCY NOTE_G1
#define TIMER_MAX_TIME 99999
#define TIMER_TIMEOUT 20000
//--------------------------------------- function declarations ----------------------------------------------
void receive_values(void);
2018-07-07 18:47:18 +02:00
void false_start_isr(void);
2018-07-07 22:50:05 +02:00
void update_screen(timer_state_e state);
2018-07-07 18:47:18 +02:00
void set_state_LEDs(timer_state_e state, boolean warn);
void startSequence(void);
2018-07-07 22:50:05 +02:00
void update_statemessage(timer_state_e timer_state);
2018-07-07 18:47:18 +02:00
void failSequence(void);
2018-07-07 23:51:35 +02:00
void wait(unsigned long ms);
2018-07-06 23:56:33 +02:00
#endif