Apply VSC auto format to the code and indent macros for readability
This commit is contained in:
1 parent
f7ec81ffaa
commit
7f9d8d18da
26 files changed
+4512
-3692
No files matched your search
+28
-26
@@ -27,19 +27,21 @@
|
||||
|
||||
#ifdef ZsensorGPIOKeyCode
|
||||
|
||||
int InputStateGPIOKeyCode = 0x0f; // Set to 3 so that it reads on startup
|
||||
int lastInputStateGPIOKeyCode = 0x0f;
|
||||
int InputStateGPIOKeyCode = 0x0f; // Set to 3 so that it reads on startup
|
||||
int lastInputStateGPIOKeyCode = 0x0f;
|
||||
int lastLatchStateGPIOKeyCode = 0;
|
||||
|
||||
void setupGPIOKeyCode() {
|
||||
pinMode(GPIOKeyCode_LATCH_PIN, INPUT_PULLUP); //
|
||||
pinMode(GPIOKeyCode_D0_PIN, INPUT_PULLUP); //
|
||||
pinMode(GPIOKeyCode_D1_PIN, INPUT_PULLUP); //
|
||||
pinMode(GPIOKeyCode_D2_PIN, INPUT_PULLUP); //
|
||||
//pinMode(GPIOKeyCode_D3_PIN, INPUT_PULLUP); //
|
||||
void setupGPIOKeyCode()
|
||||
{
|
||||
pinMode(GPIOKeyCode_LATCH_PIN, INPUT_PULLUP); //
|
||||
pinMode(GPIOKeyCode_D0_PIN, INPUT_PULLUP); //
|
||||
pinMode(GPIOKeyCode_D1_PIN, INPUT_PULLUP); //
|
||||
pinMode(GPIOKeyCode_D2_PIN, INPUT_PULLUP); //
|
||||
//pinMode(GPIOKeyCode_D3_PIN, INPUT_PULLUP); //
|
||||
}
|
||||
|
||||
void MeasureGPIOKeyCode(){
|
||||
void MeasureGPIOKeyCode()
|
||||
{
|
||||
|
||||
int latch = digitalRead(GPIOKeyCode_LATCH_PIN);
|
||||
|
||||
@@ -50,15 +52,14 @@ void MeasureGPIOKeyCode(){
|
||||
{
|
||||
// whatever the reading is at, it's been there for longer than the debounce
|
||||
// delay, so take it as the actual current state:
|
||||
#if defined(ESP8266) || defined(ESP32)
|
||||
#if defined(ESP8266) || defined(ESP32)
|
||||
yield();
|
||||
#endif
|
||||
#endif
|
||||
// if the Input state has changed:
|
||||
if (latch > 0 && lastLatchStateGPIOKeyCode != latch) {
|
||||
int reading = digitalRead(GPIOKeyCode_D0_PIN)
|
||||
| (digitalRead(GPIOKeyCode_D1_PIN) << 1)
|
||||
| (digitalRead(GPIOKeyCode_D2_PIN) << 2);
|
||||
//| digitalRead(GPIOKeyCode_D3_PIN) << 3;
|
||||
if (latch > 0 && lastLatchStateGPIOKeyCode != latch)
|
||||
{
|
||||
int reading = digitalRead(GPIOKeyCode_D0_PIN) | (digitalRead(GPIOKeyCode_D1_PIN) << 1) | (digitalRead(GPIOKeyCode_D2_PIN) << 2);
|
||||
//| digitalRead(GPIOKeyCode_D3_PIN) << 3;
|
||||
|
||||
char hex[3];
|
||||
|
||||
@@ -66,19 +67,20 @@ void MeasureGPIOKeyCode(){
|
||||
sprintf(hex, "%02x", InputStateGPIOKeyCode);
|
||||
hex[2] = 0;
|
||||
Serial.printf("GPIOKeyCode %s\n", hex);
|
||||
client.publish(subjectGPIOKeyCodetoMQTT,hex);
|
||||
client.publish(subjectGPIOKeyCodetoMQTT, hex);
|
||||
lastLatchStateGPIOKeyCode = latch;
|
||||
}
|
||||
|
||||
if (latch != lastLatchStateGPIOKeyCode) {
|
||||
lastLatchStateGPIOKeyCode = latch;
|
||||
Serial.printf("GPIOKeyCode latch %d\n", latch);
|
||||
if (latch == 0)
|
||||
client.publish(subjectGPIOKeyCodeStatetoMQTT, "done");
|
||||
}
|
||||
|
||||
// save the reading. Next time through the loop, it'll be the lastInputState:
|
||||
lastInputStateGPIOKeyCode = InputStateGPIOKeyCode;
|
||||
if (latch != lastLatchStateGPIOKeyCode)
|
||||
{
|
||||
lastLatchStateGPIOKeyCode = latch;
|
||||
Serial.printf("GPIOKeyCode latch %d\n", latch);
|
||||
if (latch == 0)
|
||||
client.publish(subjectGPIOKeyCodeStatetoMQTT, "done");
|
||||
}
|
||||
|
||||
// save the reading. Next time through the loop, it'll be the lastInputState:
|
||||
lastInputStateGPIOKeyCode = InputStateGPIOKeyCode;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
Reference in new issue
Block a user