Apply VSC auto format to the code and indent macros for readability

This commit is contained in:
1technophile committed 2019-12-14 17:14:36 +01:00
1 parent f7ec81ffaa
commit 7f9d8d18da
26 files changed
+4512 -3692

No files matched your search

+25 -20
View File
@@ -31,15 +31,16 @@
#ifdef ZsensorGPIOInput
unsigned long lastDebounceTime = 0;
int InputState = 3; // Set to 3 so that it reads on startup
int lastInputState = 3;
int InputState = 3; // Set to 3 so that it reads on startup
int lastInputState = 3;
void setupGPIOInput() {
pinMode(GPIOInput_PIN, INPUT_PULLUP); // declare GPIOInput pin as input_pullup to prevent floating. Pin will be high when not connected to ground
void setupGPIOInput()
{
pinMode(GPIOInput_PIN, INPUT_PULLUP); // declare GPIOInput pin as input_pullup to prevent floating. Pin will be high when not connected to ground
}
void MeasureGPIOInput(){
void MeasureGPIOInput()
{
int reading = digitalRead(GPIOInput_PIN);
// check to see if you just pressed the button
@@ -47,41 +48,45 @@ void MeasureGPIOInput(){
// since the last press to ignore any noise:
// If the switch changed, due to noise or pressing:
if (reading != lastInputState) {
if (reading != lastInputState)
{
// reset the debouncing timer
lastDebounceTime = millis();
}
if ((millis() - lastDebounceTime) > GPIOInputDebounceDelay) {
if ((millis() - lastDebounceTime) > GPIOInputDebounceDelay)
{
// 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 (reading != InputState) {
if (reading != InputState)
{
InputState = reading;
trc(F("Creating GPIOInput buffer"));
const int JSON_MSG_CALC_BUFFER = JSON_OBJECT_SIZE(1);
StaticJsonBuffer<JSON_MSG_CALC_BUFFER> jsonBuffer;
JsonObject& GPIOdata = jsonBuffer.createObject();
if (InputState == HIGH) {
JsonObject &GPIOdata = jsonBuffer.createObject();
if (InputState == HIGH)
{
trc(F("GPIO HIGH"));
pub(subjectGPIOInputtoMQTT,"HIGH");
pub(subjectGPIOInputtoMQTT, "HIGH");
GPIOdata.set("gpio", "HIGH");
}
if (InputState == LOW) {
if (InputState == LOW)
{
trc(F("GPIO LOW"));
GPIOdata.set("gpio","LOW");
pub(subjectGPIOInputtoMQTT,"LOW");
GPIOdata.set("gpio", "LOW");
pub(subjectGPIOInputtoMQTT, "LOW");
}
if(GPIOdata.size()>0) pub(subjectGPIOInputtoMQTT,GPIOdata);
if (GPIOdata.size() > 0)
pub(subjectGPIOInputtoMQTT, GPIOdata);
}
}
// save the reading. Next time through the loop, it'll be the lastInputState:
lastInputState = reading;
}
#endif