add: invert gpios

This commit is contained in:
Tobias Reisinger 2020-04-18 02:09:50 +02:00
parent 27df642ee6
commit 82f43080ac
5 changed files with 27 additions and 2 deletions

View file

@ -6,39 +6,49 @@ relay-count = 10
[relay-0]
driver = piface
pin = 0
inverted = 0
[relay-1]
driver = piface
pin = 1
inverted = 0
[relay-2]
driver = gpio
pin = 0
inverted = 1
[relay-3]
driver = gpio
pin = 2
inverted = 1
[relay-4]
driver = gpio
pin = 3
inverted = 1
[relay-5]
driver = gpio
pin = 15
inverted = 1
[relay-6]
driver = gpio
pin = 16
inverted = 1
[relay-7]
driver = gpio
pin = 1
inverted = 1
[relay-8]
driver = gpio
pin = 4
inverted = 1
[relay-9]
driver = gpio
pin = 5
inverted = 1

View file

@ -25,6 +25,10 @@ handler_loop(controller_t *controller)
LOG_DEBUG("relay %d is active", i);
is_active = 1;
}
if(global_config.relay_configs[i].inverted)
{
is_active = !is_active;
}
switch(global_config.relay_configs[i].driver)
{
case RELAY_DRIVER_GPIO:

View file

@ -48,6 +48,11 @@ helper_load_config(IniDispatch *disp, void *config_void)
config->relay_configs[i].pin = atoi(disp->value);
return 0;
}
if(CONFINI_IS_KEY(relay_section_name, "inverted"))
{
config->relay_configs[i].inverted = atoi(disp->value);
return 0;
}
if(CONFINI_IS_KEY(relay_section_name, "driver"))
{
if(strcasecmp(disp->value, "gpio") == 0)

View file

@ -9,6 +9,7 @@
typedef struct
{
uint8_t pin;
int inverted;
relay_driver_t driver;
} config_relay_t;

View file

@ -13,13 +13,18 @@ runner_test(controller_t *controller)
{
for(uint_fast8_t i = 0; i < controller->relay_count; ++i)
{
int is_active = test_run % 2;
if(global_config.relay_configs[i].inverted)
{
is_active = !is_active;
}
switch(global_config.relay_configs[i].driver)
{
case RELAY_DRIVER_GPIO:
driver_gpio_set(global_config.relay_configs[i].pin, test_run % 2);
driver_gpio_set(global_config.relay_configs[i].pin, is_active);
break;
case RELAY_DRIVER_PIFACE:
driver_piface_set(global_config.relay_configs[i].pin, test_run % 2);
driver_piface_set(global_config.relay_configs[i].pin, is_active);
break;
default:
LOG_WARN("relay %d is not using a driver", i);