Basic buzzer framework
This commit is contained in:
24
crossbow.ino
24
crossbow.ino
@@ -1,5 +1,3 @@
|
|||||||
#define LORA_HARDWARE_SPI
|
|
||||||
|
|
||||||
#define DEVICE_MODE_TX
|
#define DEVICE_MODE_TX
|
||||||
// #define DEVICE_MODE_RX
|
// #define DEVICE_MODE_RX
|
||||||
|
|
||||||
@@ -12,16 +10,15 @@
|
|||||||
|
|
||||||
#include <LoRa.h>
|
#include <LoRa.h>
|
||||||
#include "variables.h"
|
#include "variables.h"
|
||||||
#include "sbus.h"
|
|
||||||
#include "qsp.h"
|
#include "qsp.h"
|
||||||
|
|
||||||
|
volatile int ppm[16] = {0};
|
||||||
|
|
||||||
// LoRa32u4 ports
|
// LoRa32u4 ports
|
||||||
#define LORA32U4_SS_PIN 8
|
#define LORA32U4_SS_PIN 8
|
||||||
#define LORA32U4_RST_PIN 4
|
#define LORA32U4_RST_PIN 4
|
||||||
#define LORA32U4_DI0_PIN 7
|
#define LORA32U4_DI0_PIN 7
|
||||||
|
|
||||||
volatile int ppm[16] = {0};
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Main defines for device working in TX mode
|
* Main defines for device working in TX mode
|
||||||
*/
|
*/
|
||||||
@@ -29,6 +26,10 @@ volatile int ppm[16] = {0};
|
|||||||
#include <PPMReader.h>
|
#include <PPMReader.h>
|
||||||
PPMReader ppmReader(PPM_INPUT_PIN, PPM_INPUT_INTERRUPT, true);
|
PPMReader ppmReader(PPM_INPUT_PIN, PPM_INPUT_INTERRUPT, true);
|
||||||
|
|
||||||
|
#include "txbuzzer.h"
|
||||||
|
|
||||||
|
BuzzerState_t buzzer;
|
||||||
|
|
||||||
#ifdef FEATURE_TX_OLED
|
#ifdef FEATURE_TX_OLED
|
||||||
|
|
||||||
#define OLED_RESET -1
|
#define OLED_RESET -1
|
||||||
@@ -44,6 +45,9 @@ uint32_t lastOledTaskTime = 0;
|
|||||||
* Main defines for device working in RX mode
|
* Main defines for device working in RX mode
|
||||||
*/
|
*/
|
||||||
#ifdef DEVICE_MODE_RX
|
#ifdef DEVICE_MODE_RX
|
||||||
|
|
||||||
|
#include "sbus.h"
|
||||||
|
|
||||||
uint32_t sbusTime = 0;
|
uint32_t sbusTime = 0;
|
||||||
uint8_t sbusPacket[SBUS_PACKET_LENGTH] = {0};
|
uint8_t sbusPacket[SBUS_PACKET_LENGTH] = {0};
|
||||||
uint32_t lastRxStateTaskTime = 0;
|
uint32_t lastRxStateTaskTime = 0;
|
||||||
@@ -56,7 +60,6 @@ volatile QspConfiguration_t qsp = {};
|
|||||||
volatile RxDeviceState_t rxDeviceState = {};
|
volatile RxDeviceState_t rxDeviceState = {};
|
||||||
volatile TxDeviceState_t txDeviceState = {};
|
volatile TxDeviceState_t txDeviceState = {};
|
||||||
|
|
||||||
#ifdef LORA_HARDWARE_SPI
|
|
||||||
|
|
||||||
uint8_t getRadioRssi(void)
|
uint8_t getRadioRssi(void)
|
||||||
{
|
{
|
||||||
@@ -90,8 +93,6 @@ void writeToRadio(uint8_t dataByte, QspConfiguration_t *qsp)
|
|||||||
LoRa.write(dataByte);
|
LoRa.write(dataByte);
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif
|
|
||||||
|
|
||||||
void setup(void)
|
void setup(void)
|
||||||
{
|
{
|
||||||
#ifdef DEBUG_SERIAL
|
#ifdef DEBUG_SERIAL
|
||||||
@@ -106,8 +107,6 @@ void setup(void)
|
|||||||
qsp.deviceState = DEVICE_STATE_OK;
|
qsp.deviceState = DEVICE_STATE_OK;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef LORA_HARDWARE_SPI
|
|
||||||
|
|
||||||
#ifdef WAIT_FOR_SERIAL
|
#ifdef WAIT_FOR_SERIAL
|
||||||
while (!Serial) {
|
while (!Serial) {
|
||||||
; // wait for serial port to connect. Needed for native USB
|
; // wait for serial port to connect. Needed for native USB
|
||||||
@@ -143,7 +142,6 @@ void setup(void)
|
|||||||
LoRa.onReceive(onReceive);
|
LoRa.onReceive(onReceive);
|
||||||
// #endif
|
// #endif
|
||||||
LoRa.receive();
|
LoRa.receive();
|
||||||
#endif
|
|
||||||
|
|
||||||
#ifdef DEVICE_MODE_RX
|
#ifdef DEVICE_MODE_RX
|
||||||
//initiallize default ppm values
|
//initiallize default ppm values
|
||||||
@@ -164,6 +162,8 @@ 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);
|
||||||
@@ -398,6 +398,8 @@ void loop(void)
|
|||||||
|
|
||||||
#ifdef DEVICE_MODE_TX
|
#ifdef DEVICE_MODE_TX
|
||||||
|
|
||||||
|
buzzerProcess(TX_BUZZER_PIN, currentMillis, &buzzer);
|
||||||
|
|
||||||
#ifdef FEATURE_TX_OLED
|
#ifdef FEATURE_TX_OLED
|
||||||
if (
|
if (
|
||||||
currentMillis - lastOledTaskTime > OLED_UPDATE_RATE
|
currentMillis - lastOledTaskTime > OLED_UPDATE_RATE
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
#include "Arduino.h"
|
#include "Arduino.h"
|
||||||
#include "buzzer.h"
|
#include "txbuzzer.h"
|
||||||
|
|
||||||
void buzzerProcess(uint8_t pin, uint32_t timestamp, BuzzerState_t *buzzer)
|
void buzzerProcess(uint8_t pin, uint32_t timestamp, BuzzerState_t *buzzer)
|
||||||
{
|
{
|
||||||
@@ -19,22 +19,22 @@ enum {
|
|||||||
};
|
};
|
||||||
|
|
||||||
struct BuzzerState_t {
|
struct BuzzerState_t {
|
||||||
bool enabled = true;
|
bool enabled = false;
|
||||||
uint8_t mode = BUZZER_MODE_DOUBLE_CHIRP;
|
uint8_t mode = BUZZER_MODE_OFF;
|
||||||
|
|
||||||
uint32_t updateTime = 0;
|
uint32_t updateTime = 0;
|
||||||
|
|
||||||
uint8_t tick = 0;
|
uint8_t tick = 0;
|
||||||
uint8_t element = 0;
|
uint8_t element = 0;
|
||||||
const uint8_t patternMaxTick = 20;
|
const uint8_t patternMaxTick = 20;
|
||||||
const uint8_t patternTickPerdiod = 100;
|
const uint8_t patternTickPerdiod = 75;
|
||||||
|
|
||||||
const int8_t pattern[PATTERN_MODES_NUMBER][PATTERN_ELEMENT_NUMBER] = {
|
const int8_t pattern[PATTERN_MODES_NUMBER][PATTERN_ELEMENT_NUMBER] = {
|
||||||
{PATTERN_CYCLE_OFF},
|
{PATTERN_CYCLE_OFF},
|
||||||
{PATTERN_CYCLE_ON},
|
{PATTERN_CYCLE_ON},
|
||||||
{0, 7, 10, 17},
|
{0, 7, 10, 17},
|
||||||
{0, 4, 10, 14},
|
{0, 4, 10, 14},
|
||||||
{0, 1, 10, 11},
|
{0, 1, PATTERN_CYCLE_IGNORE, PATTERN_CYCLE_IGNORE},
|
||||||
{0, 1, 2, 3}
|
{0, 1, 2, 3}
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -1,6 +1,6 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#define OLED_UPDATE_RATE 300
|
#define OLED_UPDATE_RATE 500
|
||||||
|
|
||||||
#define SBUS_UPDATE_RATE 15 //ms
|
#define SBUS_UPDATE_RATE 15 //ms
|
||||||
#define SBUS_PACKET_LENGTH 25
|
#define SBUS_PACKET_LENGTH 25
|
||||||
@@ -58,6 +58,8 @@ enum debugConfigFlags {
|
|||||||
#define PPM_INPUT_CHANNEL_COUNT 10
|
#define PPM_INPUT_CHANNEL_COUNT 10
|
||||||
#define PPM_OUTPUT_CHANNEL_COUNT 10
|
#define PPM_OUTPUT_CHANNEL_COUNT 10
|
||||||
|
|
||||||
|
#define TX_BUZZER_PIN A5
|
||||||
|
|
||||||
#define PPM_CHANNEL_DEFAULT_VALUE 1500 //set the default servo value
|
#define PPM_CHANNEL_DEFAULT_VALUE 1500 //set the default servo value
|
||||||
#define PPM_FRAME_LENGTH 30500 //set the PPM frame length in microseconds (1ms = 1000µs)
|
#define PPM_FRAME_LENGTH 30500 //set the PPM frame length in microseconds (1ms = 1000µs)
|
||||||
#define PPM_PULSE_LENGTH 300 //set the pulse length
|
#define PPM_PULSE_LENGTH 300 //set the pulse length
|
||||||
|
|||||||
Reference in New Issue
Block a user