mirror of https://github.com/arendst/Tasmota.git
First pass at led pwm settings
* Added settings for ledpwm_on and ledpwm_off with defaults that mimic current digitalwrite function * Changed ledpoweridx from digitalwrite to analogwrite * Add commands to change new settings
This commit is contained in:
parent
d3f1677c08
commit
a305f435e8
|
@ -586,6 +586,10 @@
|
|||
// Commands xsns_02_analog.ino
|
||||
#define D_CMND_ADCPARAM "AdcParam"
|
||||
|
||||
// Commands led pwm settings
|
||||
#define D_CMND_SETLEDPWMOFF "SetLedPwmOff"
|
||||
#define D_CMND_SETLEDPWMON "SetLedPwmOn"
|
||||
|
||||
/********************************************************************************************/
|
||||
|
||||
// Log message prefix
|
||||
|
|
|
@ -569,8 +569,10 @@ struct {
|
|||
uint16_t windmeter_pulse_debounce; // F3A
|
||||
int16_t windmeter_speed_factor; // F3C
|
||||
uint8_t windmeter_tele_pchange; // F3E
|
||||
uint16_t ledpwm_on; // F3F
|
||||
uint16_t ledpwm_off; // F41
|
||||
|
||||
uint8_t free_f3f[121]; // F3F - Decrement if adding new Setting variables just above and below
|
||||
uint8_t free_f42[117]; // F42 - Decrement if adding new Setting variables just above and below
|
||||
|
||||
// Only 32 bit boundary variables below
|
||||
uint16_t pulse_counter_debounce_low; // FB8
|
||||
|
|
|
@ -1055,6 +1055,10 @@ void SettingsDefaultSet2(void)
|
|||
Settings.flag2 = flag2;
|
||||
Settings.flag3 = flag3;
|
||||
Settings.flag4 = flag4;
|
||||
|
||||
// Led PWM
|
||||
Settings.ledpwm_off = 0;
|
||||
Settings.ledpwm_on = 1023;
|
||||
}
|
||||
|
||||
/********************************************************************************************/
|
||||
|
@ -1419,4 +1423,9 @@ void SettingsDelta(void)
|
|||
Settings.version = VERSION;
|
||||
SettingsSave(1);
|
||||
}
|
||||
// ledpwm
|
||||
if (Settings.version < 0x080300002) {
|
||||
Settings.ledpwm_off = 0;
|
||||
Settings.ledpwm_on = 1023;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -27,7 +27,7 @@ const char kTasmotaCommands[] PROGMEM = "|" // No prefix
|
|||
D_CMND_SERIALDELIMITER "|" D_CMND_IPADDRESS "|" D_CMND_NTPSERVER "|" D_CMND_AP "|" D_CMND_SSID "|" D_CMND_PASSWORD "|" D_CMND_HOSTNAME "|" D_CMND_WIFICONFIG "|"
|
||||
D_CMND_DEVICENAME "|" D_CMND_FRIENDLYNAME "|" D_CMND_SWITCHMODE "|" D_CMND_INTERLOCK "|" D_CMND_TELEPERIOD "|" D_CMND_RESET "|" D_CMND_TIME "|" D_CMND_TIMEZONE "|" D_CMND_TIMESTD "|"
|
||||
D_CMND_TIMEDST "|" D_CMND_ALTITUDE "|" D_CMND_LEDPOWER "|" D_CMND_LEDSTATE "|" D_CMND_LEDMASK "|" D_CMND_WIFIPOWER "|" D_CMND_TEMPOFFSET "|" D_CMND_HUMOFFSET "|"
|
||||
D_CMND_SPEEDUNIT "|" D_CMND_GLOBAL_TEMP "|" D_CMND_GLOBAL_HUM "|"
|
||||
D_CMND_SPEEDUNIT "|" D_CMND_GLOBAL_TEMP "|" D_CMND_GLOBAL_HUM "|" D_CMND_SETLEDPWMON "|" D_CMND_SETLEDPWMOFF "|"
|
||||
#ifdef USE_I2C
|
||||
D_CMND_I2CSCAN "|" D_CMND_I2CDRIVER "|"
|
||||
#endif
|
||||
|
@ -50,7 +50,7 @@ void (* const TasmotaCommand[])(void) PROGMEM = {
|
|||
&CmndSerialDelimiter, &CmndIpAddress, &CmndNtpServer, &CmndAp, &CmndSsid, &CmndPassword, &CmndHostname, &CmndWifiConfig,
|
||||
&CmndDevicename, &CmndFriendlyname, &CmndSwitchMode, &CmndInterlock, &CmndTeleperiod, &CmndReset, &CmndTime, &CmndTimezone, &CmndTimeStd,
|
||||
&CmndTimeDst, &CmndAltitude, &CmndLedPower, &CmndLedState, &CmndLedMask, &CmndWifiPower, &CmndTempOffset, &CmndHumOffset,
|
||||
&CmndSpeedUnit, &CmndGlobalTemp, &CmndGlobalHum,
|
||||
&CmndSpeedUnit, &CmndGlobalTemp, &CmndGlobalHum, &CmndSetLedPwmOn, &CmndSetLedPwmOff,
|
||||
#ifdef USE_I2C
|
||||
&CmndI2cScan, CmndI2cDriver,
|
||||
#endif
|
||||
|
@ -1890,3 +1890,27 @@ void CmndDriver(void)
|
|||
{
|
||||
XdrvCall(FUNC_COMMAND_DRIVER);
|
||||
}
|
||||
|
||||
void CmndSetLedPwmOff(void)
|
||||
{
|
||||
if ((XdrvMailbox.payload < 0) {
|
||||
Settings.ledpwm_off = 0;
|
||||
} else if (XdrvMailbox.payload > Settings.pwm_range) {
|
||||
Settings.ledpwm_off = Settings.pwm_range;
|
||||
} else {
|
||||
Settings.ledpwm_off = XdrvMailbox.payload;
|
||||
}
|
||||
ResponseCmndNumber(Settings.ledpwm_off);
|
||||
}
|
||||
|
||||
void CmndSetLedPwmOn(void)
|
||||
{
|
||||
if ((XdrvMailbox.payload < 0) {
|
||||
Settings.ledpwm_on = 0;
|
||||
} else if (XdrvMailbox.payload > Settings.pwm_range) {
|
||||
Settings.ledpwm_on = Settings.pwm_range;
|
||||
} else {
|
||||
Settings.ledpwm_on = XdrvMailbox.payload;
|
||||
}
|
||||
ResponseCmndNumber(Settings.ledpwm_on);
|
||||
}
|
|
@ -351,7 +351,13 @@ void SetLedPowerIdx(uint32_t led, uint32_t state)
|
|||
} else {
|
||||
led_power &= (0xFF ^ mask);
|
||||
}
|
||||
DigitalWrite(GPIO_LED1, led, bitRead(led_inverted, led) ? !state : state);
|
||||
uint16_t led_pwm_set = 0;
|
||||
if (bitRead(led_inverted, led)) {
|
||||
led_pwm_set = state ? Settings.pwm_range - Settings.ledpwm_on : Settings.pwm_range - Settings.ledpwm_off;
|
||||
} else {
|
||||
led_pwm_set = state ? Settings.ledpwm_on : Settings.ledpwm_off;
|
||||
}
|
||||
analogWrite(led, led_pwm_set)
|
||||
}
|
||||
#ifdef USE_BUZZER
|
||||
if (led == 0) {
|
||||
|
|
Loading…
Reference in New Issue