Buzzer Single and Continous modes
This commit is contained in:
22
crossbow.ino
22
crossbow.ino
@@ -1,5 +1,5 @@
|
|||||||
// #define DEVICE_MODE_TX
|
#define DEVICE_MODE_TX
|
||||||
#define DEVICE_MODE_RX
|
// #define DEVICE_MODE_RX
|
||||||
|
|
||||||
#define FEATURE_TX_OLED
|
#define FEATURE_TX_OLED
|
||||||
|
|
||||||
@@ -162,8 +162,6 @@ void setup(void)
|
|||||||
TCCR1B = 0;
|
TCCR1B = 0;
|
||||||
TCCR1B |= (1 << CS11); //set timer1 to increment every 0,5 us or 1us on 8MHz
|
TCCR1B |= (1 << CS11); //set timer1 to increment every 0,5 us or 1us on 8MHz
|
||||||
|
|
||||||
pinMode(TX_BUZZER_PIN, OUTPUT);
|
|
||||||
|
|
||||||
#ifdef FEATURE_TX_OLED
|
#ifdef FEATURE_TX_OLED
|
||||||
display.begin(SSD1306_SWITCHCAPVCC, 0x3C); // initialize with the I2C addr 0x3C (for the 128x32)
|
display.begin(SSD1306_SWITCHCAPVCC, 0x3C); // initialize with the I2C addr 0x3C (for the 128x32)
|
||||||
display.setTextSize(1);
|
display.setTextSize(1);
|
||||||
@@ -172,17 +170,19 @@ void setup(void)
|
|||||||
display.display();
|
display.display();
|
||||||
#endif
|
#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
|
#endif
|
||||||
|
|
||||||
pinMode(LED_BUILTIN, OUTPUT);
|
pinMode(LED_BUILTIN, OUTPUT);
|
||||||
|
|
||||||
/*
|
|
||||||
* TX should start talking imediately after power up
|
|
||||||
*/
|
|
||||||
#ifdef DEVICE_MODE_TX
|
|
||||||
qsp.canTransmit = true;
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#ifdef DEBUG_SERIAL
|
#ifdef DEBUG_SERIAL
|
||||||
qsp.debugConfig |= DEBUG_FLAG_SERIAL;
|
qsp.debugConfig |= DEBUG_FLAG_SERIAL;
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
21
txbuzzer.cpp
21
txbuzzer.cpp
@@ -1,10 +1,28 @@
|
|||||||
#include "Arduino.h"
|
#include "Arduino.h"
|
||||||
#include "txbuzzer.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)
|
void buzzerProcess(uint8_t pin, uint32_t timestamp, BuzzerState_t *buzzer)
|
||||||
{
|
{
|
||||||
|
|
||||||
if (!buzzer->enabled)
|
if (!buzzer->enabled && !buzzer->singleModeEnabled)
|
||||||
{
|
{
|
||||||
digitalWrite(pin, LOW);
|
digitalWrite(pin, LOW);
|
||||||
return;
|
return;
|
||||||
@@ -42,6 +60,7 @@ void buzzerProcess(uint8_t pin, uint32_t timestamp, BuzzerState_t *buzzer)
|
|||||||
if (buzzer->tick >= buzzer->patternMaxTick)
|
if (buzzer->tick >= buzzer->patternMaxTick)
|
||||||
{
|
{
|
||||||
buzzer->tick = 0;
|
buzzer->tick = 0;
|
||||||
|
buzzer->singleModeEnabled = false;
|
||||||
}
|
}
|
||||||
buzzer->updateTime = timestamp + buzzer->patternTickPerdiod;
|
buzzer->updateTime = timestamp + buzzer->patternTickPerdiod;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -19,7 +19,8 @@ enum {
|
|||||||
};
|
};
|
||||||
|
|
||||||
struct BuzzerState_t {
|
struct BuzzerState_t {
|
||||||
bool enabled = false;
|
bool enabled = false; //Continous mode buzzer
|
||||||
|
bool singleModeEnabled = false;
|
||||||
uint8_t mode = BUZZER_MODE_OFF;
|
uint8_t mode = BUZZER_MODE_OFF;
|
||||||
|
|
||||||
uint32_t updateTime = 0;
|
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);
|
void buzzerProcess(uint8_t pin, uint32_t timestamp, BuzzerState_t *buzzer);
|
||||||
Reference in New Issue
Block a user