Merge branch 'mega' into bugfix/p016-correct-signed-conversion-to-unsigned

This commit is contained in:
Ton Huisman
2021-06-05 22:11:04 +02:00
committed by GitHub
5 changed files with 68 additions and 23 deletions
-20
View File
@@ -129,26 +129,6 @@ boolean Plugin_003(byte function, struct EventStruct *event, String& string)
break;
}
case PLUGIN_WEBFORM_SHOW_VALUES:
{
unsigned long pulseCounter, pulseCounterTotal = 0;
float pulseTime_msec = 0.0;
P003_data_struct *P003_data =
static_cast<P003_data_struct *>(getPluginTaskData(event->TaskIndex));
if (nullptr != P003_data) {
P003_data->pulseHelper.getPulseCounters(pulseCounter, pulseCounterTotal, pulseTime_msec);
}
pluginWebformShowValue(ExtraTaskSettings.TaskDeviceValueNames[P003_IDX_pulseCounter], String(pulseCounter));
pluginWebformShowValue(ExtraTaskSettings.TaskDeviceValueNames[P003_IDX_pulseTotalCounter], String(pulseCounterTotal));
pluginWebformShowValue(ExtraTaskSettings.TaskDeviceValueNames[P003_IDX_pulseTime], String(pulseTime_msec), false);
success = true;
break;
}
case PLUGIN_INIT:
{
Internal_GPIO_pulseHelper::pulseCounterConfig config;
+12
View File
@@ -535,6 +535,18 @@ void createAndSetPortStatus_Mode_State(uint32_t key, byte newMode, int8_t newSta
{
// WARNING: operator [] creates an entry in the map if key does not exist
#ifdef ESP32
switch (newMode) {
case PIN_MODE_PWM:
case PIN_MODE_SERVO:
break;
default:
checkAndClearPWM(key);
break;
}
#endif
// If it doesn't exist, it is now created.
globalMapPortStatus[key].mode = newMode;
auto it = globalMapPortStatus.find(key);
+6 -3
View File
@@ -36,6 +36,9 @@ void hardwareInit()
const bool serialPinConflict = (Settings.UseSerial && (gpio == 1 || gpio == 3));
if (!serialPinConflict) {
const uint32_t key = createKey(1, gpio);
#ifdef ESP32
checkAndClearPWM(key);
#endif
if (getGpioPullResistor(gpio, hasPullUp, hasPullDown)) {
const PinBootState bootState = Settings.getPinBootState(gpio);
if (bootState != PinBootState::Default_state) {
@@ -1191,11 +1194,11 @@ bool set_Gpio_PWM(int gpio, uint32_t dutyCycle, uint32_t fadeDuration_ms, uint32
pinMode(gpio, OUTPUT);
#endif // if defined(ESP8266)
#if defined(ESP8266)
if ((frequency > 0) && (frequency <= 40000)) {
#if defined(ESP8266)
analogWriteFreq(frequency);
#endif // if defined(ESP8266)
}
#endif // if defined(ESP8266)
if (fadeDuration_ms != 0)
{
@@ -1220,7 +1223,7 @@ bool set_Gpio_PWM(int gpio, uint32_t dutyCycle, uint32_t fadeDuration_ms, uint32
analogWrite(gpio, new_value);
#endif // if defined(ESP8266)
#if defined(ESP32)
analogWriteESP32(gpio, new_value);
frequency = analogWriteESP32(gpio, new_value, frequency);
#endif // if defined(ESP32)
delay(1);
}
+44
View File
@@ -6,6 +6,27 @@
#include "../../ESPEasy-Globals.h"
#ifdef ESP32
#include "../Helpers/Hardware.h"
void checkAndClearPWM(uint32_t key) {
if (existPortStatus(key)) {
switch (globalMapPortStatus[key].mode) {
case PIN_MODE_PWM:
case PIN_MODE_SERVO:
{
const uint16_t port = getPortFromKey(key);
analogWriteESP32(port, 0);
}
break;
}
}
}
#endif
/**********************************************************
* *
* Helper Functions for managing the status data structure *
@@ -14,9 +35,24 @@
void savePortStatus(uint32_t key, struct portStatusStruct& tempStatus) {
// FIXME TD-er: task and monitor are unsigned, should we only check for == ????
if ((tempStatus.task <= 0) && (tempStatus.monitor <= 0) && (tempStatus.command <= 0)) {
#ifdef ESP32
checkAndClearPWM(key);
#endif
globalMapPortStatus.erase(key);
}
else {
#ifdef ESP32
switch (tempStatus.mode) {
case PIN_MODE_PWM:
case PIN_MODE_SERVO:
break;
default:
checkAndClearPWM(key);
break;
}
#endif
globalMapPortStatus[key] = tempStatus;
}
}
@@ -33,6 +69,10 @@ void removeTaskFromPort(uint32_t key) {
if ((it->second.task <= 0) && (it->second.monitor <= 0) && (it->second.command <= 0) &&
(it->second.init <= 0)) {
// erase using the key, so the iterator can be const
#ifdef ESP32
checkAndClearPWM(key);
#endif
globalMapPortStatus.erase(key);
}
}
@@ -46,6 +86,10 @@ void removeMonitorFromPort(uint32_t key) {
if ((it->second.task <= 0) && (it->second.monitor <= 0) && (it->second.command <= 0) &&
(it->second.init <= 0)) {
// erase using the key, so the iterator can be const
#ifdef ESP32
checkAndClearPWM(key);
#endif
globalMapPortStatus.erase(key);
}
}
+6
View File
@@ -6,6 +6,12 @@
#include "../DataStructs/PortStatusStruct.h"
#include "../Globals/Plugins.h"
#ifdef ESP32
void checkAndClearPWM(uint32_t key);
#endif
/**********************************************************
* *
* Helper Functions for managing the status data structure *