diff --git a/compiled/esp8266-wifi/firmware.bin b/compiled/esp8266-wifi/firmware.bin index e8dfa8c..8a85a60 100644 Binary files a/compiled/esp8266-wifi/firmware.bin and b/compiled/esp8266-wifi/firmware.bin differ diff --git a/lighthub/inputs.cpp b/lighthub/inputs.cpp index 318395c..19677a1 100644 --- a/lighthub/inputs.cpp +++ b/lighthub/inputs.cpp @@ -449,39 +449,40 @@ void Input::contactPoll() { void Input::analogPoll() { - int16_t mappedInputVal; + int16_t inputVal; + int32_t mappedInputVal; // 100x inputVal aJsonObject *inputMap = aJson.getObjectItem(inputObj, "map"); - short Noize = ANALOG_NOIZE; + int16_t Noize = ANALOG_NOIZE; short simple = 0; - -/* -#if defined(ARDUINO_ARCH_STM32) - WiringPinMode inputPinMode; -#endif - - -#if defined(__SAM3X8E__)||defined(ARDUINO_ARCH_AVR)||defined(ARDUINO_ARCH_ESP8266)||defined(ARDUINO_ARCH_ESP32) -#endif */ uint32_t inputPinMode; + int max=1024*100; + int min=0; + + if (inType & IN_ACTIVE_HIGH) { inputPinMode = INPUT; } else { inputPinMode = INPUT_PULLUP; } pinMode(pin, inputPinMode); - mappedInputVal = analogRead(pin); + inputVal = analogRead(pin); // Mapping if (inputMap && inputMap->type == aJson_Array) { - int max=1024; + if (aJson.getArraySize(inputMap)>=4) - mappedInputVal = map (mappedInputVal, + mappedInputVal = map (inputVal, aJson.getArrayItem(inputMap, 0)->valueint, aJson.getArrayItem(inputMap, 1)->valueint, - aJson.getArrayItem(inputMap, 2)->valueint, - max=aJson.getArrayItem(inputMap, 3)->valueint); + min=aJson.getArrayItem(inputMap, 2)->valueint*100, + max=aJson.getArrayItem(inputMap, 3)->valueint*100); + else mappedInputVal = inputVal*100; + if (aJson.getArraySize(inputMap)==5) Noize = aJson.getArrayItem(inputMap, 4)->valueint; - if (mappedInputVal>max) mappedInputVal=max; + + if (mappedInputVal>max) mappedInputVal = max; + if (mappedInputValcurrentValue = mappedInputVal; }} else - if (abs(mappedInputVal - store->currentValue)>Noize) // value changed >ANALOG_NOIZE + //if (abs(mappedInputVal - store->currentValue)>Noize || mappedInputVal == min || mappedInputVal ==max) // value changed >ANALOG_NOIZE + if (abs(inputVal - store->currentValue)>Noize || mappedInputVal == min || mappedInputVal ==max) // value changed >ANALOG_NOIZE store->bounce = 0; else // no change if (store->bouncebounce ++; if (store->bouncecurrentValue)) //confirmed change { - onAnalogChanged(mappedInputVal); + onAnalogChanged(mappedInputVal/100.); + // store->currentValue = mappedInputVal; store->currentValue = mappedInputVal; } @@ -563,7 +566,7 @@ if (!strchr(addrstr,'/')) setTopic(addrstr,sizeof(addrstr),T_OUT,emit->valuestri } } -void Input::onAnalogChanged(int newValue) { +void Input::onAnalogChanged(float newValue) { debugSerial << F("IN:") << (pin) << F("=") << newValue << endl; aJsonObject *item = aJson.getObjectItem(inputObj, "item"); aJsonObject *emit = aJson.getObjectItem(inputObj, "emit"); @@ -581,15 +584,17 @@ void Input::onAnalogChanged(int newValue) { strncpy(addrstr,emit->valuestring,sizeof(addrstr)); if (!strchr(addrstr,'/')) setTopic(addrstr,sizeof(addrstr),T_OUT,emit->valuestring); char strVal[16]; - itoa(newValue,strVal,10); + //itoa(newValue,strVal,10); + printFloatValueToStr(newValue, strVal); if (mqttClient.connected() && !ethernetIdleCount) mqttClient.publish(addrstr, strVal, true); } if (item) { + int intNewValue = round(newValue); Item it(item->valuestring); if (it.isValid()) { - it.Ctrl(0, 1, &newValue, true); + it.Ctrl(0, 1, &intNewValue, true); } } } diff --git a/lighthub/inputs.h b/lighthub/inputs.h index 2722ffa..bbb50d9 100644 --- a/lighthub/inputs.h +++ b/lighthub/inputs.h @@ -103,7 +103,7 @@ public: boolean isValid(); void onContactChanged(int newValue); - void onAnalogChanged(int newValue); + void onAnalogChanged(float newValue); int poll(short cause); void setup();