-
-
Notifications
You must be signed in to change notification settings - Fork 402
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #596 from bdring/Devt
Devt
- Loading branch information
Showing
52 changed files
with
1,199 additions
and
997 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,41 +1,14 @@ | ||
#include "ControlPin.h" | ||
|
||
#include "Report.h" // addPinReport | ||
#include "Protocol.h" // ExecAlarm | ||
#include <esp_attr.h> // IRAM_ATTR | ||
#include <esp32-hal-gpio.h> // CHANGE | ||
|
||
void IRAM_ATTR ControlPin::handleISR() { | ||
bool pinState = _pin.read(); | ||
_value = pinState; | ||
|
||
// Rate limit control pin events so switch bounce does not cause multiple events | ||
if (pinState && (_debounceEnd == 0 || ((getCpuTicks() - _debounceEnd) >= 0))) { | ||
_debounceEnd = usToEndTicks(debounceUs); | ||
// We use 0 to mean that the debounce lockout is inactive, | ||
// so if the end time happens to be 0, bump it up by one tick. | ||
if (_debounceEnd == 0) { | ||
_debounceEnd = 1; | ||
namespace Machine { | ||
void ControlPin::run(void* arg) { | ||
if (get()) { | ||
// log_debug(_legend); | ||
block(); | ||
startTimer(); | ||
_event->run(arg); | ||
} else { | ||
reArm(); | ||
} | ||
_rtVariable = true; | ||
} | ||
} | ||
|
||
void ControlPin::init() { | ||
if (_pin.undefined()) { | ||
return; | ||
} | ||
_pin.report(_legend); | ||
auto attr = Pin::Attr::Input | Pin::Attr::ISR; | ||
if (_pin.capabilities().has(Pins::PinCapabilities::PullUp)) { | ||
attr = attr | Pin::Attr::PullUp; | ||
} | ||
_pin.setAttr(attr); | ||
_pin.attachInterrupt(ISRHandler, CHANGE, this); | ||
_rtVariable = false; | ||
_value = _pin.read(); | ||
} | ||
|
||
ControlPin::~ControlPin() { | ||
_pin.detachInterrupt(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
// Copyright (c) 2022 - Mitch Bradley | ||
// Use of this source code is governed by a GPLv3 license that can be found in the LICENSE file. | ||
|
||
#pragma once | ||
#include <Arduino.h> // String | ||
|
||
// Objects derived from the Event base class are placed in the event queue. | ||
// Protocol dequeues them and calls their run methods. | ||
class Event { | ||
public: | ||
Event() {} | ||
virtual void run(void* arg) = 0; | ||
}; | ||
|
||
class NoArgEvent : public Event { | ||
void (*_function)() = nullptr; | ||
|
||
public: | ||
NoArgEvent(void (*function)()) : _function(function) {} | ||
void run(void* arg) override { | ||
if (_function) { | ||
_function(); | ||
} | ||
} | ||
}; | ||
|
||
class ArgEvent : public Event { | ||
void (*_function)(void*) = nullptr; | ||
|
||
public: | ||
ArgEvent(void (*function)(void*)) : _function(function) {} | ||
void run(void* arg) override { | ||
if (_function) { | ||
_function(arg); | ||
} | ||
} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.