@@ -18,10 +18,16 @@ Copyright (c) 20xx, MPL Contributor1 contrib1@example.net
|
|||||||
#define LORA_SS_PIN 8
|
#define LORA_SS_PIN 8
|
||||||
#define LORA_RST_PIN 4
|
#define LORA_RST_PIN 4
|
||||||
#define LORA_DI0_PIN 7
|
#define LORA_DI0_PIN 7
|
||||||
|
|
||||||
|
#define BUTTON_0_PIN 9
|
||||||
|
#define BUTTON_1_PIN 10
|
||||||
#elif defined(ARDUINO_SAMD_FEATHER_M0)
|
#elif defined(ARDUINO_SAMD_FEATHER_M0)
|
||||||
#define LORA_SS_PIN 8
|
#define LORA_SS_PIN 8
|
||||||
#define LORA_RST_PIN 4
|
#define LORA_RST_PIN 4
|
||||||
#define LORA_DI0_PIN 3
|
#define LORA_DI0_PIN 3
|
||||||
|
|
||||||
|
#define BUTTON_0_PIN 9 //Please verify
|
||||||
|
#define BUTTON_1_PIN 10 //Please verify
|
||||||
#else
|
#else
|
||||||
#error please select hardware
|
#error please select hardware
|
||||||
#endif
|
#endif
|
||||||
@@ -60,6 +66,16 @@ uint32_t lastOledTaskTime = 0;
|
|||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#include "tactile.h"
|
||||||
|
|
||||||
|
Tactile button0(BUTTON_0_PIN);
|
||||||
|
Tactile button1(BUTTON_1_PIN);
|
||||||
|
|
||||||
|
// uint8_t buttonStates[2] = {HIGH, HIGH};
|
||||||
|
// uint8_t previousButtonStates[2] = {HIGH, HIGH};
|
||||||
|
// uint32_t buttonPressMillis[2] = {0, 0};
|
||||||
|
// uint8_t buttonAction[2] = {BUTTON_ACTION_NONE, BUTTON_ACTION_NONE};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@@ -200,11 +216,7 @@ void setup(void)
|
|||||||
LORA_DI0_PIN
|
LORA_DI0_PIN
|
||||||
);
|
);
|
||||||
|
|
||||||
if (!LoRa.begin(getFrequencyForChannel(radioState.channel)))
|
if (!LoRa.begin(getFrequencyForChannel(radioState.channel))) {
|
||||||
{
|
|
||||||
#ifdef DEBUG_SERIAL
|
|
||||||
Serial.println("LoRa init failed. Check your connections.");
|
|
||||||
#endif
|
|
||||||
while (true);
|
while (true);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -263,6 +275,13 @@ void setup(void)
|
|||||||
* Prepare Serial1 for S.Bus processing
|
* Prepare Serial1 for S.Bus processing
|
||||||
*/
|
*/
|
||||||
txInput.start();
|
txInput.start();
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Buttons on TX module
|
||||||
|
*/
|
||||||
|
button0.start();
|
||||||
|
button1.start();
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
pinMode(LED_BUILTIN, OUTPUT);
|
pinMode(LED_BUILTIN, OUTPUT);
|
||||||
@@ -342,6 +361,10 @@ void loop(void)
|
|||||||
*/
|
*/
|
||||||
#ifdef DEVICE_MODE_TX
|
#ifdef DEVICE_MODE_TX
|
||||||
|
|
||||||
|
//Process buttons
|
||||||
|
button0.loop();
|
||||||
|
button1.loop();
|
||||||
|
|
||||||
txInput.recoverStuckFrames();
|
txInput.recoverStuckFrames();
|
||||||
|
|
||||||
static uint32_t serialRestartMillis = 0;
|
static uint32_t serialRestartMillis = 0;
|
||||||
@@ -363,28 +386,14 @@ void loop(void)
|
|||||||
//In the beginning just keep jumping forward and try to resync over lost single frames
|
//In the beginning just keep jumping forward and try to resync over lost single frames
|
||||||
if (radioState.failedDwellsCount < 6 && radioState.channelEntryMillis + RX_CHANNEL_DWELL_TIME < currentMillis) {
|
if (radioState.failedDwellsCount < 6 && radioState.channelEntryMillis + RX_CHANNEL_DWELL_TIME < currentMillis) {
|
||||||
radioState.failedDwellsCount++;
|
radioState.failedDwellsCount++;
|
||||||
|
|
||||||
#ifdef DEBUG_SERIAL
|
|
||||||
Serial.print("Sync forward on ch ");
|
|
||||||
Serial.print(radioState.channel);
|
|
||||||
Serial.print(" number ");
|
|
||||||
Serial.println(radioState.failedDwellsCount);
|
|
||||||
#endif
|
|
||||||
|
|
||||||
hopFrequency(&radioState, true, radioState.channel, radioState.channelEntryMillis + RX_CHANNEL_DWELL_TIME);
|
hopFrequency(&radioState, true, radioState.channel, radioState.channelEntryMillis + RX_CHANNEL_DWELL_TIME);
|
||||||
LoRa.receive();
|
LoRa.receive();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// If we are loosing more frames, start jumping in the opposite direction since probably we are completely out of sync now
|
// If we are loosing more frames, start jumping in the opposite direction since probably we are completely out of sync now
|
||||||
if (radioState.failedDwellsCount >= 6 && radioState.channelEntryMillis + (RX_CHANNEL_DWELL_TIME * 5) < currentMillis) {
|
if (radioState.failedDwellsCount >= 6 && radioState.channelEntryMillis + (RX_CHANNEL_DWELL_TIME * 5) < currentMillis) {
|
||||||
hopFrequency(&radioState, false, radioState.channel, radioState.channelEntryMillis + RX_CHANNEL_DWELL_TIME); //Start jumping in opposite direction to resync
|
hopFrequency(&radioState, false, radioState.channel, radioState.channelEntryMillis + RX_CHANNEL_DWELL_TIME); //Start jumping in opposite direction to resync
|
||||||
LoRa.receive();
|
LoRa.receive();
|
||||||
|
|
||||||
#ifdef DEBUG_SERIAL
|
|
||||||
Serial.println("Sync backward");
|
|
||||||
#endif
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
42
crossbow/tactile.cpp
Normal file
42
crossbow/tactile.cpp
Normal file
@@ -0,0 +1,42 @@
|
|||||||
|
#include "Arduino.h"
|
||||||
|
#include "tactile.h"
|
||||||
|
|
||||||
|
Tactile::Tactile(uint8_t pin) {
|
||||||
|
_pin = pin;
|
||||||
|
}
|
||||||
|
|
||||||
|
void Tactile::loop(void) {
|
||||||
|
|
||||||
|
uint8_t pinState = digitalRead(_pin);
|
||||||
|
|
||||||
|
//Press moment
|
||||||
|
if (pinState == LOW && _previousPinState == HIGH) {
|
||||||
|
_pressMillis = millis();
|
||||||
|
}
|
||||||
|
|
||||||
|
//Release moment
|
||||||
|
if (pinState == HIGH && _previousPinState == LOW) {
|
||||||
|
const uint32_t buttonTime = abs(millis() - _pressMillis);
|
||||||
|
|
||||||
|
if (buttonTime > TACTILE_LONG_PRESS_TIME) {
|
||||||
|
_state = TACTILE_STATE_LONG_PRESS;
|
||||||
|
} else if (buttonTime > TACTILE_MIN_PRESS_TIME) {
|
||||||
|
_state = TACTILE_STATE_SHORT_PRESS;
|
||||||
|
} else {
|
||||||
|
_state = TACTILE_STATE_NONE;
|
||||||
|
}
|
||||||
|
|
||||||
|
} else {
|
||||||
|
_state = TACTILE_STATE_NONE;
|
||||||
|
}
|
||||||
|
|
||||||
|
_previousPinState = pinState;
|
||||||
|
}
|
||||||
|
|
||||||
|
void Tactile::start(void) {
|
||||||
|
pinMode(_pin, INPUT_PULLUP);
|
||||||
|
}
|
||||||
|
|
||||||
|
uint8_t Tactile::getState(void) {
|
||||||
|
return _state;
|
||||||
|
}
|
||||||
30
crossbow/tactile.h
Normal file
30
crossbow/tactile.h
Normal file
@@ -0,0 +1,30 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
|
#ifndef TACTILE_H
|
||||||
|
#define TACTILE_H
|
||||||
|
|
||||||
|
#include "Arduino.h"
|
||||||
|
|
||||||
|
enum tactileStateFlags {
|
||||||
|
TACTILE_STATE_NONE,
|
||||||
|
TACTILE_STATE_SHORT_PRESS,
|
||||||
|
TACTILE_STATE_LONG_PRESS
|
||||||
|
};
|
||||||
|
|
||||||
|
#define TACTILE_MIN_PRESS_TIME 50
|
||||||
|
#define TACTILE_LONG_PRESS_TIME 1000
|
||||||
|
|
||||||
|
class Tactile {
|
||||||
|
public:
|
||||||
|
Tactile(uint8_t pin);
|
||||||
|
void loop(void);
|
||||||
|
void start(void);
|
||||||
|
uint8_t getState(void);
|
||||||
|
private:
|
||||||
|
uint8_t _pin;
|
||||||
|
uint8_t _previousPinState = HIGH;
|
||||||
|
uint32_t _pressMillis = 0;
|
||||||
|
uint8_t _state = TACTILE_STATE_NONE;
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif
|
||||||
Reference in New Issue
Block a user