Fix ShutterClose Index display

Fix ShutterClose Index display (#6535)
This commit is contained in:
Theo Arends 2019-10-01 17:19:37 +02:00
parent be4867e7f6
commit ea7718c810
1 changed files with 17 additions and 16 deletions

View File

@ -441,7 +441,7 @@ void CmndShutterPosition(void)
// Code for shutters with circuit safe configuration, switch the direction Relay // Code for shutters with circuit safe configuration, switch the direction Relay
ExecuteCommandPower(Settings.shutter_startrelay[index] +1, new_shutterdirection == 1 ? 0 : 1, SRC_SHUTTER); ExecuteCommandPower(Settings.shutter_startrelay[index] +1, new_shutterdirection == 1 ? 0 : 1, SRC_SHUTTER);
// power on // power on
ExecuteCommandPower(Settings.shutter_startrelay[index] , 1, SRC_SHUTTER); ExecuteCommandPower(Settings.shutter_startrelay[index], 1, SRC_SHUTTER);
} else { } else {
// now start the motor for the right direction, work for momentary and normal shutters. // now start the motor for the right direction, work for momentary and normal shutters.
AddLog_P2(LOG_LEVEL_INFO, PSTR("SHT: Start shutter in direction %d"), Shutter.direction[index]); AddLog_P2(LOG_LEVEL_INFO, PSTR("SHT: Start shutter in direction %d"), Shutter.direction[index]);
@ -453,6 +453,7 @@ void CmndShutterPosition(void)
} else { } else {
target_pos_percent = ShutterRealToPercentPosition(Shutter.real_position[index], index); target_pos_percent = ShutterRealToPercentPosition(Shutter.real_position[index], index);
} }
XdrvMailbox.index = index +1;
ResponseCmndIdxNumber(Settings.shutter_invert[index] ? 100 - target_pos_percent : target_pos_percent); ResponseCmndIdxNumber(Settings.shutter_invert[index] ? 100 - target_pos_percent : target_pos_percent);
} }
} }
@ -461,11 +462,11 @@ void CmndShutterOpenTime(void)
{ {
if ((XdrvMailbox.index > 0) && (XdrvMailbox.index <= shutters_present)) { if ((XdrvMailbox.index > 0) && (XdrvMailbox.index <= shutters_present)) {
if (XdrvMailbox.data_len > 0) { if (XdrvMailbox.data_len > 0) {
Settings.shutter_opentime[XdrvMailbox.index-1] = (uint16_t)(10 * CharToFloat(XdrvMailbox.data)); Settings.shutter_opentime[XdrvMailbox.index -1] = (uint16_t)(10 * CharToFloat(XdrvMailbox.data));
ShutterInit(); ShutterInit();
} }
char time_chr[10]; char time_chr[10];
dtostrfd((float)(Settings.shutter_opentime[XdrvMailbox.index-1]) / 10, 1, time_chr); dtostrfd((float)(Settings.shutter_opentime[XdrvMailbox.index -1]) / 10, 1, time_chr);
ResponseCmndIdxChar(time_chr); ResponseCmndIdxChar(time_chr);
} }
} }
@ -474,11 +475,11 @@ void CmndShutterCloseTime(void)
{ {
if ((XdrvMailbox.index > 0) && (XdrvMailbox.index <= shutters_present)) { if ((XdrvMailbox.index > 0) && (XdrvMailbox.index <= shutters_present)) {
if (XdrvMailbox.data_len > 0) { if (XdrvMailbox.data_len > 0) {
Settings.shutter_closetime[XdrvMailbox.index-1] = (uint16_t)(10 * CharToFloat(XdrvMailbox.data)); Settings.shutter_closetime[XdrvMailbox.index -1] = (uint16_t)(10 * CharToFloat(XdrvMailbox.data));
ShutterInit(); ShutterInit();
} }
char time_chr[10]; char time_chr[10];
dtostrfd((float)(Settings.shutter_closetime[XdrvMailbox.index-1]) / 10, 1, time_chr); dtostrfd((float)(Settings.shutter_closetime[XdrvMailbox.index -1]) / 10, 1, time_chr);
ResponseCmndIdxChar(time_chr); ResponseCmndIdxChar(time_chr);
} }
} }
@ -487,14 +488,14 @@ void CmndShutterRelay(void)
{ {
if ((XdrvMailbox.index > 0) && (XdrvMailbox.index <= MAX_SHUTTERS)) { if ((XdrvMailbox.index > 0) && (XdrvMailbox.index <= MAX_SHUTTERS)) {
if ((XdrvMailbox.payload >= 0) && (XdrvMailbox.payload <= 64)) { if ((XdrvMailbox.payload >= 0) && (XdrvMailbox.payload <= 64)) {
Settings.shutter_startrelay[XdrvMailbox.index-1] = XdrvMailbox.payload; Settings.shutter_startrelay[XdrvMailbox.index -1] = XdrvMailbox.payload;
if (XdrvMailbox.payload > 0) { if (XdrvMailbox.payload > 0) {
Shutter.mask |= 3 << (XdrvMailbox.payload - 1); Shutter.mask |= 3 << (XdrvMailbox.payload - 1);
} else { } else {
Shutter.mask ^= 3 << (Settings.shutter_startrelay[XdrvMailbox.index-1] - 1); Shutter.mask ^= 3 << (Settings.shutter_startrelay[XdrvMailbox.index -1] - 1);
} }
AddLog_P2(LOG_LEVEL_INFO, PSTR("SHT: Relay %d is %d"), XdrvMailbox.index, XdrvMailbox.payload); AddLog_P2(LOG_LEVEL_INFO, PSTR("SHT: Relay %d is %d"), XdrvMailbox.index, XdrvMailbox.payload);
Settings.shutter_startrelay[XdrvMailbox.index-1] = XdrvMailbox.payload; Settings.shutter_startrelay[XdrvMailbox.index -1] = XdrvMailbox.payload;
ShutterInit(); ShutterInit();
// if payload is 0 to disable the relay there must be a reboot. Otherwhise does not work // if payload is 0 to disable the relay there must be a reboot. Otherwhise does not work
} }
@ -506,11 +507,11 @@ void CmndShutterSetHalfway(void)
{ {
if ((XdrvMailbox.index > 0) && (XdrvMailbox.index <= shutters_present)) { if ((XdrvMailbox.index > 0) && (XdrvMailbox.index <= shutters_present)) {
if ((XdrvMailbox.payload >= 0) && (XdrvMailbox.payload <= 100)) { if ((XdrvMailbox.payload >= 0) && (XdrvMailbox.payload <= 100)) {
Settings.shutter_set50percent[XdrvMailbox.index-1] = Settings.shutter_invert[XdrvMailbox.index-1] ? 100 - XdrvMailbox.payload : XdrvMailbox.payload; Settings.shutter_set50percent[XdrvMailbox.index -1] = Settings.shutter_invert[XdrvMailbox.index -1] ? 100 - XdrvMailbox.payload : XdrvMailbox.payload;
ShutterInit(); ShutterInit();
ResponseCmndIdxNumber(XdrvMailbox.payload); // ???? ResponseCmndIdxNumber(XdrvMailbox.payload); // ????
} else { } else {
ResponseCmndIdxNumber(Settings.shutter_set50percent[XdrvMailbox.index-1]); ResponseCmndIdxNumber(Settings.shutter_set50percent[XdrvMailbox.index -1]);
} }
} }
} }
@ -518,9 +519,9 @@ void CmndShutterSetHalfway(void)
void CmndShutterSetClose(void) void CmndShutterSetClose(void)
{ {
if ((XdrvMailbox.index > 0) && (XdrvMailbox.index <= shutters_present)) { if ((XdrvMailbox.index > 0) && (XdrvMailbox.index <= shutters_present)) {
Shutter.real_position[XdrvMailbox.index-1] = 0; Shutter.real_position[XdrvMailbox.index -1] = 0;
ShutterStartInit(XdrvMailbox.index-1, 0, 0); ShutterStartInit(XdrvMailbox.index -1, 0, 0);
Settings.shutter_position[XdrvMailbox.index-1] = 0; Settings.shutter_position[XdrvMailbox.index -1] = 0;
ResponseCmndChar(D_CONFIGURATION_RESET); ResponseCmndChar(D_CONFIGURATION_RESET);
} }
} }
@ -529,9 +530,9 @@ void CmndShutterInvert(void)
{ {
if ((XdrvMailbox.index > 0) && (XdrvMailbox.index <= shutters_present)) { if ((XdrvMailbox.index > 0) && (XdrvMailbox.index <= shutters_present)) {
if ((XdrvMailbox.payload >= 0) && (XdrvMailbox.payload <= 1)) { if ((XdrvMailbox.payload >= 0) && (XdrvMailbox.payload <= 1)) {
Settings.shutter_invert[XdrvMailbox.index-1] = XdrvMailbox.payload; Settings.shutter_invert[XdrvMailbox.index -1] = XdrvMailbox.payload;
} }
ResponseCmndIdxNumber(Settings.shutter_invert[XdrvMailbox.index-1]); ResponseCmndIdxNumber(Settings.shutter_invert[XdrvMailbox.index -1]);
} }
} }