Skip to content

Commit

Permalink
Add command GpioRead (#19814)
Browse files Browse the repository at this point in the history
* Add command ``GpioRead``

* change output
  • Loading branch information
s-hadinger authored Oct 21, 2023
1 parent 6efe2ab commit 356de1a
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 2 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ All notable changes to this project will be documented in this file.
- I2C bus2 support to HYTxxx temperature and humidity sensor
- I2C bus2 support to SI1145/6/7 Ultra violet index and light sensor
- I2C bus2 support to LM75AD temperature sensor
- Add command ``GpioRead``

### Breaking Changed

Expand Down
1 change: 1 addition & 0 deletions tasmota/include/i18n.h
Original file line number Diff line number Diff line change
Expand Up @@ -302,6 +302,7 @@
#define D_CMND_GPIO "GPIO"
#define D_JSON_NOT_SUPPORTED "Not supported"
#define D_CMND_GPIOS "GPIOs"
#define D_CMND_GPIOREAD "GPIORead"
#define D_CMND_PWM "PWM"
#define D_CMND_PWMFREQUENCY "PWMFrequency"
#define D_CMND_PWMRANGE "PWMRange"
Expand Down
25 changes: 23 additions & 2 deletions tasmota/tasmota_support/support_command.ino
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ const char kTasmotaCommands[] PROGMEM = "|" // No prefix
D_CMND_POWERONSTATE "|" D_CMND_PULSETIME "|" D_CMND_BLINKTIME "|" D_CMND_BLINKCOUNT "|" D_CMND_SAVEDATA "|"
D_CMND_SO "|" D_CMND_SETOPTION "|" D_CMND_TEMPERATURE_RESOLUTION "|" D_CMND_HUMIDITY_RESOLUTION "|" D_CMND_PRESSURE_RESOLUTION "|" D_CMND_POWER_RESOLUTION "|"
D_CMND_VOLTAGE_RESOLUTION "|" D_CMND_FREQUENCY_RESOLUTION "|" D_CMND_CURRENT_RESOLUTION "|" D_CMND_ENERGY_RESOLUTION "|" D_CMND_WEIGHT_RESOLUTION "|"
D_CMND_MODULE "|" D_CMND_MODULES "|" D_CMND_GPIO "|" D_CMND_GPIOS "|" D_CMND_TEMPLATE "|" D_CMND_PWM "|" D_CMND_PWMFREQUENCY "|" D_CMND_PWMRANGE "|"
D_CMND_MODULE "|" D_CMND_MODULES "|" D_CMND_GPIO "|" D_CMND_GPIOREAD "|" D_CMND_GPIOS "|" D_CMND_TEMPLATE "|" D_CMND_PWM "|" D_CMND_PWMFREQUENCY "|" D_CMND_PWMRANGE "|"
D_CMND_BUTTONDEBOUNCE "|" D_CMND_SWITCHDEBOUNCE "|" D_CMND_SYSLOG "|" D_CMND_LOGHOST "|" D_CMND_LOGPORT "|"
D_CMND_SERIALBUFFER "|" D_CMND_SERIALSEND "|" D_CMND_BAUDRATE "|" D_CMND_SERIALCONFIG "|" 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_WIFI "|" D_CMND_DNSTIMEOUT "|"
Expand Down Expand Up @@ -67,7 +67,7 @@ void (* const TasmotaCommand[])(void) PROGMEM = {
&CmndPowerOnState, &CmndPulsetime, &CmndBlinktime, &CmndBlinkcount, &CmndSavedata,
&CmndSetoption, &CmndSetoption, &CmndTemperatureResolution, &CmndHumidityResolution, &CmndPressureResolution, &CmndPowerResolution,
&CmndVoltageResolution, &CmndFrequencyResolution, &CmndCurrentResolution, &CmndEnergyResolution, &CmndWeightResolution,
&CmndModule, &CmndModules, &CmndGpio, &CmndGpios, &CmndTemplate, &CmndPwm, &CmndPwmfrequency, &CmndPwmrange,
&CmndModule, &CmndModules, &CmndGpio, &CmndGpioRead, &CmndGpios, &CmndTemplate, &CmndPwm, &CmndPwmfrequency, &CmndPwmrange,
&CmndButtonDebounce, &CmndSwitchDebounce, &CmndSyslog, &CmndLoghost, &CmndLogport,
&CmndSerialBuffer, &CmndSerialSend, &CmndBaudrate, &CmndSerialConfig, &CmndSerialDelimiter,
&CmndIpAddress, &CmndNtpServer, &CmndAp, &CmndSsid, &CmndPassword, &CmndHostname, &CmndWifiConfig, &CmndWifi, &CmndDnsTimeout,
Expand Down Expand Up @@ -1768,6 +1768,27 @@ void CmndGpio(void)
}
}

// Perform a digitalRead on each configured PGIO
void CmndGpioRead(void)
{
myio template_gp;
TemplateGpios(&template_gp);
bool jsflg = false;
Response_P(PSTR("{\"" D_CMND_GPIOREAD "\":{"));
for (uint32_t i = 0; i < nitems(Settings->my_gp.io); i++) {
uint32_t sensor_type = template_gp.io[i];
if ((sensor_type != GPIO_NONE) && (AGPIO(GPIO_USER) != sensor_type)) {
if (jsflg) {
ResponseAppend_P(PSTR(","));
}
jsflg = true;
bool state = digitalRead(i);
ResponseAppend_P(PSTR("\"" D_CMND_GPIO "%d\":%d"), i, state);
}
}
ResponseAppend_P(PSTR("}}"));
}

void ShowGpios(const uint16_t *NiceList, uint32_t size, uint32_t offset, uint32_t &lines) {
uint32_t ridx;
uint32_t midx;
Expand Down

0 comments on commit 356de1a

Please sign in to comment.