mirror of
https://github.com/meshtastic/firmware.git
synced 2025-04-26 18:09:04 +00:00
Format plz
This commit is contained in:
parent
6a5e0edb60
commit
384eac9a87
@ -9,210 +9,197 @@
|
|||||||
|
|
||||||
namespace concurrency
|
namespace concurrency
|
||||||
{
|
{
|
||||||
/**
|
/**
|
||||||
* Watch a GPIO and if we get an IRQ, wake the main thread.
|
* Watch a GPIO and if we get an IRQ, wake the main thread.
|
||||||
* Use to add wake on button press
|
* Use to add wake on button press
|
||||||
*/
|
*/
|
||||||
void wakeOnIrq(int irq, int mode)
|
void wakeOnIrq(int irq, int mode)
|
||||||
{
|
{
|
||||||
attachInterrupt(
|
attachInterrupt(
|
||||||
irq,
|
irq,
|
||||||
[]
|
[] {
|
||||||
{
|
BaseType_t higherWake = 0;
|
||||||
BaseType_t higherWake = 0;
|
mainDelay.interruptFromISR(&higherWake);
|
||||||
mainDelay.interruptFromISR(&higherWake);
|
},
|
||||||
},
|
FALLING);
|
||||||
FALLING);
|
}
|
||||||
}
|
|
||||||
|
|
||||||
class ButtonThread : public concurrency::OSThread
|
class ButtonThread : public concurrency::OSThread
|
||||||
{
|
{
|
||||||
// Prepare for button presses
|
// Prepare for button presses
|
||||||
#ifdef BUTTON_PIN
|
#ifdef BUTTON_PIN
|
||||||
OneButton userButton;
|
OneButton userButton;
|
||||||
#endif
|
#endif
|
||||||
#ifdef BUTTON_PIN_ALT
|
#ifdef BUTTON_PIN_ALT
|
||||||
OneButton userButtonAlt;
|
OneButton userButtonAlt;
|
||||||
#endif
|
#endif
|
||||||
#ifdef BUTTON_PIN_TOUCH
|
#ifdef BUTTON_PIN_TOUCH
|
||||||
OneButton userButtonTouch;
|
OneButton userButtonTouch;
|
||||||
#endif
|
#endif
|
||||||
static bool shutdown_on_long_stop;
|
static bool shutdown_on_long_stop;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
static uint32_t longPressTime;
|
static uint32_t longPressTime;
|
||||||
|
|
||||||
// callback returns the period for the next callback invocation (or 0 if we should no longer be called)
|
// callback returns the period for the next callback invocation (or 0 if we should no longer be called)
|
||||||
ButtonThread() : OSThread("Button")
|
ButtonThread() : OSThread("Button")
|
||||||
{
|
{
|
||||||
#ifdef BUTTON_PIN
|
#ifdef BUTTON_PIN
|
||||||
userButton = OneButton(BUTTON_PIN, true, true);
|
userButton = OneButton(BUTTON_PIN, true, true);
|
||||||
#ifdef INPUT_PULLUP_SENSE
|
#ifdef INPUT_PULLUP_SENSE
|
||||||
// Some platforms (nrf52) have a SENSE variant which allows wake from sleep - override what OneButton did
|
// Some platforms (nrf52) have a SENSE variant which allows wake from sleep - override what OneButton did
|
||||||
pinMode(BUTTON_PIN, INPUT_PULLUP_SENSE);
|
pinMode(BUTTON_PIN, INPUT_PULLUP_SENSE);
|
||||||
#endif
|
#endif
|
||||||
userButton.attachClick(userButtonPressed);
|
userButton.attachClick(userButtonPressed);
|
||||||
userButton.setClickTicks(300);
|
userButton.setClickTicks(300);
|
||||||
userButton.attachDuringLongPress(userButtonPressedLong);
|
userButton.attachDuringLongPress(userButtonPressedLong);
|
||||||
userButton.attachDoubleClick(userButtonDoublePressed);
|
userButton.attachDoubleClick(userButtonDoublePressed);
|
||||||
userButton.attachMultiClick(userButtonMultiPressed);
|
userButton.attachMultiClick(userButtonMultiPressed);
|
||||||
userButton.attachLongPressStart(userButtonPressedLongStart);
|
userButton.attachLongPressStart(userButtonPressedLongStart);
|
||||||
userButton.attachLongPressStop(userButtonPressedLongStop);
|
userButton.attachLongPressStop(userButtonPressedLongStop);
|
||||||
wakeOnIrq(BUTTON_PIN, FALLING);
|
wakeOnIrq(BUTTON_PIN, FALLING);
|
||||||
#endif
|
#endif
|
||||||
#ifdef BUTTON_PIN_ALT
|
#ifdef BUTTON_PIN_ALT
|
||||||
userButtonAlt = OneButton(BUTTON_PIN_ALT, true, true);
|
userButtonAlt = OneButton(BUTTON_PIN_ALT, true, true);
|
||||||
#ifdef INPUT_PULLUP_SENSE
|
#ifdef INPUT_PULLUP_SENSE
|
||||||
// Some platforms (nrf52) have a SENSE variant which allows wake from sleep - override what OneButton did
|
// Some platforms (nrf52) have a SENSE variant which allows wake from sleep - override what OneButton did
|
||||||
pinMode(BUTTON_PIN_ALT, INPUT_PULLUP_SENSE);
|
pinMode(BUTTON_PIN_ALT, INPUT_PULLUP_SENSE);
|
||||||
#endif
|
#endif
|
||||||
userButtonAlt.attachClick(userButtonPressed);
|
userButtonAlt.attachClick(userButtonPressed);
|
||||||
userButtonAlt.attachDuringLongPress(userButtonPressedLong);
|
userButtonAlt.attachDuringLongPress(userButtonPressedLong);
|
||||||
userButtonAlt.attachDoubleClick(userButtonDoublePressed);
|
userButtonAlt.attachDoubleClick(userButtonDoublePressed);
|
||||||
userButtonAlt.attachLongPressStart(userButtonPressedLongStart);
|
userButtonAlt.attachLongPressStart(userButtonPressedLongStart);
|
||||||
userButtonAlt.attachLongPressStop(userButtonPressedLongStop);
|
userButtonAlt.attachLongPressStop(userButtonPressedLongStop);
|
||||||
wakeOnIrq(BUTTON_PIN_ALT, FALLING);
|
wakeOnIrq(BUTTON_PIN_ALT, FALLING);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef BUTTON_PIN_TOUCH
|
#ifdef BUTTON_PIN_TOUCH
|
||||||
userButtonTouch = OneButton(BUTTON_PIN_TOUCH, true, true);
|
userButtonTouch = OneButton(BUTTON_PIN_TOUCH, true, true);
|
||||||
userButtonTouch.attachClick(touchPressed);
|
userButtonTouch.attachClick(touchPressed);
|
||||||
wakeOnIrq(BUTTON_PIN_TOUCH, FALLING);
|
wakeOnIrq(BUTTON_PIN_TOUCH, FALLING);
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
/// If the button is pressed we suppress CPU sleep until release
|
/// If the button is pressed we suppress CPU sleep until release
|
||||||
int32_t runOnce() override
|
int32_t runOnce() override
|
||||||
{
|
{
|
||||||
canSleep = true; // Assume we should not keep the board awake
|
canSleep = true; // Assume we should not keep the board awake
|
||||||
|
|
||||||
#ifdef BUTTON_PIN
|
#ifdef BUTTON_PIN
|
||||||
userButton.tick();
|
userButton.tick();
|
||||||
canSleep &= userButton.isIdle();
|
canSleep &= userButton.isIdle();
|
||||||
#endif
|
#endif
|
||||||
#ifdef BUTTON_PIN_ALT
|
#ifdef BUTTON_PIN_ALT
|
||||||
userButtonAlt.tick();
|
userButtonAlt.tick();
|
||||||
canSleep &= userButtonAlt.isIdle();
|
canSleep &= userButtonAlt.isIdle();
|
||||||
#endif
|
#endif
|
||||||
#ifdef BUTTON_PIN_TOUCH
|
#ifdef BUTTON_PIN_TOUCH
|
||||||
userButtonTouch.tick();
|
userButtonTouch.tick();
|
||||||
canSleep &= userButtonTouch.isIdle();
|
canSleep &= userButtonTouch.isIdle();
|
||||||
#endif
|
#endif
|
||||||
// if (!canSleep) LOG_DEBUG("Supressing sleep!\n");
|
// if (!canSleep) LOG_DEBUG("Supressing sleep!\n");
|
||||||
// else LOG_DEBUG("sleep ok\n");
|
// else LOG_DEBUG("sleep ok\n");
|
||||||
|
|
||||||
return 5;
|
return 5;
|
||||||
}
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
static void touchPressed()
|
static void touchPressed()
|
||||||
{
|
{
|
||||||
screen->forceDisplay();
|
screen->forceDisplay();
|
||||||
LOG_DEBUG("touch press!\n");
|
LOG_DEBUG("touch press!\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
static void userButtonPressed()
|
static void userButtonPressed()
|
||||||
{
|
{
|
||||||
// LOG_DEBUG("press!\n");
|
// LOG_DEBUG("press!\n");
|
||||||
#ifdef BUTTON_PIN
|
#ifdef BUTTON_PIN
|
||||||
if ((BUTTON_PIN != moduleConfig.canned_message.inputbroker_pin_press) || !moduleConfig.canned_message.enabled)
|
if ((BUTTON_PIN != moduleConfig.canned_message.inputbroker_pin_press) || !moduleConfig.canned_message.enabled) {
|
||||||
{
|
powerFSM.trigger(EVENT_PRESS);
|
||||||
powerFSM.trigger(EVENT_PRESS);
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
static void userButtonPressedLong()
|
#endif
|
||||||
{
|
}
|
||||||
// LOG_DEBUG("Long press!\n");
|
static void userButtonPressedLong()
|
||||||
|
{
|
||||||
|
// LOG_DEBUG("Long press!\n");
|
||||||
#ifdef ARCH_ESP32
|
#ifdef ARCH_ESP32
|
||||||
screen->adjustBrightness();
|
screen->adjustBrightness();
|
||||||
#endif
|
#endif
|
||||||
// If user button is held down for 5 seconds, shutdown the device.
|
// If user button is held down for 5 seconds, shutdown the device.
|
||||||
if ((millis() - longPressTime > 5 * 1000) && (longPressTime > 0))
|
if ((millis() - longPressTime > 5 * 1000) && (longPressTime > 0)) {
|
||||||
{
|
|
||||||
#ifdef HAS_PMU
|
#ifdef HAS_PMU
|
||||||
if (pmu_found == true)
|
if (pmu_found == true) {
|
||||||
{
|
setLed(false);
|
||||||
setLed(false);
|
power->shutdown();
|
||||||
power->shutdown();
|
}
|
||||||
}
|
|
||||||
#elif defined(ARCH_NRF52)
|
#elif defined(ARCH_NRF52)
|
||||||
// Do actual shutdown when button released, otherwise the button release
|
// Do actual shutdown when button released, otherwise the button release
|
||||||
// may wake the board immediatedly.
|
// may wake the board immediatedly.
|
||||||
if ((!shutdown_on_long_stop) && (millis() > 30 * 1000))
|
if ((!shutdown_on_long_stop) && (millis() > 30 * 1000)) {
|
||||||
{
|
screen->startShutdownScreen();
|
||||||
screen->startShutdownScreen();
|
LOG_INFO("Shutdown from long press");
|
||||||
LOG_INFO("Shutdown from long press");
|
playBeep();
|
||||||
playBeep();
|
|
||||||
#ifdef PIN_LED1
|
#ifdef PIN_LED1
|
||||||
ledOff(PIN_LED1);
|
ledOff(PIN_LED1);
|
||||||
#endif
|
#endif
|
||||||
#ifdef PIN_LED2
|
#ifdef PIN_LED2
|
||||||
ledOff(PIN_LED2);
|
ledOff(PIN_LED2);
|
||||||
#endif
|
#endif
|
||||||
#ifdef PIN_LED3
|
#ifdef PIN_LED3
|
||||||
ledOff(PIN_LED3);
|
ledOff(PIN_LED3);
|
||||||
#endif
|
#endif
|
||||||
shutdown_on_long_stop = true;
|
shutdown_on_long_stop = true;
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
}
|
} else {
|
||||||
else
|
// LOG_DEBUG("Long press %u\n", (millis() - longPressTime));
|
||||||
{
|
|
||||||
// LOG_DEBUG("Long press %u\n", (millis() - longPressTime));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
static void userButtonDoublePressed()
|
static void userButtonDoublePressed()
|
||||||
{
|
{
|
||||||
#if defined(USE_EINK) && defined(PIN_EINK_EN)
|
#if defined(USE_EINK) && defined(PIN_EINK_EN)
|
||||||
digitalWrite(PIN_EINK_EN, digitalRead(PIN_EINK_EN) == LOW);
|
digitalWrite(PIN_EINK_EN, digitalRead(PIN_EINK_EN) == LOW);
|
||||||
#endif
|
#endif
|
||||||
screen->print("Sent ad-hoc ping\n");
|
screen->print("Sent ad-hoc ping\n");
|
||||||
service.refreshMyNodeInfo();
|
service.refreshMyNodeInfo();
|
||||||
service.sendNetworkPing(NODENUM_BROADCAST, true);
|
service.sendNetworkPing(NODENUM_BROADCAST, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void userButtonMultiPressed()
|
static void userButtonMultiPressed()
|
||||||
{
|
{
|
||||||
#if defined(GPS_POWER_TOGGLE)
|
#if defined(GPS_POWER_TOGGLE)
|
||||||
if (config.position.gps_enabled)
|
if (config.position.gps_enabled) {
|
||||||
{
|
LOG_DEBUG("Flag set to false for gps power\n");
|
||||||
LOG_DEBUG("Flag set to false for gps power\n");
|
} else {
|
||||||
}
|
LOG_DEBUG("Flag set to true to restore power\n");
|
||||||
else
|
}
|
||||||
{
|
config.position.gps_enabled = !(config.position.gps_enabled);
|
||||||
LOG_DEBUG("Flag set to true to restore power\n");
|
doGPSpowersave(config.position.gps_enabled);
|
||||||
}
|
|
||||||
config.position.gps_enabled = !(config.position.gps_enabled);
|
|
||||||
doGPSpowersave(config.position.gps_enabled);
|
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
static void userButtonPressedLongStart()
|
static void userButtonPressedLongStart()
|
||||||
{
|
{
|
||||||
if (millis() > 30 * 1000)
|
if (millis() > 30 * 1000) {
|
||||||
{
|
LOG_DEBUG("Long press start!\n");
|
||||||
LOG_DEBUG("Long press start!\n");
|
longPressTime = millis();
|
||||||
longPressTime = millis();
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
static void userButtonPressedLongStop()
|
||||||
|
{
|
||||||
|
if (millis() > 30 * 1000) {
|
||||||
|
LOG_DEBUG("Long press stop!\n");
|
||||||
|
longPressTime = 0;
|
||||||
|
if (shutdown_on_long_stop) {
|
||||||
|
playShutdownMelody();
|
||||||
|
delay(3000);
|
||||||
|
power->shutdown();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
static void userButtonPressedLongStop()
|
};
|
||||||
{
|
|
||||||
if (millis() > 30 * 1000)
|
|
||||||
{
|
|
||||||
LOG_DEBUG("Long press stop!\n");
|
|
||||||
longPressTime = 0;
|
|
||||||
if (shutdown_on_long_stop)
|
|
||||||
{
|
|
||||||
playShutdownMelody();
|
|
||||||
delay(3000);
|
|
||||||
power->shutdown();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
} // namespace concurrency
|
} // namespace concurrency
|
||||||
|
Loading…
Reference in New Issue
Block a user