diff --git a/crossbow.ino b/crossbow.ino index afe2b32..e5adc07 100644 --- a/crossbow.ino +++ b/crossbow.ino @@ -1,5 +1,5 @@ -// #define DEVICE_MODE_TX -#define DEVICE_MODE_RX +#define DEVICE_MODE_TX +// #define DEVICE_MODE_RX #define FEATURE_TX_OLED @@ -162,8 +162,6 @@ void setup(void) TCCR1B = 0; TCCR1B |= (1 << CS11); //set timer1 to increment every 0,5 us or 1us on 8MHz - pinMode(TX_BUZZER_PIN, OUTPUT); - #ifdef FEATURE_TX_OLED display.begin(SSD1306_SWITCHCAPVCC, 0x3C); // initialize with the I2C addr 0x3C (for the 128x32) display.setTextSize(1); @@ -172,17 +170,19 @@ void setup(void) display.display(); #endif + /* + * TX should start talking imediately after power up + */ + qsp.canTransmit = true; + + pinMode(TX_BUZZER_PIN, OUTPUT); + + //Play single tune to indicate power up + buzzerSingleMode(BUZZER_MODE_CHIRP, TX_BUZZER_PIN, millis(), &buzzer); #endif pinMode(LED_BUILTIN, OUTPUT); -/* - * TX should start talking imediately after power up - */ -#ifdef DEVICE_MODE_TX - qsp.canTransmit = true; -#endif - #ifdef DEBUG_SERIAL qsp.debugConfig |= DEBUG_FLAG_SERIAL; #endif diff --git a/txbuzzer.cpp b/txbuzzer.cpp index 4774ecf..b01473d 100644 --- a/txbuzzer.cpp +++ b/txbuzzer.cpp @@ -1,10 +1,28 @@ #include "Arduino.h" #include "txbuzzer.h" +/** + * This method plays selected pattern only once + * It disables continious mode + */ +void buzzerSingleMode(uint8_t mode, uint8_t pin, uint32_t timestamp, BuzzerState_t *buzzer) { + buzzer->singleModeEnabled = true; + buzzer->enabled = false; + buzzer->mode = mode; + buzzer->tick = 0; +} + +void buzzerContinousMode(uint8_t mode, uint8_t pin, uint32_t timestamp, BuzzerState_t *buzzer) { + buzzer->singleModeEnabled = false; + buzzer->enabled = true; + buzzer->mode = mode; + buzzer->tick = 0; +} + void buzzerProcess(uint8_t pin, uint32_t timestamp, BuzzerState_t *buzzer) { - if (!buzzer->enabled) + if (!buzzer->enabled && !buzzer->singleModeEnabled) { digitalWrite(pin, LOW); return; @@ -42,6 +60,7 @@ void buzzerProcess(uint8_t pin, uint32_t timestamp, BuzzerState_t *buzzer) if (buzzer->tick >= buzzer->patternMaxTick) { buzzer->tick = 0; + buzzer->singleModeEnabled = false; } buzzer->updateTime = timestamp + buzzer->patternTickPerdiod; } diff --git a/txbuzzer.h b/txbuzzer.h index f57d320..90d00ba 100644 --- a/txbuzzer.h +++ b/txbuzzer.h @@ -19,7 +19,8 @@ enum { }; struct BuzzerState_t { - bool enabled = false; + bool enabled = false; //Continous mode buzzer + bool singleModeEnabled = false; uint8_t mode = BUZZER_MODE_OFF; uint32_t updateTime = 0; @@ -40,4 +41,6 @@ struct BuzzerState_t { }; +void buzzerSingleMode(uint8_t mode, uint8_t pin, uint32_t timestamp, BuzzerState_t *buzzer); +void buzzerContinousMode(uint8_t mode, uint8_t pin, uint32_t timestamp, BuzzerState_t *buzzer); void buzzerProcess(uint8_t pin, uint32_t timestamp, BuzzerState_t *buzzer); \ No newline at end of file