Fake gpio inputs for native

This commit is contained in:
fvanroie 2021-05-23 22:57:05 +02:00
parent e85804b2cc
commit 6b613eaf38
3 changed files with 18 additions and 4 deletions

View File

@ -170,6 +170,7 @@ void loop()
if(mainLoopCounter == 0 || mainLoopCounter == 5) {
haspDevice.loop_5s();
gpioEvery5Seconds();
}
/* Reset loop counter every 10 seconds */

View File

@ -325,6 +325,7 @@ void gpioSetup(void)
gpioSavePinConfig(1, 4, hasp_gpio_type_t::LIGHT_RELAY, 0, -1, false);
gpioSavePinConfig(2, 13, hasp_gpio_type_t::LED, 0, -1, false);
gpioSavePinConfig(3, 14, hasp_gpio_type_t::DAC, 0, -1, false);
gpioSavePinConfig(4, 5, hasp_gpio_type_t::MOTION, 0, -1, false);
}
IRAM_ATTR void gpioLoop(void)
{}
@ -341,6 +342,16 @@ static inline bool gpio_is_output(hasp_gpio_config_t* gpio)
return (gpio->type > hasp_gpio_type_t::USED) && (gpio->type < 0x80);
}
void gpioEvery5Seconds(void)
{
for(uint8_t i = 0; i < HASP_NUM_GPIO_CONFIG; i++) {
if(gpio_is_input(&gpioConfig[i])) {
gpioConfig[i].val = !gpioConfig[i].val;
event_gpio_input(gpioConfig[i].pin, gpioConfig[i].val);
}
}
}
/* ********************************* State Setters *************************************** */
bool gpio_get_pin_state(uint8_t pin, bool& power, int32_t& val)

View File

@ -11,10 +11,6 @@
using namespace ace_button;
#endif
#ifdef __cplusplus
extern "C" {
#endif
struct hasp_gpio_config_t
{
uint8_t pin : 8; // pin number
@ -31,6 +27,12 @@ struct hasp_gpio_config_t
#endif
};
extern hasp_gpio_config_t gpioConfig[HASP_NUM_GPIO_CONFIG];
#ifdef __cplusplus
extern "C" {
#endif
void gpioSetup(void);
IRAM_ATTR void gpioLoop(void);
void gpioEvery5Seconds(void);