Buzzer Single and Continous modes
This commit is contained in:
18
crossbow.ino
18
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
|
||||
|
||||
#endif
|
||||
|
||||
pinMode(LED_BUILTIN, OUTPUT);
|
||||
|
||||
/*
|
||||
* TX should start talking imediately after power up
|
||||
*/
|
||||
#ifdef DEVICE_MODE_TX
|
||||
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);
|
||||
|
||||
#ifdef DEBUG_SERIAL
|
||||
qsp.debugConfig |= DEBUG_FLAG_SERIAL;
|
||||
#endif
|
||||
|
||||
21
txbuzzer.cpp
21
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;
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
Reference in New Issue
Block a user