mirror of
https://github.com/arendst/Tasmota.git
synced 2025-07-23 18:56:38 +00:00
Refactor device_present calculation
This commit is contained in:
parent
f0eef7771f
commit
a994c71de4
@ -233,6 +233,9 @@ void ButtonProbe(void) {
|
|||||||
void ButtonInit(void) {
|
void ButtonInit(void) {
|
||||||
bool ac_detect = (Settings->button_debounce % 10 == 9);
|
bool ac_detect = (Settings->button_debounce % 10 == 9);
|
||||||
Button.used = 0;
|
Button.used = 0;
|
||||||
|
/*
|
||||||
|
uint32_t last_used = 0;
|
||||||
|
*/
|
||||||
for (uint32_t i = 0; i < MAX_KEYS_SET; i++) {
|
for (uint32_t i = 0; i < MAX_KEYS_SET; i++) {
|
||||||
Button.last_state[i] = NOT_PRESSED;
|
Button.last_state[i] = NOT_PRESSED;
|
||||||
#ifdef ESP8266
|
#ifdef ESP8266
|
||||||
@ -261,14 +264,13 @@ void ButtonInit(void) {
|
|||||||
}
|
}
|
||||||
#endif // USE_ADC
|
#endif // USE_ADC
|
||||||
else {
|
else {
|
||||||
|
// Insert, Skip and Append virtual buttons
|
||||||
XdrvMailbox.index = i;
|
XdrvMailbox.index = i;
|
||||||
if (XdrvCall(FUNC_ADD_BUTTON)) {
|
if (XdrvCall(FUNC_ADD_BUTTON)) {
|
||||||
/*
|
// At entry:
|
||||||
At entry:
|
// XdrvMailbox.index = button index
|
||||||
XdrvMailbox.index = button index
|
// At exit:
|
||||||
At exit:
|
// XdrvMailbox.index bit 0 = current state
|
||||||
XdrvMailbox.index bit 0 = current state
|
|
||||||
*/
|
|
||||||
bitSet(Button.used, i); // This pin is used
|
bitSet(Button.used, i); // This pin is used
|
||||||
bool state = (XdrvMailbox.index &1);
|
bool state = (XdrvMailbox.index &1);
|
||||||
ButtonSetVirtualPinState(i, state); // Virtual hardware pin state
|
ButtonSetVirtualPinState(i, state); // Virtual hardware pin state
|
||||||
@ -280,8 +282,38 @@ void ButtonInit(void) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
Button.debounced_state[i] = Button.last_state[i];
|
Button.debounced_state[i] = Button.last_state[i];
|
||||||
|
/*
|
||||||
|
if (bitRead(Button.used, i)) {
|
||||||
|
last_used = i +1;
|
||||||
|
}
|
||||||
|
*/
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
// Append virtual buttons
|
||||||
|
for (uint32_t i = last_used; i < MAX_KEYS_SET; i++) {
|
||||||
|
Button.last_state[i] = NOT_PRESSED;
|
||||||
|
|
||||||
|
XdrvMailbox.index = i;
|
||||||
|
if (XdrvCall(FUNC_ADD_BUTTON)) {
|
||||||
|
// At entry:
|
||||||
|
// XdrvMailbox.index = button index
|
||||||
|
// At exit:
|
||||||
|
// XdrvMailbox.index bit 0 = current state
|
||||||
|
bitSet(Button.used, i); // This pin is used
|
||||||
|
bool state = (XdrvMailbox.index &1);
|
||||||
|
ButtonSetVirtualPinState(i, state); // Virtual hardware pin state
|
||||||
|
if (!state) { ButtonInvertFlag(i); } // Set inverted flag
|
||||||
|
// last_state[i] must be 1 to indicate no button pressed
|
||||||
|
Button.last_state[i] = (bitRead(Button.virtual_pin, i) != bitRead(Button.inverted_mask, i));
|
||||||
|
|
||||||
|
AddLog(LOG_LEVEL_DEBUG, PSTR("BTN: Add vButton%d, State %d"), i +1, Button.last_state[i]);
|
||||||
|
}
|
||||||
|
|
||||||
|
Button.debounced_state[i] = Button.last_state[i];
|
||||||
|
}
|
||||||
|
*/
|
||||||
|
|
||||||
// AddLog(LOG_LEVEL_DEBUG, PSTR("BTN: vPinUsed %08X, State %08X, Invert %08X"), Button.used, Button.virtual_pin, Button.inverted_mask);
|
// AddLog(LOG_LEVEL_DEBUG, PSTR("BTN: vPinUsed %08X, State %08X, Invert %08X"), Button.used, Button.virtual_pin, Button.inverted_mask);
|
||||||
|
|
||||||
if (Button.used) { // Any bit set
|
if (Button.used) { // Any bit set
|
||||||
|
@ -2196,6 +2196,22 @@ void GpioInit(void)
|
|||||||
XdrvCall(FUNC_I2C_INIT); // Init RTC
|
XdrvCall(FUNC_I2C_INIT); // Init RTC
|
||||||
|
|
||||||
TasmotaGlobal.devices_present = 0;
|
TasmotaGlobal.devices_present = 0;
|
||||||
|
uint32_t bi_device = 0;
|
||||||
|
for (uint32_t i = 0; i < MAX_RELAYS; i++) {
|
||||||
|
if (PinUsed(GPIO_REL1, i)) {
|
||||||
|
TasmotaGlobal.devices_present++;
|
||||||
|
#ifdef ESP8266
|
||||||
|
if (EXS_RELAY == TasmotaGlobal.module_type) {
|
||||||
|
if (i &1) { TasmotaGlobal.devices_present--; }
|
||||||
|
}
|
||||||
|
#endif // ESP8266
|
||||||
|
if (bitRead(TasmotaGlobal.rel_bistable, i)) {
|
||||||
|
if (bi_device &1) { TasmotaGlobal.devices_present--; }
|
||||||
|
bi_device++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
TasmotaGlobal.light_type = LT_BASIC; // Use basic PWM control if SetOption15 = 0
|
TasmotaGlobal.light_type = LT_BASIC; // Use basic PWM control if SetOption15 = 0
|
||||||
|
|
||||||
XsnsCall(FUNC_MODULE_INIT);
|
XsnsCall(FUNC_MODULE_INIT);
|
||||||
@ -2225,22 +2241,6 @@ void GpioInit(void)
|
|||||||
|
|
||||||
GpioInitPwm();
|
GpioInitPwm();
|
||||||
|
|
||||||
uint32_t bi_device = 0;
|
|
||||||
for (uint32_t i = 0; i < MAX_RELAYS; i++) {
|
|
||||||
if (PinUsed(GPIO_REL1, i)) {
|
|
||||||
TasmotaGlobal.devices_present++;
|
|
||||||
#ifdef ESP8266
|
|
||||||
if (EXS_RELAY == TasmotaGlobal.module_type) {
|
|
||||||
if (i &1) { TasmotaGlobal.devices_present--; }
|
|
||||||
}
|
|
||||||
#endif // ESP8266
|
|
||||||
if (bitRead(TasmotaGlobal.rel_bistable, i)) {
|
|
||||||
if (bi_device &1) { TasmotaGlobal.devices_present--; }
|
|
||||||
bi_device++;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
for (uint32_t i = 0; i < MAX_LEDS; i++) {
|
for (uint32_t i = 0; i < MAX_LEDS; i++) {
|
||||||
if (PinUsed(GPIO_LED1, i)) {
|
if (PinUsed(GPIO_LED1, i)) {
|
||||||
#ifdef USE_ARILUX_RF
|
#ifdef USE_ARILUX_RF
|
||||||
|
@ -163,21 +163,7 @@ void TmInit(void) {
|
|||||||
}
|
}
|
||||||
digitalWrite(Tm1638.strobe_pin, HIGH);
|
digitalWrite(Tm1638.strobe_pin, HIGH);
|
||||||
|
|
||||||
// Dirty hack to offset TM1638 leds from GPIO relays
|
Tm1638.led_offset = TasmotaGlobal.devices_present;
|
||||||
// At this time in code sequence the number of GPIO relays has not been established
|
|
||||||
uint32_t bi_device = 0;
|
|
||||||
uint32_t devices_present = 0;
|
|
||||||
for (uint32_t i = 0; i < MAX_RELAYS; i++) {
|
|
||||||
if (PinUsed(GPIO_REL1, i)) {
|
|
||||||
devices_present++;
|
|
||||||
if (bitRead(TasmotaGlobal.rel_bistable, i)) {
|
|
||||||
if (bi_device &1) { devices_present--; }
|
|
||||||
bi_device++;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
Tm1638.led_offset = devices_present;
|
|
||||||
TasmotaGlobal.devices_present += TM1638_MAX_LEDS;
|
TasmotaGlobal.devices_present += TM1638_MAX_LEDS;
|
||||||
Tm1638.key_offset = -1;
|
Tm1638.key_offset = -1;
|
||||||
Tm1638.detected = true;
|
Tm1638.detected = true;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user