Change pin handling part 1

This commit is contained in:
Theo Arends 2020-04-26 17:33:27 +02:00
parent f09d0a5c78
commit c9149b53c5
31 changed files with 225 additions and 195 deletions

View File

@ -1073,10 +1073,37 @@ int ResponseJsonEndEnd(void)
* GPIO Module and Template management
\*********************************************************************************************/
uint32_t Pin(uint32_t gpio, uint32_t index = 0);
uint32_t Pin(uint32_t gpio, uint32_t index) {
//#ifdef ESP8266
return pin[gpio + index]; // Pin number configured for gpio or 99 if not used
/*
#else
uint16_t real_gpio = (gpio << 5) + index;
for (uint32_t i = 0; i < ARRAY_SIZE(pin); i++) {
if (pin[i] == real_gpio) {
return i; // Pin number configured for gpio
}
}
return 99; // No pin used for gpio
#endif
*/
}
void SetPin(uint32_t lpin, uint32_t gpio) {
//#ifdef ESP8266
pin[gpio] = lpin;
/*
#else
pin[lpin] = gpio;
#endif
*/
}
void DigitalWrite(uint32_t gpio_pin, uint32_t state)
{
if (pin[gpio_pin] < 99) {
digitalWrite(pin[gpio_pin], state &1);
if (Pin(gpio_pin) < 99) {
digitalWrite(Pin(gpio_pin), state &1);
}
}

View File

@ -60,9 +60,9 @@ void ButtonInit(void)
{
Button.present = 0;
for (uint32_t i = 0; i < MAX_KEYS; i++) {
if (pin[GPIO_KEY1 +i] < 99) {
if (Pin(GPIO_KEY1, i) < 99) {
Button.present++;
pinMode(pin[GPIO_KEY1 +i], bitRead(Button.no_pullup_mask, i) ? INPUT : ((16 == pin[GPIO_KEY1 +i]) ? INPUT_PULLDOWN_16 : INPUT_PULLUP));
pinMode(Pin(GPIO_KEY1, i), bitRead(Button.no_pullup_mask, i) ? INPUT : ((16 == Pin(GPIO_KEY1, i)) ? INPUT_PULLDOWN_16 : INPUT_PULLUP));
}
#ifndef USE_ADC_VCC
else if ((99 == Button.adc) && ((ADC0_BUTTON == my_adc0) || (ADC0_BUTTON_INV == my_adc0))) {
@ -135,9 +135,9 @@ void ButtonHandler(void)
}
else
#endif // ESP8266
if (pin[GPIO_KEY1 +button_index] < 99) {
if (Pin(GPIO_KEY1, button_index) < 99) {
button_present = 1;
button = (digitalRead(pin[GPIO_KEY1 +button_index]) != bitRead(Button.inverted_mask, button_index));
button = (digitalRead(Pin(GPIO_KEY1, button_index)) != bitRead(Button.inverted_mask, button_index));
}
#ifndef USE_ADC_VCC
if (Button.adc == button_index) {

View File

@ -60,9 +60,9 @@ void ButtonInit(void)
{
Button.present = 0;
for (uint32_t i = 0; i < MAX_KEYS; i++) {
if (pin[GPIO_KEY1 +i] < 99) {
if (Pin(GPIO_KEY1, i) < 99) {
Button.present++;
pinMode(pin[GPIO_KEY1 +i], bitRead(Button.no_pullup_mask, i) ? INPUT : ((16 == pin[GPIO_KEY1 +i]) ? INPUT_PULLDOWN_16 : INPUT_PULLUP));
pinMode(Pin(GPIO_KEY1, i), bitRead(Button.no_pullup_mask, i) ? INPUT : ((16 == Pin(GPIO_KEY1, i)) ? INPUT_PULLDOWN_16 : INPUT_PULLUP));
}
#ifndef USE_ADC_VCC
else if ((99 == Button.adc) && ((ADC0_BUTTON == my_adc0) || (ADC0_BUTTON_INV == my_adc0))) {
@ -132,9 +132,9 @@ void ButtonHandler(void)
}
else
#endif // ESP8266
if (pin[GPIO_KEY1 +button_index] < 99) {
if (Pin(GPIO_KEY1, button_index) < 99) {
button_present = 1;
button = (digitalRead(pin[GPIO_KEY1 +button_index]) != bitRead(Button.inverted_mask, button_index));
button = (digitalRead(Pin(GPIO_KEY1, button_index)) != bitRead(Button.inverted_mask, button_index));
}
#ifndef USE_ADC_VCC
if (Button.adc == button_index) {
@ -266,9 +266,9 @@ void ButtonHandler(void)
} else {
SendKey(KEY_BUTTON, button_index +1, Button.press_counter[button_index] +9); // 2,3,4 and 5 press send just the key value (11,12,13 and 14) for rules
if (0 == button_index) { // BUTTON1 can toggle up to 5 relays if present. If a relay is not present will send out the key value (2,11,12,13 and 14) for rules
if ((Button.press_counter[button_index] > 1 && pin[GPIO_REL1 + Button.press_counter[button_index]-1] < 99) && Button.press_counter[button_index] <= MAX_RELAY_BUTTON1) {
if ((Button.press_counter[button_index] > 1 && Pin(GPIO_REL1, Button.press_counter[button_index]-1) < 99) && Button.press_counter[button_index] <= MAX_RELAY_BUTTON1) {
ExecuteCommandPower(button_index + Button.press_counter[button_index], POWER_TOGGLE, SRC_BUTTON); // Execute Toggle command internally
AddLog_P2(LOG_LEVEL_DEBUG, PSTR("DBG: Relay%d found on GPIO%d"), Button.press_counter[button_index], pin[GPIO_REL1 + Button.press_counter[button_index]-1]);
AddLog_P2(LOG_LEVEL_DEBUG, PSTR("DBG: Relay%d found on GPIO%d"), Button.press_counter[button_index], Pin(GPIO_REL1, Button.press_counter[button_index]-1));
}
}
}

View File

@ -1167,9 +1167,9 @@ void CmndTemplate(void)
void CmndPwm(void)
{
if (pwm_present && (XdrvMailbox.index > 0) && (XdrvMailbox.index <= MAX_PWMS)) {
if ((XdrvMailbox.payload >= 0) && (XdrvMailbox.payload <= Settings.pwm_range) && (pin[GPIO_PWM1 + XdrvMailbox.index -1] < 99)) {
if ((XdrvMailbox.payload >= 0) && (XdrvMailbox.payload <= Settings.pwm_range) && (Pin(GPIO_PWM1, XdrvMailbox.index -1) < 99)) {
Settings.pwm_value[XdrvMailbox.index -1] = XdrvMailbox.payload;
analogWrite(pin[GPIO_PWM1 + XdrvMailbox.index -1], bitRead(pwm_inverted, XdrvMailbox.index -1) ? Settings.pwm_range - XdrvMailbox.payload : XdrvMailbox.payload);
analogWrite(Pin(GPIO_PWM1, XdrvMailbox.index -1), bitRead(pwm_inverted, XdrvMailbox.index -1) ? Settings.pwm_range - XdrvMailbox.payload : XdrvMailbox.payload);
}
Response_P(PSTR("{"));
MqttShowPWMState(); // Render the PWM status to MQTT
@ -1694,7 +1694,7 @@ void CmndAltitude(void)
void CmndLedPower(void)
{
if ((XdrvMailbox.index > 0) && (XdrvMailbox.index <= MAX_LEDS)) {
if (99 == pin[GPIO_LEDLNK]) { XdrvMailbox.index = 1; }
if (99 == Pin(GPIO_LEDLNK)) { XdrvMailbox.index = 1; }
if ((XdrvMailbox.payload >= 0) && (XdrvMailbox.payload <= 2)) {
Settings.ledstate &= 8; // Disable power control
uint32_t mask = 1 << (XdrvMailbox.index -1); // Led to control
@ -1713,14 +1713,14 @@ void CmndLedPower(void)
break;
}
blinks = 0;
if (99 == pin[GPIO_LEDLNK]) {
if (99 == Pin(GPIO_LEDLNK)) {
SetLedPower(Settings.ledstate &8);
} else {
SetLedPowerIdx(XdrvMailbox.index -1, (led_power & mask));
}
}
bool state = bitRead(led_power, XdrvMailbox.index -1);
if (99 == pin[GPIO_LEDLNK]) {
if (99 == Pin(GPIO_LEDLNK)) {
state = bitRead(Settings.ledstate, 3);
}
ResponseCmndIdxChar(GetStateText(state));

View File

@ -49,8 +49,8 @@ void update_rotary(void)
*/
uint8_t s = Rotary.state & 3;
if (digitalRead(pin[GPIO_ROT1A])) { s |= 4; }
if (digitalRead(pin[GPIO_ROT1B])) { s |= 8; }
if (digitalRead(Pin(GPIO_ROT1A))) { s |= 4; }
if (digitalRead(Pin(GPIO_ROT1B))) { s |= 8; }
switch (s) {
case 0: case 5: case 10: case 15:
break;
@ -80,20 +80,20 @@ bool RotaryButtonPressed(void)
void RotaryInit(void)
{
Rotary.present = 0;
if ((pin[GPIO_ROT1A] < 99) && (pin[GPIO_ROT1B] < 99)) {
if ((Pin(GPIO_ROT1A) < 99) && (Pin(GPIO_ROT1B) < 99)) {
Rotary.present++;
pinMode(pin[GPIO_ROT1A], INPUT_PULLUP);
pinMode(pin[GPIO_ROT1B], INPUT_PULLUP);
pinMode(Pin(GPIO_ROT1A), INPUT_PULLUP);
pinMode(Pin(GPIO_ROT1B), INPUT_PULLUP);
// GPIO6-GPIO11 are typically used to interface with the flash memory IC on
// most esp8266 modules, so we should avoid adding interrupts to these pins.
if ((pin[GPIO_ROT1A] < 6) || (pin[GPIO_ROT1A] > 11)) {
attachInterrupt(digitalPinToInterrupt(pin[GPIO_ROT1A]), update_rotary, CHANGE);
if ((Pin(GPIO_ROT1A) < 6) || (Pin(GPIO_ROT1A) > 11)) {
attachInterrupt(digitalPinToInterrupt(Pin(GPIO_ROT1A)), update_rotary, CHANGE);
Rotary.interrupts_in_use_count++;
}
if ((pin[GPIO_ROT1B] < 6) || (pin[GPIO_ROT1B] > 11)) {
attachInterrupt(digitalPinToInterrupt(pin[GPIO_ROT1B]), update_rotary, CHANGE);
if ((Pin(GPIO_ROT1B) < 6) || (Pin(GPIO_ROT1B) > 11)) {
attachInterrupt(digitalPinToInterrupt(Pin(GPIO_ROT1B)), update_rotary, CHANGE);
Rotary.interrupts_in_use_count++;
}
}

View File

@ -86,9 +86,9 @@ void SwitchProbe(void)
uint8_t force_low = (Settings.switch_debounce % 50) &2; // 52, 102, 152 etc
for (uint32_t i = 0; i < MAX_SWITCHES; i++) {
if (pin[GPIO_SWT1 +i] < 99) {
if (Pin(GPIO_SWT1, i) < 99) {
// Olimex user_switch2.c code to fix 50Hz induced pulses
if (1 == digitalRead(pin[GPIO_SWT1 +i])) {
if (1 == digitalRead(Pin(GPIO_SWT1, i))) {
if (force_high) { // Enabled with SwitchDebounce x1
if (1 == Switch.virtual_state[i]) {
@ -127,10 +127,10 @@ void SwitchInit(void)
Switch.present = 0;
for (uint32_t i = 0; i < MAX_SWITCHES; i++) {
Switch.last_state[i] = 1; // Init global to virtual switch state;
if (pin[GPIO_SWT1 +i] < 99) {
if (Pin(GPIO_SWT1, i) < 99) {
Switch.present++;
pinMode(pin[GPIO_SWT1 +i], bitRead(Switch.no_pullup_mask, i) ? INPUT : ((16 == pin[GPIO_SWT1 +i]) ? INPUT_PULLDOWN_16 : INPUT_PULLUP));
Switch.last_state[i] = digitalRead(pin[GPIO_SWT1 +i]); // Set global now so doesn't change the saved power state on first switch check
pinMode(Pin(GPIO_SWT1, i), bitRead(Switch.no_pullup_mask, i) ? INPUT : ((16 == Pin(GPIO_SWT1, i)) ? INPUT_PULLDOWN_16 : INPUT_PULLUP));
Switch.last_state[i] = digitalRead(Pin(GPIO_SWT1, i)); // Set global now so doesn't change the saved power state on first switch check
}
Switch.virtual_state[i] = Switch.last_state[i];
}
@ -148,7 +148,7 @@ void SwitchHandler(uint8_t mode)
uint16_t loops_per_second = 1000 / Settings.switch_debounce;
for (uint32_t i = 0; i < MAX_SWITCHES; i++) {
if ((pin[GPIO_SWT1 +i] < 99) || (mode)) {
if ((Pin(GPIO_SWT1, i) < 99) || (mode)) {
uint8_t button = Switch.virtual_state[i];
uint8_t switchflag = POWER_TOGGLE +1;

View File

@ -325,8 +325,8 @@ void SetPowerOnState(void)
// Issue #526 and #909
for (uint32_t i = 0; i < devices_present; i++) {
if (!Settings.flag3.no_power_feedback) { // SetOption63 - Don't scan relay power state at restart - #5594 and #5663
if ((i < MAX_RELAYS) && (pin[GPIO_REL1 +i] < 99)) {
bitWrite(power, i, digitalRead(pin[GPIO_REL1 +i]) ^ bitRead(rel_inverted, i));
if ((i < MAX_RELAYS) && (Pin(GPIO_REL1, i) < 99)) {
bitWrite(power, i, digitalRead(Pin(GPIO_REL1, i)) ^ bitRead(rel_inverted, i));
}
}
if ((i < MAX_PULSETIMERS) && (bitRead(power, i) || (POWER_ALL_OFF_PULSETIME_ON == Settings.poweronstate))) {
@ -338,12 +338,12 @@ void SetPowerOnState(void)
void SetLedPowerIdx(uint32_t led, uint32_t state)
{
if ((99 == pin[GPIO_LEDLNK]) && (0 == led)) { // Legacy - LED1 is link led only if LED2 is present
if (pin[GPIO_LED1 +1] < 99) {
if ((99 == Pin(GPIO_LEDLNK)) && (0 == led)) { // Legacy - LED1 is link led only if LED2 is present
if (Pin(GPIO_LED1, 1) < 99) {
led = 1;
}
}
if (pin[GPIO_LED1 + led] < 99) {
if (Pin(GPIO_LED1, led) < 99) {
uint32_t mask = 1 << led;
if (state) {
state = 1;
@ -351,7 +351,7 @@ void SetLedPowerIdx(uint32_t led, uint32_t state)
} else {
led_power &= (0xFF ^ mask);
}
DigitalWrite(GPIO_LED1 + led, bitRead(led_inverted, led) ? !state : state);
DigitalWrite(Pin(GPIO_LED1, led), bitRead(led_inverted, led) ? !state : state);
}
#ifdef USE_BUZZER
if (led == 0) {
@ -362,7 +362,7 @@ void SetLedPowerIdx(uint32_t led, uint32_t state)
void SetLedPower(uint32_t state)
{
if (99 == pin[GPIO_LEDLNK]) { // Legacy - Only use LED1 and/or LED2
if (99 == Pin(GPIO_LEDLNK)) { // Legacy - Only use LED1 and/or LED2
SetLedPowerIdx(0, state);
} else {
power_t mask = 1;
@ -383,10 +383,10 @@ void SetLedPowerAll(uint32_t state)
void SetLedLink(uint32_t state)
{
uint32_t led_pin = pin[GPIO_LEDLNK];
uint32_t led_pin = Pin(GPIO_LEDLNK);
uint32_t led_inv = ledlnk_inverted;
if (99 == led_pin) { // Legacy - LED1 is status
led_pin = pin[GPIO_LED1];
led_pin = Pin(GPIO_LED1);
led_inv = bitRead(led_inverted, 0);
}
if (led_pin < 99) {
@ -608,7 +608,7 @@ void MqttShowPWMState(void)
ResponseAppend_P(PSTR("\"" D_CMND_PWM "\":{"));
bool first = true;
for (uint32_t i = 0; i < MAX_PWMS; i++) {
if (pin[GPIO_PWM1 + i] < 99) {
if (Pin(GPIO_PWM1, i) < 99) {
ResponseAppend_P(PSTR("%s\"" D_CMND_PWM "%d\":%d"), first ? "" : ",", i+1, Settings.pwm_value[i]);
first = false;
}
@ -703,9 +703,9 @@ bool MqttShowSensor(void)
int json_data_start = strlen(mqtt_data);
for (uint32_t i = 0; i < MAX_SWITCHES; i++) {
#ifdef USE_TM1638
if ((pin[GPIO_SWT1 +i] < 99) || ((pin[GPIO_TM16CLK] < 99) && (pin[GPIO_TM16DIO] < 99) && (pin[GPIO_TM16STB] < 99))) {
if ((Pin(GPIO_SWT1, i) < 99) || ((Pin(GPIO_TM16CLK) < 99) && (Pin(GPIO_TM16DIO) < 99) && (Pin(GPIO_TM16STB) < 99))) {
#else
if (pin[GPIO_SWT1 +i] < 99) {
if (Pin(GPIO_SWT1, i) < 99) {
#endif // USE_TM1638
ResponseAppend_P(PSTR(",\"" D_JSON_SWITCH "%d\":\"%s\""), i +1, GetStateText(SwitchState(i)));
}
@ -913,7 +913,7 @@ void Every250mSeconds(void)
if (200 == blinks) blinks = 0; // Disable blink
}
}
if (Settings.ledstate &1 && (pin[GPIO_LEDLNK] < 99 || !(blinks || restart_flag || ota_state_flag)) ) {
if (Settings.ledstate &1 && (Pin(GPIO_LEDLNK) < 99 || !(blinks || restart_flag || ota_state_flag)) ) {
bool tstate = power & Settings.ledmask;
#ifdef ESP8266
if ((SONOFF_TOUCH == my_module_type) || (SONOFF_T11 == my_module_type) || (SONOFF_T12 == my_module_type) || (SONOFF_T13 == my_module_type)) {
@ -1320,9 +1320,9 @@ void SerialInput(void)
void ResetPwm(void)
{
for (uint32_t i = 0; i < MAX_PWMS; i++) { // Basic PWM control only
if (pin[GPIO_PWM1 +i] < 99) {
analogWrite(pin[GPIO_PWM1 +i], bitRead(pwm_inverted, i) ? Settings.pwm_range : 0);
// analogWrite(pin[GPIO_PWM1 +i], bitRead(pwm_inverted, i) ? Settings.pwm_range - Settings.pwm_value[i] : Settings.pwm_value[i]);
if (Pin(GPIO_PWM1, i) < 99) {
analogWrite(Pin(GPIO_PWM1, i), bitRead(pwm_inverted, i) ? Settings.pwm_range : 0);
// analogWrite(Pin(GPIO_PWM1, i), bitRead(pwm_inverted, i) ? Settings.pwm_range - Settings.pwm_value[i] : Settings.pwm_value[i]);
}
}
}
@ -1331,8 +1331,6 @@ void ResetPwm(void)
void GpioInit(void)
{
uint32_t mpin;
if (!ValidModule(Settings.module)) {
uint32_t module = MODULE;
if (!ValidModule(MODULE)) {
@ -1386,10 +1384,10 @@ void GpioInit(void)
}
for (uint32_t i = 0; i < GPIO_MAX; i++) {
pin[i] = 99;
SetPin(99, i);
}
for (uint32_t i = 0; i < ARRAY_SIZE(my_module.io); i++) {
mpin = ValidPin(i, my_module.io[i]);
uint32_t mpin = ValidPin(i, my_module.io[i]);
DEBUG_CORE_LOG(PSTR("INI: gpio pin %d, mpin %d"), i, mpin);
@ -1437,36 +1435,36 @@ void GpioInit(void)
mpin = XdrvMailbox.index;
};
}
if (mpin) pin[mpin] = i;
if (mpin) { SetPin(i, mpin); }
}
#ifdef ESP8266
if ((2 == pin[GPIO_TXD]) || (H801 == my_module_type)) { Serial.set_tx(2); }
if ((2 == Pin(GPIO_TXD)) || (H801 == my_module_type)) { Serial.set_tx(2); }
#endif // ESP8266
analogWriteRange(Settings.pwm_range); // Default is 1023 (Arduino.h)
analogWriteFreq(Settings.pwm_frequency); // Default is 1000 (core_esp8266_wiring_pwm.c)
#ifdef USE_SPI
spi_flg = ((((pin[GPIO_SPI_CS] < 99) && (pin[GPIO_SPI_CS] > 14)) || (pin[GPIO_SPI_CS] < 12)) || (((pin[GPIO_SPI_DC] < 99) && (pin[GPIO_SPI_DC] > 14)) || (pin[GPIO_SPI_DC] < 12)));
spi_flg = ((((Pin(GPIO_SPI_CS) < 99) && (Pin(GPIO_SPI_CS) > 14)) || (Pin(GPIO_SPI_CS) < 12)) || (((Pin(GPIO_SPI_DC) < 99) && (Pin(GPIO_SPI_DC) > 14)) || (Pin(GPIO_SPI_DC) < 12)));
if (spi_flg) {
for (uint32_t i = 0; i < GPIO_MAX; i++) {
if ((pin[i] >= 12) && (pin[i] <=14)) pin[i] = 99;
if ((Pin(i) >= 12) && (Pin(i) <=14)) { SetPin(99, i); }
}
my_module.io[12] = GPIO_SPI_MISO;
pin[GPIO_SPI_MISO] = 12;
SetPin(12, GPIO_SPI_MISO);
my_module.io[13] = GPIO_SPI_MOSI;
pin[GPIO_SPI_MOSI] = 13;
SetPin(13, GPIO_SPI_MOSI);
my_module.io[14] = GPIO_SPI_CLK;
pin[GPIO_SPI_CLK] = 14;
SetPin(14, GPIO_SPI_CLK);
}
soft_spi_flg = ((pin[GPIO_SSPI_CS] < 99) && (pin[GPIO_SSPI_SCLK] < 99) && ((pin[GPIO_SSPI_MOSI] < 99) || (pin[GPIO_SSPI_MOSI] < 99)));
soft_spi_flg = ((Pin(GPIO_SSPI_CS) < 99) && (Pin(GPIO_SSPI_SCLK) < 99) && ((Pin(GPIO_SSPI_MOSI) < 99) || (Pin(GPIO_SSPI_MOSI) < 99)));
#endif // USE_SPI
// Set any non-used GPIO to INPUT - Related to resetPins() in support_legacy_cores.ino
// Doing it here solves relay toggles at restart.
for (uint32_t i = 0; i < ARRAY_SIZE(my_module.io); i++) {
mpin = ValidPin(i, my_module.io[i]);
uint32_t mpin = ValidPin(i, my_module.io[i]);
// AddLog_P2(LOG_LEVEL_DEBUG, PSTR("INI: gpio pin %d, mpin %d"), i, mpin);
if (((i < 6) || (i > 11)) && (0 == mpin)) { // Skip SPI flash interface
if (!((1 == i) || (3 == i))) { // Skip serial
@ -1476,9 +1474,9 @@ void GpioInit(void)
}
#ifdef USE_I2C
i2c_flg = ((pin[GPIO_I2C_SCL] < 99) && (pin[GPIO_I2C_SDA] < 99));
i2c_flg = ((Pin(GPIO_I2C_SCL) < 99) && (Pin(GPIO_I2C_SDA) < 99));
if (i2c_flg) {
Wire.begin(pin[GPIO_I2C_SDA], pin[GPIO_I2C_SCL]);
Wire.begin(Pin(GPIO_I2C_SDA), Pin(GPIO_I2C_SCL));
}
#endif // USE_I2C
@ -1508,25 +1506,25 @@ void GpioInit(void)
#endif // ESP8266
for (uint32_t i = 0; i < MAX_PWMS; i++) { // Basic PWM control only
if (pin[GPIO_PWM1 +i] < 99) {
pinMode(pin[GPIO_PWM1 +i], OUTPUT);
if (Pin(GPIO_PWM1, i) < 99) {
pinMode(Pin(GPIO_PWM1, i), OUTPUT);
if (light_type) {
// force PWM GPIOs to low or high mode, see #7165
analogWrite(pin[GPIO_PWM1 +i], bitRead(pwm_inverted, i) ? Settings.pwm_range : 0);
analogWrite(Pin(GPIO_PWM1, i), bitRead(pwm_inverted, i) ? Settings.pwm_range : 0);
} else {
pwm_present = true;
analogWrite(pin[GPIO_PWM1 +i], bitRead(pwm_inverted, i) ? Settings.pwm_range - Settings.pwm_value[i] : Settings.pwm_value[i]);
analogWrite(Pin(GPIO_PWM1, i), bitRead(pwm_inverted, i) ? Settings.pwm_range - Settings.pwm_value[i] : Settings.pwm_value[i]);
}
}
}
for (uint32_t i = 0; i < MAX_RELAYS; i++) {
if (pin[GPIO_REL1 +i] < 99) {
pinMode(pin[GPIO_REL1 +i], OUTPUT);
if (Pin(GPIO_REL1, i) < 99) {
pinMode(Pin(GPIO_REL1, i), OUTPUT);
devices_present++;
#ifdef ESP8266
if (EXS_RELAY == my_module_type) {
digitalWrite(pin[GPIO_REL1 +i], bitRead(rel_inverted, i) ? 1 : 0);
digitalWrite(Pin(GPIO_REL1, i), bitRead(rel_inverted, i) ? 1 : 0);
if (i &1) { devices_present--; }
}
#endif // ESP8266
@ -1534,28 +1532,28 @@ void GpioInit(void)
}
for (uint32_t i = 0; i < MAX_LEDS; i++) {
if (pin[GPIO_LED1 +i] < 99) {
if (Pin(GPIO_LED1, i) < 99) {
#ifdef USE_ARILUX_RF
if ((3 == i) && (leds_present < 2) && (99 == pin[GPIO_ARIRFSEL])) {
pin[GPIO_ARIRFSEL] = pin[GPIO_LED4]; // Legacy support where LED4 was Arilux RF enable
pin[GPIO_LED4] = 99;
if ((3 == i) && (leds_present < 2) && (99 == Pin(GPIO_ARIRFSEL))) {
SetPin(Pin(GPIO_LED4), GPIO_ARIRFSEL); // Legacy support where LED4 was Arilux RF enable
SetPin(99, GPIO_LED4);
} else {
#endif
pinMode(pin[GPIO_LED1 +i], OUTPUT);
pinMode(Pin(GPIO_LED1, i), OUTPUT);
leds_present++;
digitalWrite(pin[GPIO_LED1 +i], bitRead(led_inverted, i));
digitalWrite(Pin(GPIO_LED1, i), bitRead(led_inverted, i));
#ifdef USE_ARILUX_RF
}
#endif
}
}
if (pin[GPIO_LEDLNK] < 99) {
pinMode(pin[GPIO_LEDLNK], OUTPUT);
digitalWrite(pin[GPIO_LEDLNK], ledlnk_inverted);
if (Pin(GPIO_LEDLNK) < 99) {
pinMode(Pin(GPIO_LEDLNK), OUTPUT);
digitalWrite(Pin(GPIO_LEDLNK), ledlnk_inverted);
}
#ifdef USE_PWM_DIMMER
if (PWM_DIMMER == my_module_type && pin[GPIO_REL1] < 99) devices_present--;
if (PWM_DIMMER == my_module_type && Pin(GPIO_REL1) < 99) { devices_present--; }
#endif // USE_PWM_DIMMER
ButtonInit();

View File

@ -118,6 +118,9 @@ uint16_t tele_period = 9999; // Tele period timer
uint16_t blink_counter = 0; // Number of blink cycles
uint16_t seriallog_timer = 0; // Timer to disable Seriallog
uint16_t syslog_timer = 0; // Timer to re-enable syslog_level
//#ifdef ESP32
//uint16_t pin[MAX_GPIO_PIN]; // Possible pin configurations
//#endif
int16_t save_data_counter; // Counter and flag for config save to Flash
RulesBitfield rules_flag; // Rule state flags (16 bits)
uint8_t mqtt_cmnd_blocked = 0; // Ignore flag for publish command
@ -126,7 +129,9 @@ uint8_t state_250mS = 0; // State 250msecond per second flag
uint8_t latching_relay_pulse = 0; // Latching relay pulse timer
uint8_t ssleep; // Current copy of Settings.sleep
uint8_t blinkspeed = 1; // LED blink rate
//#ifdef ESP8266
uint8_t pin[GPIO_MAX]; // Possible pin configurations
//#endif
uint8_t active_device = 1; // Active device in ExecuteCommandPower
uint8_t leds_present = 0; // Max number of LED supported
uint8_t led_inverted = 0; // LED inverted flag (1 = (0 = On, 1 = Off))

View File

@ -1244,7 +1244,7 @@ bool LightModuleInit(void)
if (Settings.flag.pwm_control) { // SetOption15 - Switch between commands PWM or COLOR/DIMMER/CT/CHANNEL
for (uint32_t i = 0; i < MAX_PWMS; i++) {
if (pin[GPIO_PWM1 +i] < 99) { light_type++; } // Use Dimmer/Color control for all PWM as SetOption15 = 1
if (Pin(GPIO_PWM1, i) < 99) { light_type++; } // Use Dimmer/Color control for all PWM as SetOption15 = 1
}
}
@ -1347,14 +1347,14 @@ void LightInit(void)
if (light_type < LT_PWM6) { // PWM
for (uint32_t i = 0; i < light_type; i++) {
Settings.pwm_value[i] = 0; // Disable direct PWM control
if (pin[GPIO_PWM1 +i] < 99) {
pinMode(pin[GPIO_PWM1 +i], OUTPUT);
if (Pin(GPIO_PWM1, i) < 99) {
pinMode(Pin(GPIO_PWM1, i), OUTPUT);
}
}
if (pin[GPIO_ARIRFRCV] < 99) {
if (pin[GPIO_ARIRFSEL] < 99) {
pinMode(pin[GPIO_ARIRFSEL], OUTPUT);
digitalWrite(pin[GPIO_ARIRFSEL], 1); // Turn off RF
if (Pin(GPIO_ARIRFRCV) < 99) {
if (Pin(GPIO_ARIRFSEL) < 99) {
pinMode(Pin(GPIO_ARIRFSEL), OUTPUT);
digitalWrite(Pin(GPIO_ARIRFSEL), 1); // Turn off RF
}
}
}
@ -2133,13 +2133,13 @@ void LightSetOutputs(const uint16_t *cur_col_10) {
// now apply the actual PWM values, adjusted and remapped 10-bits range
if (light_type < LT_PWM6) { // only for direct PWM lights, not for Tuya, Armtronix...
for (uint32_t i = 0; i < (Light.subtype - Light.pwm_offset); i++) {
if (pin[GPIO_PWM1 +i] < 99) {
if (Pin(GPIO_PWM1, i) < 99) {
//AddLog_P2(LOG_LEVEL_DEBUG, PSTR(D_LOG_APPLICATION "Cur_Col%d 10 bits %d"), i, cur_col_10[i]);
uint16_t cur_col = cur_col_10[i + Light.pwm_offset];
if (!isChannelCT(i)) { // if CT don't use pwm_min and pwm_max
cur_col = cur_col > 0 ? changeUIntScale(cur_col, 0, Settings.pwm_range, Light.pwm_min, Light.pwm_max) : 0; // shrink to the range of pwm_min..pwm_max
}
analogWrite(pin[GPIO_PWM1 +i], bitRead(pwm_inverted, i) ? Settings.pwm_range - cur_col : cur_col);
analogWrite(Pin(GPIO_PWM1, i), bitRead(pwm_inverted, i) ? Settings.pwm_range - cur_col : cur_col);
}
}
}

View File

@ -49,7 +49,7 @@ bool irsend_active = false;
void IrSendInit(void)
{
irsend = new IRsend(pin[GPIO_IRSEND]); // an IR led is at GPIO_IRSEND
irsend = new IRsend(Pin(GPIO_IRSEND)); // an IR led is at GPIO_IRSEND
irsend->begin();
}
@ -78,7 +78,7 @@ void IrReceiveUpdateThreshold(void)
void IrReceiveInit(void)
{
// an IR led is at GPIO_IRRECV
irrecv = new IRrecv(pin[GPIO_IRRECV], IR_RCV_BUFFER_SIZE, IR_RCV_TIMEOUT, IR_RCV_SAVE_BUFFER);
irrecv = new IRrecv(Pin(GPIO_IRRECV), IR_RCV_BUFFER_SIZE, IR_RCV_TIMEOUT, IR_RCV_SAVE_BUFFER);
irrecv->setUnknownThreshold(Settings.param[P_IR_UNKNOW_THRESHOLD]);
irrecv->enableIRIn(); // Start the receiver
@ -279,28 +279,28 @@ bool Xdrv05(uint8_t function)
{
bool result = false;
if ((pin[GPIO_IRSEND] < 99) || (pin[GPIO_IRRECV] < 99)) {
if ((Pin(GPIO_IRSEND) < 99) || (Pin(GPIO_IRRECV) < 99)) {
switch (function) {
case FUNC_PRE_INIT:
if (pin[GPIO_IRSEND] < 99) {
if (Pin(GPIO_IRSEND) < 99) {
IrSendInit();
}
#ifdef USE_IR_RECEIVE
if (pin[GPIO_IRRECV] < 99) {
if (Pin(GPIO_IRRECV) < 99) {
IrReceiveInit();
}
#endif // USE_IR_RECEIVE
break;
case FUNC_EVERY_50_MSECOND:
#ifdef USE_IR_RECEIVE
if (pin[GPIO_IRRECV] < 99) {
if (Pin(GPIO_IRRECV) < 99) {
IrReceiveCheck(); // check if there's anything on IR side
}
#endif // USE_IR_RECEIVE
irsend_active = false; // re-enable IR reception
break;
case FUNC_COMMAND:
if (pin[GPIO_IRSEND] < 99) {
if (Pin(GPIO_IRSEND) < 99) {
result = DecodeCommand(kIrRemoteCommands, IrRemoteCommand);
}
break;

View File

@ -48,7 +48,7 @@ bool irsend_active = false;
void IrSendInit(void)
{
irsend = new IRsend(pin[GPIO_IRSEND]); // an IR led is at GPIO_IRSEND
irsend = new IRsend(Pin(GPIO_IRSEND)); // an IR led is at GPIO_IRSEND
irsend->begin();
}
@ -105,7 +105,7 @@ void IrReceiveUpdateThreshold(void)
void IrReceiveInit(void)
{
// an IR led is at GPIO_IRRECV
irrecv = new IRrecv(pin[GPIO_IRRECV], IR_FULL_BUFFER_SIZE, IR__FULL_RCV_TIMEOUT, IR_FULL_RCV_SAVE_BUFFER);
irrecv = new IRrecv(Pin(GPIO_IRRECV), IR_FULL_BUFFER_SIZE, IR__FULL_RCV_TIMEOUT, IR_FULL_RCV_SAVE_BUFFER);
irrecv->setUnknownThreshold(Settings.param[P_IR_UNKNOW_THRESHOLD]);
irrecv->enableIRIn(); // Start the receiver
}
@ -365,7 +365,7 @@ uint32_t IrRemoteCmndIrHvacJson(void)
if (json[parm_uc]) { state.sleep = json[parm_uc]; }
//if (json[D_JSON_IRHVAC_CLOCK]) { state.clock = json[D_JSON_IRHVAC_CLOCK]; } // not sure it's useful to support 'clock'
IRac ac(pin[GPIO_IRSEND]);
IRac ac(Pin(GPIO_IRSEND));
bool success = ac.sendAc(state, &prev);
if (!success) { return IE_SYNTAX_IRHVAC; }
@ -635,24 +635,24 @@ bool Xdrv05(uint8_t function)
{
bool result = false;
if ((pin[GPIO_IRSEND] < 99) || (pin[GPIO_IRRECV] < 99)) {
if ((Pin(GPIO_IRSEND) < 99) || (Pin(GPIO_IRRECV) < 99)) {
switch (function) {
case FUNC_PRE_INIT:
if (pin[GPIO_IRSEND] < 99) {
if (Pin(GPIO_IRSEND) < 99) {
IrSendInit();
}
if (pin[GPIO_IRRECV] < 99) {
if (Pin(GPIO_IRRECV) < 99) {
IrReceiveInit();
}
break;
case FUNC_EVERY_50_MSECOND:
if (pin[GPIO_IRRECV] < 99) {
if (Pin(GPIO_IRRECV) < 99) {
IrReceiveCheck(); // check if there's anything on IR side
}
irsend_active = false; // re-enable IR reception
break;
case FUNC_COMMAND:
if (pin[GPIO_IRSEND] < 99) {
if (Pin(GPIO_IRSEND) < 99) {
result = DecodeCommand(kIrRemoteCommands, IrRemoteCommand);
}
break;

View File

@ -576,7 +576,7 @@ void HandleDomoticzConfiguration(void)
i +1, i, Settings.domoticz_relay_idx[i],
i +1, i, Settings.domoticz_key_idx[i]);
}
if (pin[GPIO_SWT1 +i] < 99) {
if (Pin(GPIO_SWT1, i) < 99) {
WSContentSend_P(HTTP_FORM_DOMOTICZ_SWITCH,
i +1, i, Settings.domoticz_switch_idx[i]);
}

View File

@ -87,8 +87,8 @@ void SerialBridgeInput(void)
void SerialBridgeInit(void)
{
serial_bridge_active = false;
if ((pin[GPIO_SBR_RX] < 99) && (pin[GPIO_SBR_TX] < 99)) {
SerialBridgeSerial = new TasmotaSerial(pin[GPIO_SBR_RX], pin[GPIO_SBR_TX]);
if ((Pin(GPIO_SBR_RX) < 99) && (Pin(GPIO_SBR_TX) < 99)) {
SerialBridgeSerial = new TasmotaSerial(Pin(GPIO_SBR_RX), Pin(GPIO_SBR_TX));
if (SerialBridgeSerial->begin(Settings.sbaudrate * 300)) { // Baud rate is stored div 300 so it fits into 16 bits
if (SerialBridgeSerial->hardwareSerial()) {
ClaimSerial();

View File

@ -580,9 +580,9 @@ void RulesEvery50ms(void)
// Boot time SWITCHES Status
for (uint32_t i = 0; i < MAX_SWITCHES; i++) {
#ifdef USE_TM1638
if ((pin[GPIO_SWT1 +i] < 99) || ((pin[GPIO_TM16CLK] < 99) && (pin[GPIO_TM16DIO] < 99) && (pin[GPIO_TM16STB] < 99))) {
if ((Pin(GPIO_SWT1, i) < 99) || ((Pin(GPIO_TM16CLK) < 99) && (Pin(GPIO_TM16DIO) < 99) && (Pin(GPIO_TM16STB) < 99))) {
#else
if (pin[GPIO_SWT1 +i] < 99) {
if (Pin(GPIO_SWT1, i) < 99) {
#endif // USE_TM1638
snprintf_P(json_event, sizeof(json_event), PSTR("{\"" D_JSON_SWITCH "%d\":{\"Boot\":%d}}"), i +1, (SwitchState(i)));
RulesProcessEvent(json_event);

View File

@ -370,7 +370,7 @@ void HAssAnnounceSwitches(void)
uint8_t hold = 0;
uint8_t pir = 0;
if (pin[GPIO_SWT1 + switch_index] < 99) { switch_present = 1; }
if (Pin(GPIO_SWT1, switch_index) < 99) { switch_present = 1; }
if (KeyTopicActive(1) && strcmp(SettingsText(SET_MQTT_SWITCH_TOPIC), mqtt_topic)) // Enable Discovery for Switches only if Switchtopic is set to a custom name
{
@ -451,7 +451,7 @@ void HAssAnnounceButtons(void)
} else
#endif
{
if (pin[GPIO_KEY1 + button_index] < 99) {
if (Pin(GPIO_KEY1, button_index) < 99) {
button_present = 1;
}
}

View File

@ -136,7 +136,7 @@ uint16_t MP3_Checksum(uint8_t *array)
\*********************************************************************************************/
void MP3PlayerInit(void) {
MP3Player = new TasmotaSerial(-1, pin[GPIO_MP3_DFR562]);
MP3Player = new TasmotaSerial(-1, Pin(GPIO_MP3_DFR562));
// start serial communication fixed to 9600 baud
if (MP3Player->begin(9600)) {
MP3Player->flush();
@ -232,7 +232,7 @@ bool Xdrv14(uint8_t function)
{
bool result = false;
if (pin[GPIO_MP3_DFR562] < 99) {
if (Pin(GPIO_MP3_DFR562) < 99) {
switch (function) {
case FUNC_PRE_INIT:
MP3PlayerInit(); // init and start communication

View File

@ -596,9 +596,9 @@ void TuyaNormalPowerModePacketProcess(void)
bool TuyaModuleSelected(void)
{
if (!(pin[GPIO_TUYA_RX] < 99) || !(pin[GPIO_TUYA_TX] < 99)) { // fallback to hardware-serial if not explicitly selected
pin[GPIO_TUYA_TX] = 1;
pin[GPIO_TUYA_RX] = 3;
if (!(Pin(GPIO_TUYA_RX) < 99) || !(Pin(GPIO_TUYA_TX) < 99)) { // fallback to hardware-serial if not explicitly selected
SetPin(1, GPIO_TUYA_TX);
SetPin(3, GPIO_TUYA_RX);
Settings.my_gp.io[1] = GPIO_TUYA_TX;
Settings.my_gp.io[3] = GPIO_TUYA_RX;
restart_flag = 2;
@ -643,7 +643,7 @@ void TuyaInit(void)
{
Tuya.buffer = (char*)(malloc(TUYA_BUFFER_SIZE));
if (Tuya.buffer != nullptr) {
TuyaSerial = new TasmotaSerial(pin[GPIO_TUYA_RX], pin[GPIO_TUYA_TX], 2);
TuyaSerial = new TasmotaSerial(Pin(GPIO_TUYA_RX), Pin(GPIO_TUYA_TX), 2);
if (TuyaSerial->begin(9600)) {
if (TuyaSerial->hardwareSerial()) { ClaimSerial(); }
// Get MCU Configuration

View File

@ -81,12 +81,12 @@ void RfReceiveCheck(void)
void RfInit(void)
{
if (pin[GPIO_RFSEND] < 99) {
mySwitch.enableTransmit(pin[GPIO_RFSEND]);
if (Pin(GPIO_RFSEND) < 99) {
mySwitch.enableTransmit(Pin(GPIO_RFSEND));
}
if (pin[GPIO_RFRECV] < 99) {
pinMode( pin[GPIO_RFRECV], INPUT);
mySwitch.enableReceive(pin[GPIO_RFRECV]);
if (Pin(GPIO_RFRECV) < 99) {
pinMode( Pin(GPIO_RFRECV), INPUT);
mySwitch.enableReceive(Pin(GPIO_RFRECV));
}
}
@ -170,15 +170,15 @@ bool Xdrv17(uint8_t function)
{
bool result = false;
if ((pin[GPIO_RFSEND] < 99) || (pin[GPIO_RFRECV] < 99)) {
if ((Pin(GPIO_RFSEND) < 99) || (Pin(GPIO_RFRECV) < 99)) {
switch (function) {
case FUNC_EVERY_50_MSECOND:
if (pin[GPIO_RFRECV] < 99) {
if (Pin(GPIO_RFRECV) < 99) {
RfReceiveCheck();
}
break;
case FUNC_COMMAND:
if (pin[GPIO_RFSEND] < 99) {
if (Pin(GPIO_RFSEND) < 99) {
result = DecodeCommand(kRfSendCommands, RfSendCommand);
}
break;

View File

@ -97,7 +97,7 @@ void ArmtronixInit(void)
Armtronix.dim_state[1] = -1;
Armtronix.knob_state[0] = -1;
Armtronix.knob_state[1] = -1;
ArmtronixSerial = new TasmotaSerial(pin[GPIO_RXD], pin[GPIO_TXD], 2);
ArmtronixSerial = new TasmotaSerial(Pin(GPIO_RXD), Pin(GPIO_TXD), 2);
if (ArmtronixSerial->begin(115200)) {
if (ArmtronixSerial->hardwareSerial()) { ClaimSerial(); }
ArmtronixSerial->println("Status");

View File

@ -187,7 +187,7 @@ void PS16DZInit(void)
{
Ps16dz.rx_buffer = (char*)(malloc(PS16DZ_BUFFER_SIZE));
if (Ps16dz.rx_buffer != nullptr) {
PS16DZSerial = new TasmotaSerial(pin[GPIO_RXD], pin[GPIO_TXD], 2);
PS16DZSerial = new TasmotaSerial(Pin(GPIO_RXD), Pin(GPIO_TXD), 2);
if (PS16DZSerial->begin(19200)) {
if (PS16DZSerial->hardwareSerial()) { ClaimSerial(); }
}

View File

@ -162,10 +162,10 @@ void ZigbeeInit(void)
// AddLog_P2(LOG_LEVEL_INFO, PSTR("ZigbeeInit Mem1 = %d"), ESP_getFreeHeap());
zigbee.active = false;
if ((pin[GPIO_ZIGBEE_RX] < 99) && (pin[GPIO_ZIGBEE_TX] < 99)) {
AddLog_P2(LOG_LEVEL_DEBUG_MORE, PSTR(D_LOG_ZIGBEE "GPIOs Rx:%d Tx:%d"), pin[GPIO_ZIGBEE_RX], pin[GPIO_ZIGBEE_TX]);
if ((Pin(GPIO_ZIGBEE_RX) < 99) && (Pin(GPIO_ZIGBEE_TX) < 99)) {
AddLog_P2(LOG_LEVEL_DEBUG_MORE, PSTR(D_LOG_ZIGBEE "GPIOs Rx:%d Tx:%d"), Pin(GPIO_ZIGBEE_RX), Pin(GPIO_ZIGBEE_TX));
// if seriallog_level is 0, we allow GPIO 13/15 to switch to Hardware Serial
ZigbeeSerial = new TasmotaSerial(pin[GPIO_ZIGBEE_RX], pin[GPIO_ZIGBEE_TX], seriallog_level ? 1 : 2, 0, 256); // set a receive buffer of 256 bytes
ZigbeeSerial = new TasmotaSerial(Pin(GPIO_ZIGBEE_RX), Pin(GPIO_ZIGBEE_TX), seriallog_level ? 1 : 2, 0, 256); // set a receive buffer of 256 bytes
ZigbeeSerial->begin(115200);
if (ZigbeeSerial->hardwareSerial()) {
ClaimSerial();

View File

@ -111,8 +111,8 @@ bool BuzzerPinState(void)
void BuzzerInit(void)
{
if (pin[GPIO_BUZZER] < 99) {
pinMode(pin[GPIO_BUZZER], OUTPUT);
if (Pin(GPIO_BUZZER) < 99) {
pinMode(Pin(GPIO_BUZZER), OUTPUT);
BuzzerOff();
} else {
Buzzer.active = false;

View File

@ -27,12 +27,12 @@
#include <A4988_Stepper.h>
short A4988_dir_pin = pin[GPIO_MAX];
short A4988_stp_pin = pin[GPIO_MAX];
short A4988_ms1_pin = pin[GPIO_MAX];
short A4988_ms2_pin = pin[GPIO_MAX];
short A4988_ms3_pin = pin[GPIO_MAX];
short A4988_ena_pin = pin[GPIO_MAX];
short A4988_dir_pin = 0;
short A4988_stp_pin = 0;
short A4988_ms1_pin = 0;
short A4988_ms2_pin = 0;
short A4988_ms3_pin = 0;
short A4988_ena_pin = 0;
int A4988_spr = 0;
float A4988_rpm = 0;
short A4988_mis = 0;
@ -41,12 +41,12 @@ A4988_Stepper* myA4988 = nullptr;
void A4988Init(void)
{
A4988_dir_pin = pin[GPIO_A4988_DIR];
A4988_stp_pin = pin[GPIO_A4988_STP];
A4988_ena_pin = pin[GPIO_A4988_ENA];
A4988_ms1_pin = pin[GPIO_A4988_MS1];
A4988_ms2_pin = pin[GPIO_A4988_MS2];
A4988_ms3_pin = pin[GPIO_A4988_MS3];
A4988_dir_pin = Pin(GPIO_A4988_DIR);
A4988_stp_pin = Pin(GPIO_A4988_STP);
A4988_ena_pin = Pin(GPIO_A4988_ENA);
A4988_ms1_pin = Pin(GPIO_A4988_MS1);
A4988_ms2_pin = Pin(GPIO_A4988_MS2);
A4988_ms3_pin = Pin(GPIO_A4988_MS3);
A4988_spr = 200;
A4988_rpm = 30;
A4988_mis = 1;
@ -93,7 +93,7 @@ void CmndDoTurn(void) {
}
void CmndSetMIS(void) {
if ((pin[GPIO_A4988_MS1] < 99) && (pin[GPIO_A4988_MS2] < 99) && (pin[GPIO_A4988_MS3] < 99) && (XdrvMailbox.data_len > 0)) {
if ((Pin(GPIO_A4988_MS1) < 99) && (Pin(GPIO_A4988_MS2) < 99) && (Pin(GPIO_A4988_MS3) < 99) && (XdrvMailbox.data_len > 0)) {
short newMIS = strtoul(XdrvMailbox.data,nullptr,10);
myA4988->setMIS(newMIS);
ResponseCmndDone();
@ -122,7 +122,7 @@ void CmndSetRPM(void) {
bool Xdrv25(uint8_t function)
{
bool result = false;
if ((pin[GPIO_A4988_DIR] < 99) && (pin[GPIO_A4988_STP] < 99)) {
if ((Pin(GPIO_A4988_DIR) < 99) && (Pin(GPIO_A4988_STP) < 99)) {
switch (function) {
case FUNC_INIT:
A4988Init();

View File

@ -147,7 +147,7 @@ void AriluxRfHandler(void)
void AriluxRfInit(void)
{
if ((pin[GPIO_ARIRFRCV] < 99) && (pin[GPIO_ARIRFSEL] < 99)) {
if ((Pin(GPIO_ARIRFRCV) < 99) && (Pin(GPIO_ARIRFSEL) < 99)) {
if (Settings.last_module != Settings.module) {
Settings.rf_code[1][6] = 0;
Settings.rf_code[1][7] = 0;
@ -155,16 +155,16 @@ void AriluxRfInit(void)
}
Arilux.rf_received_value = 0;
digitalWrite(pin[GPIO_ARIRFSEL], 0); // Turn on RF
attachInterrupt(pin[GPIO_ARIRFRCV], AriluxRfInterrupt, CHANGE);
digitalWrite(Pin(GPIO_ARIRFSEL), 0); // Turn on RF
attachInterrupt(Pin(GPIO_ARIRFRCV), AriluxRfInterrupt, CHANGE);
}
}
void AriluxRfDisable(void)
{
if ((pin[GPIO_ARIRFRCV] < 99) && (pin[GPIO_ARIRFSEL] < 99)) {
detachInterrupt(pin[GPIO_ARIRFRCV]);
digitalWrite(pin[GPIO_ARIRFSEL], 1); // Turn off RF
if ((Pin(GPIO_ARIRFRCV) < 99) && (Pin(GPIO_ARIRFSEL) < 99)) {
detachInterrupt(Pin(GPIO_ARIRFRCV));
digitalWrite(Pin(GPIO_ARIRFSEL), 1); // Turn off RF
}
}
@ -178,7 +178,7 @@ bool Xdrv26(uint8_t function)
switch (function) {
case FUNC_EVERY_50_MSECOND:
if (pin[GPIO_ARIRFRCV] < 99) { AriluxRfHandler(); }
if (Pin(GPIO_ARIRFRCV) < 99) { AriluxRfHandler(); }
break;
case FUNC_EVERY_SECOND:
if (10 == uptime) { AriluxRfInit(); } // Needs rest before enabling RF interrupts

View File

@ -97,7 +97,7 @@ void ShutterRtc50mS(void)
Shutter.pwm_frequency[i] += Shutter.accelerator[i];
Shutter.pwm_frequency[i] = tmax(0,tmin(Shutter.direction[i]==1 ? Shutter.max_pwm_frequency : Shutter.max_close_pwm_frequency[i],Shutter.pwm_frequency[i]));
analogWriteFreq(Shutter.pwm_frequency[i]);
analogWrite(pin[GPIO_PWM1+i], 50);
analogWrite(Pin(GPIO_PWM1, i), 50);
}
}
}
@ -201,12 +201,12 @@ void ShutterInit(void)
}
} else {
Shutter.mode = SHT_OFF_ON__OPEN_CLOSE;
if ((pin[GPIO_PWM1+i] < 99) && (pin[GPIO_CNTR1+i] < 99)) {
if ((Pin(GPIO_PWM1, i) < 99) && (Pin(GPIO_CNTR1, i) < 99)) {
Shutter.mode = SHT_OFF_ON__OPEN_CLOSE_STEPPER;
Shutter.pwm_frequency[i] = 0;
Shutter.accelerator[i] = 0;
analogWriteFreq(Shutter.pwm_frequency[i]);
analogWrite(pin[GPIO_PWM1+i], 50);
analogWrite(Pin(GPIO_PWM1, i), 50);
}
}
@ -352,13 +352,13 @@ void ShutterUpdatePosition(void)
Shutter.accelerator[i] = 0;
Shutter.pwm_frequency[i] = Shutter.pwm_frequency[i] > 250 ? 250 : Shutter.pwm_frequency[i];
analogWriteFreq(Shutter.pwm_frequency[i]);
analogWrite(pin[GPIO_PWM1+i], 50);
analogWrite(Pin(GPIO_PWM1, i), 50);
Shutter.pwm_frequency[i] = 0;
analogWriteFreq(Shutter.pwm_frequency[i]);
while (RtcSettings.pulse_counter[i] < (uint32_t)(Shutter.target_position[i]-Shutter.start_position[i])*Shutter.direction[i]*Shutter.max_pwm_frequency/2000) {
delay(1);
}
analogWrite(pin[GPIO_PWM1+i], 0);
analogWrite(Pin(GPIO_PWM1, i), 0);
Shutter.real_position[i] = ShutterCounterBasedPosition(i);
AddLog_P2(LOG_LEVEL_DEBUG, PSTR("SHT: Real %d, pulsecount %d, start %d"), Shutter.real_position[i],RtcSettings.pulse_counter[i], Shutter.start_position[i]);
@ -421,7 +421,7 @@ void ShutterStartInit(uint32_t i, int32_t direction, int32_t target_pos)
if (Shutter.mode == SHT_OFF_ON__OPEN_CLOSE_STEPPER) {
Shutter.pwm_frequency[i] = 0;
analogWriteFreq(Shutter.pwm_frequency[i]);
analogWrite(pin[GPIO_PWM1+i], 0);
analogWrite(Pin(GPIO_PWM1, i), 0);
RtcSettings.pulse_counter[i] = 0;
Shutter.accelerator[i] = Shutter.max_pwm_frequency / (Shutter.motordelay[i]>0 ? Shutter.motordelay[i] : 1);
AddLog_P2(LOG_LEVEL_DEBUG, PSTR("SHT: Ramp up: %d"), Shutter.accelerator[i]);
@ -450,10 +450,10 @@ void ShutterWaitForMotorStop(uint32_t i)
Shutter.pwm_frequency[i] = tmax(Shutter.pwm_frequency[i]-((Shutter.direction[i] == 1 ? Shutter.max_pwm_frequency : Shutter.max_close_pwm_frequency[i])/(Shutter.motordelay[i]+1)) , 0);
//AddLog_P2(LOG_LEVEL_DEBUG_MORE, PSTR("SHT: Frequency: %ld"), Shutter.pwm_frequency[i]);
analogWriteFreq(Shutter.pwm_frequency[i]);
analogWrite(pin[GPIO_PWM1+i], 50);
analogWrite(Pin(GPIO_PWM1, i), 50);
delay(50);
}
analogWrite(pin[GPIO_PWM1+i], 0);
analogWrite(Pin(GPIO_PWM1, i), 0);
Shutter.real_position[i] = ShutterCounterBasedPosition(i);
} else {
ExecuteCommandPower(Settings.shutter_startrelay[i], 0, SRC_SHUTTER);

View File

@ -54,9 +54,9 @@ bool DeepSleepEnabled(void)
return false; // Disabled
}
if (pin[GPIO_DEEPSLEEP] < 99) {
pinMode(pin[GPIO_DEEPSLEEP], INPUT_PULLUP);
return (digitalRead(pin[GPIO_DEEPSLEEP])); // Disable DeepSleep if user holds pin GPIO_DEEPSLEEP low
if (Pin(GPIO_DEEPSLEEP) < 99) {
pinMode(Pin(GPIO_DEEPSLEEP), INPUT_PULLUP);
return (digitalRead(Pin(GPIO_DEEPSLEEP))); // Disable DeepSleep if user holds pin GPIO_DEEPSLEEP low
}
return true; // Enabled

View File

@ -395,11 +395,11 @@ void EsxMcuStart(void)
int retries = 3;
#ifdef EXS_DEBUG
AddLog_P2(LOG_LEVEL_DEBUG, PSTR("EXS: Request MCU configuration, PIN %d to Low"), pin[GPIO_EXS_ENABLE]);
AddLog_P2(LOG_LEVEL_DEBUG, PSTR("EXS: Request MCU configuration, PIN %d to Low"), Pin(GPIO_EXS_ENABLE));
#endif
pinMode(pin[GPIO_EXS_ENABLE], OUTPUT);
digitalWrite(pin[GPIO_EXS_ENABLE], LOW);
pinMode(Pin(GPIO_EXS_ENABLE), OUTPUT);
digitalWrite(Pin(GPIO_EXS_ENABLE), LOW);
delay(1); // wait 1ms fot the MCU to come online
@ -413,13 +413,13 @@ void EsxMcuStart(void)
void ExsInit(void)
{
#ifdef EXS_DEBUG
AddLog_P2(LOG_LEVEL_INFO, PSTR("EXS: Starting Tx %d Rx %d"), pin[GPIO_TXD], pin[GPIO_RXD]);
AddLog_P2(LOG_LEVEL_INFO, PSTR("EXS: Starting Tx %d Rx %d"), Pin(GPIO_TXD), Pin(GPIO_RXD));
#endif
Exs.buffer = (uint8_t *)malloc(EXS_BUFFER_SIZE);
if (Exs.buffer != nullptr)
{
ExsSerial = new TasmotaSerial(pin[GPIO_RXD], pin[GPIO_TXD], 2);
ExsSerial = new TasmotaSerial(Pin(GPIO_RXD), Pin(GPIO_TXD), 2);
if (ExsSerial->begin(9600))
{
if (ExsSerial->hardwareSerial())

View File

@ -219,11 +219,11 @@ uint8_t TasmotaSlave_UpdateInit(void)
void TasmotaSlave_Reset(void)
{
if (TSlave.SerialEnabled) {
digitalWrite(pin[GPIO_TASMOTASLAVE_RST], !TSlave.inverted);
digitalWrite(Pin(GPIO_TASMOTASLAVE_RST), !TSlave.inverted);
delay(1);
digitalWrite(pin[GPIO_TASMOTASLAVE_RST], TSlave.inverted);
digitalWrite(Pin(GPIO_TASMOTASLAVE_RST), TSlave.inverted);
delay(1);
digitalWrite(pin[GPIO_TASMOTASLAVE_RST], !TSlave.inverted);
digitalWrite(Pin(GPIO_TASMOTASLAVE_RST), !TSlave.inverted);
delay(5);
}
}
@ -437,20 +437,20 @@ void TasmotaSlave_Init(void)
return;
}
if (!TSlave.SerialEnabled) {
if ((pin[GPIO_TASMOTASLAVE_RXD] < 99) && (pin[GPIO_TASMOTASLAVE_TXD] < 99) &&
((pin[GPIO_TASMOTASLAVE_RST] < 99) || (pin[GPIO_TASMOTASLAVE_RST_INV] < 99))) {
TasmotaSlave_Serial = new TasmotaSerial(pin[GPIO_TASMOTASLAVE_RXD], pin[GPIO_TASMOTASLAVE_TXD], 1, 0, 200);
if ((Pin(GPIO_TASMOTASLAVE_RXD) < 99) && (Pin(GPIO_TASMOTASLAVE_TXD) < 99) &&
((Pin(GPIO_TASMOTASLAVE_RST) < 99) || (Pin(GPIO_TASMOTASLAVE_RST_INV) < 99))) {
TasmotaSlave_Serial = new TasmotaSerial(Pin(GPIO_TASMOTASLAVE_RXD), Pin(GPIO_TASMOTASLAVE_TXD), 1, 0, 200);
if (TasmotaSlave_Serial->begin(USE_TASMOTA_SLAVE_SERIAL_SPEED)) {
if (TasmotaSlave_Serial->hardwareSerial()) {
ClaimSerial();
}
TasmotaSlave_Serial->setTimeout(50);
if (pin[GPIO_TASMOTASLAVE_RST_INV] < 99) {
pin[GPIO_TASMOTASLAVE_RST] = pin[GPIO_TASMOTASLAVE_RST_INV];
pin[GPIO_TASMOTASLAVE_RST_INV] = 99;
if (Pin(GPIO_TASMOTASLAVE_RST_INV) < 99) {
SetPin(Pin(GPIO_TASMOTASLAVE_RST_INV), GPIO_TASMOTASLAVE_RST);
SetPin(99, GPIO_TASMOTASLAVE_RST_INV);
TSlave.inverted = HIGH;
}
pinMode(pin[GPIO_TASMOTASLAVE_RST], OUTPUT);
pinMode(Pin(GPIO_TASMOTASLAVE_RST), OUTPUT);
TSlave.SerialEnabled = true;
TasmotaSlave_Reset();
AddLog_P2(LOG_LEVEL_INFO, PSTR("Tasmota Slave Enabled"));

View File

@ -60,7 +60,7 @@ RF24 NRF24radio;
bool NRF24initRadio()
{
NRF24radio.begin(pin[GPIO_SPI_CS],pin[GPIO_SPI_DC]);
NRF24radio.begin(Pin(GPIO_SPI_CS),Pin(GPIO_SPI_DC));
NRF24radio.powerUp();
if(NRF24radio.isChipConnected()){
@ -73,7 +73,7 @@ bool NRF24initRadio()
bool NRF24Detect(void)
{
if ((pin[GPIO_SPI_CS]<99) && (pin[GPIO_SPI_DC]<99)){
if ((Pin(GPIO_SPI_CS)<99) && (Pin(GPIO_SPI_DC)<99)){
SPI.pins(SCK,MOSI,MISO,-1);
if(NRF24initRadio()){
NRF24.chipType = 32; // SPACE

View File

@ -94,7 +94,7 @@ void PWMModulePreInit(void)
PWMDimmerSetPoweredOffLed();
// The relay initializes to on. If the power is supposed to be off, turn the relay off.
if (!power && pin[GPIO_REL1] < 99) digitalWrite(pin[GPIO_REL1], bitRead(rel_inverted, 0) ? 1 : 0);
if (!power && Pin(GPIO_REL1) < 99) digitalWrite(Pin(GPIO_REL1), bitRead(rel_inverted, 0) ? 1 : 0);
#ifdef USE_PWM_DIMMER_REMOTE
// If remote device mode is enabled, set the device group count to the number of buttons
@ -104,7 +104,7 @@ void PWMModulePreInit(void)
device_group_count = 0;
for (uint32_t button_index = 0; button_index < MAX_KEYS; button_index++) {
if (pin[GPIO_KEY1 + button_index] < 99) device_group_count++;
if (Pin(GPIO_KEY1, button_index) < 99) device_group_count++;
}
remote_pwm_dimmer_count = device_group_count - 1;
@ -156,10 +156,10 @@ void PWMDimmerSetBrightnessLeds(int32_t operation)
void PWMDimmerSetPoweredOffLed(void)
{
// Set the powered-off LED state.
if (pin[GPIO_LEDLNK] < 99) {
if (Pin(GPIO_LEDLNK) < 99) {
bool power_off_led_on = !power && Settings.flag4.powered_off_led;
if (ledlnk_inverted) power_off_led_on ^= 1;
digitalWrite(pin[GPIO_LEDLNK], power_off_led_on);
digitalWrite(Pin(GPIO_LEDLNK), power_off_led_on);
}
}
@ -250,13 +250,13 @@ void PWMDimmerHandleButton(void)
* Released Hold down On No Dimmer
* Released Press & release up Off No Power on at bri preset low
* Released Press & release down Off No Power on at bri preset high
*
*
* Holding any button for over 10 seconds executes the WiFiConfig 2 command.
*
*
* In remote mode, whichever button is pressed first becomes the power button and any buttons
* pressed while it is held affect the device associated with it. The up and down buttons change
* depeneding on which button is the current power button:
*
*
* Power Down Up
* ----- ---- --
* 1 2 3
@ -283,7 +283,7 @@ void PWMDimmerHandleButton(void)
uint8_t dgr_more_to_come = false;
uint32_t button_index = XdrvMailbox.index;
uint32_t now = millis();
// Initialize some variables.
#ifdef USE_PWM_DIMMER_REMOTE
bool power_is_on = (!active_device_is_local ? active_remote_pwm_dimmer->power_on : power);
@ -482,7 +482,7 @@ void PWMDimmerHandleButton(void)
// If the up or down button was tapped while the power button was held, ...
else if (tap_count) {
// If the button was tapped but not held, handle the operation based on which button was
// tapped.
if (!button_was_held) {
@ -546,7 +546,7 @@ void PWMDimmerHandleButton(void)
// If the power is on, ...
if (power_is_on) {
// If the button was not held, adjust the brightness. Set the direction based on which
// button is pressed. The new brightness will be calculated below.
if (button_hold_time[button_index] >= now) {

View File

@ -242,8 +242,8 @@ void CreateKeeloqPacket()
void KeeloqInit()
{
jaroliftDevice.port_tx = pin[GPIO_CC1101_GDO2]; // Output port for transmission
jaroliftDevice.port_rx = pin[GPIO_CC1101_GDO0]; // Input port for reception
jaroliftDevice.port_tx = Pin(GPIO_CC1101_GDO2); // Output port for transmission
jaroliftDevice.port_rx = Pin(GPIO_CC1101_GDO0); // Input port for reception
DEBUG_DRIVER_LOG(LOG_LEVEL_DEBUG_MORE, PSTR("cc1101.init()"));
delay(100);
@ -266,7 +266,7 @@ void KeeloqInit()
\*********************************************************************************************/
bool Xdrv36(uint8_t function)
{
if ((99 == pin[GPIO_CC1101_GDO0]) || (99 == pin[GPIO_CC1101_GDO2])) { return false; }
if ((99 == Pin(GPIO_CC1101_GDO0)) || (99 == Pin(GPIO_CC1101_GDO2))) { return false; }
bool result = false;
@ -284,4 +284,4 @@ bool Xdrv36(uint8_t function)
return result;
}
#endif // USE_KEELOQ
#endif // USE_KEELOQ