mirror of
https://github.com/lumapu/ahoy.git
synced 2025-05-24 22:36:10 +02:00
make LED polarity selectable
This commit is contained in:
parent
ba996f56dd
commit
33264cc776
6 changed files with 36 additions and 16 deletions
28
src/app.cpp
28
src/app.cpp
|
@ -69,7 +69,7 @@ void app::setup() {
|
|||
mPayload.addAlarmListener(std::bind(&PubMqttType::alarmEventListener, &mMqtt, std::placeholders::_1, std::placeholders::_2, std::placeholders::_3));
|
||||
}
|
||||
#endif
|
||||
setupLed();
|
||||
setupLed(mConfig->led.led_high_active);
|
||||
|
||||
mWeb.setup(this, &mSys, mConfig);
|
||||
mWeb.setProtection(strlen(mConfig->sys.adminPwd) != 0);
|
||||
|
@ -353,7 +353,7 @@ void app::tickSend(void) {
|
|||
}
|
||||
yield();
|
||||
|
||||
updateLed();
|
||||
updateLed(mConfig->led.led_high_active);
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
|
@ -386,31 +386,33 @@ void app::mqttSubRxCb(JsonObject obj) {
|
|||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
void app::setupLed(void) {
|
||||
/** LED connection diagram
|
||||
* \\
|
||||
* PIN ---- |<----- 3.3V
|
||||
*
|
||||
* */
|
||||
void app::setupLed(uint8_t is_high_active) {
|
||||
|
||||
uint8_t led_off = (is_high_active != 0) ? LOW : HIGH;
|
||||
|
||||
if (mConfig->led.led0 != 0xff) {
|
||||
pinMode(mConfig->led.led0, OUTPUT);
|
||||
digitalWrite(mConfig->led.led0, HIGH); // LED off
|
||||
digitalWrite(mConfig->led.led0, led_off);
|
||||
}
|
||||
if (mConfig->led.led1 != 0xff) {
|
||||
pinMode(mConfig->led.led1, OUTPUT);
|
||||
digitalWrite(mConfig->led.led1, HIGH); // LED off
|
||||
digitalWrite(mConfig->led.led1, led_off);
|
||||
}
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
void app::updateLed(void) {
|
||||
void app::updateLed(uint8_t is_high_active) {
|
||||
|
||||
uint8_t led_off = (is_high_active != 0) ? LOW : HIGH;
|
||||
uint8_t led_on = (is_high_active != 0) ? HIGH : LOW;
|
||||
|
||||
if (mConfig->led.led0 != 0xff) {
|
||||
Inverter<> *iv = mSys.getInverterByPos(0);
|
||||
if (NULL != iv) {
|
||||
if (iv->isProducing(mTimestamp))
|
||||
digitalWrite(mConfig->led.led0, LOW); // LED on
|
||||
digitalWrite(mConfig->led.led0, led_on);
|
||||
else
|
||||
digitalWrite(mConfig->led.led0, HIGH); // LED off
|
||||
digitalWrite(mConfig->led.led0, led_off);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -213,8 +213,8 @@ class app : public IApp, public ah::Scheduler {
|
|||
|
||||
void mqttSubRxCb(JsonObject obj);
|
||||
|
||||
void setupLed(void);
|
||||
void updateLed(void);
|
||||
void setupLed(uint8_t is_high_active);
|
||||
void updateLed(uint8_t is_high_active);
|
||||
|
||||
void tickReboot(void) {
|
||||
DPRINTLN(DBG_INFO, F("Rebooting..."));
|
||||
|
|
|
@ -100,6 +100,7 @@ typedef struct {
|
|||
typedef struct {
|
||||
uint8_t led0; // first LED pin
|
||||
uint8_t led1; // second LED pin
|
||||
uint8_t led_high_active; // determines if LEDs are high or low active
|
||||
} cfgLed_t;
|
||||
|
||||
typedef struct {
|
||||
|
@ -378,6 +379,7 @@ class settings {
|
|||
|
||||
mCfg.led.led0 = DEF_PIN_OFF;
|
||||
mCfg.led.led1 = DEF_PIN_OFF;
|
||||
mCfg.led.led_high_active = LOW;
|
||||
|
||||
memset(&mCfg.inst, 0, sizeof(cfgInst_t));
|
||||
|
||||
|
@ -517,9 +519,11 @@ class settings {
|
|||
if(set) {
|
||||
obj[F("0")] = mCfg.led.led0;
|
||||
obj[F("1")] = mCfg.led.led1;
|
||||
obj[F("2")] = mCfg.led.led_high_active;
|
||||
} else {
|
||||
mCfg.led.led0 = obj[F("0")];
|
||||
mCfg.led.led1 = obj[F("1")];
|
||||
mCfg.led.led_high_active = obj[F("2")];
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -391,6 +391,7 @@ class RestApi {
|
|||
obj[F("miso")] = mConfig->nrf.pinMiso;
|
||||
obj[F("led0")] = mConfig->led.led0;
|
||||
obj[F("led1")] = mConfig->led.led1;
|
||||
obj[F("led_high_active")] = mConfig->led.led_high_active;
|
||||
}
|
||||
|
||||
void getRadio(JsonObject obj) {
|
||||
|
|
|
@ -411,6 +411,10 @@
|
|||
[47, "GPIO47"],
|
||||
[48, "GPIO48"],
|
||||
];
|
||||
var led_high_active = [
|
||||
[0, "low active"],
|
||||
[1, "high active"],
|
||||
];
|
||||
|
||||
const re = /11[2,4,6]1.*/;
|
||||
|
||||
|
@ -670,6 +674,14 @@
|
|||
])
|
||||
);
|
||||
}
|
||||
e.append(
|
||||
ml("div", { class: "row mb-3" }, [
|
||||
ml("div", { class: "col-12 col-sm-3 my-2" }, "LED polarity"),
|
||||
ml("div", { class: "col-12 col-sm-9" },
|
||||
sel('pinLedHighActive', led_high_active, obj["led_high_active"])
|
||||
)
|
||||
])
|
||||
);
|
||||
}
|
||||
|
||||
function parseRadio(obj) {
|
||||
|
|
|
@ -33,7 +33,7 @@
|
|||
|
||||
#define WEB_SERIAL_BUF_SIZE 2048
|
||||
|
||||
const char *const pinArgNames[] = {"pinCs", "pinCe", "pinIrq", "pinSclk", "pinMosi", "pinMiso", "pinLed0", "pinLed1"};
|
||||
const char *const pinArgNames[] = {"pinCs", "pinCe", "pinIrq", "pinSclk", "pinMosi", "pinMiso", "pinLed0", "pinLed1", "pinLedHighActive"};
|
||||
|
||||
template <class HMSYSTEM>
|
||||
class Web {
|
||||
|
@ -532,6 +532,7 @@ class Web {
|
|||
case 5: mConfig->nrf.pinMiso = ((pin != 0xff) ? pin : DEF_MISO_PIN); break;
|
||||
case 6: mConfig->led.led0 = pin; break;
|
||||
case 7: mConfig->led.led1 = pin; break;
|
||||
case 8: mConfig->led.led_high_active = pin; break; // this is not really a pin but a polarity, but handling it close to here makes sense
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue