add: invert gpios
This commit is contained in:
parent
27df642ee6
commit
82f43080ac
5 changed files with 27 additions and 2 deletions
|
@ -6,39 +6,49 @@ relay-count = 10
|
||||||
[relay-0]
|
[relay-0]
|
||||||
driver = piface
|
driver = piface
|
||||||
pin = 0
|
pin = 0
|
||||||
|
inverted = 0
|
||||||
|
|
||||||
[relay-1]
|
[relay-1]
|
||||||
driver = piface
|
driver = piface
|
||||||
pin = 1
|
pin = 1
|
||||||
|
inverted = 0
|
||||||
|
|
||||||
[relay-2]
|
[relay-2]
|
||||||
driver = gpio
|
driver = gpio
|
||||||
pin = 0
|
pin = 0
|
||||||
|
inverted = 1
|
||||||
|
|
||||||
[relay-3]
|
[relay-3]
|
||||||
driver = gpio
|
driver = gpio
|
||||||
pin = 2
|
pin = 2
|
||||||
|
inverted = 1
|
||||||
|
|
||||||
[relay-4]
|
[relay-4]
|
||||||
driver = gpio
|
driver = gpio
|
||||||
pin = 3
|
pin = 3
|
||||||
|
inverted = 1
|
||||||
|
|
||||||
[relay-5]
|
[relay-5]
|
||||||
driver = gpio
|
driver = gpio
|
||||||
pin = 15
|
pin = 15
|
||||||
|
inverted = 1
|
||||||
|
|
||||||
[relay-6]
|
[relay-6]
|
||||||
driver = gpio
|
driver = gpio
|
||||||
pin = 16
|
pin = 16
|
||||||
|
inverted = 1
|
||||||
|
|
||||||
[relay-7]
|
[relay-7]
|
||||||
driver = gpio
|
driver = gpio
|
||||||
pin = 1
|
pin = 1
|
||||||
|
inverted = 1
|
||||||
|
|
||||||
[relay-8]
|
[relay-8]
|
||||||
driver = gpio
|
driver = gpio
|
||||||
pin = 4
|
pin = 4
|
||||||
|
inverted = 1
|
||||||
|
|
||||||
[relay-9]
|
[relay-9]
|
||||||
driver = gpio
|
driver = gpio
|
||||||
pin = 5
|
pin = 5
|
||||||
|
inverted = 1
|
||||||
|
|
|
@ -25,6 +25,10 @@ handler_loop(controller_t *controller)
|
||||||
LOG_DEBUG("relay %d is active", i);
|
LOG_DEBUG("relay %d is active", i);
|
||||||
is_active = 1;
|
is_active = 1;
|
||||||
}
|
}
|
||||||
|
if(global_config.relay_configs[i].inverted)
|
||||||
|
{
|
||||||
|
is_active = !is_active;
|
||||||
|
}
|
||||||
switch(global_config.relay_configs[i].driver)
|
switch(global_config.relay_configs[i].driver)
|
||||||
{
|
{
|
||||||
case RELAY_DRIVER_GPIO:
|
case RELAY_DRIVER_GPIO:
|
||||||
|
|
|
@ -48,6 +48,11 @@ helper_load_config(IniDispatch *disp, void *config_void)
|
||||||
config->relay_configs[i].pin = atoi(disp->value);
|
config->relay_configs[i].pin = atoi(disp->value);
|
||||||
return 0;
|
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(CONFINI_IS_KEY(relay_section_name, "driver"))
|
||||||
{
|
{
|
||||||
if(strcasecmp(disp->value, "gpio") == 0)
|
if(strcasecmp(disp->value, "gpio") == 0)
|
||||||
|
|
|
@ -9,6 +9,7 @@
|
||||||
typedef struct
|
typedef struct
|
||||||
{
|
{
|
||||||
uint8_t pin;
|
uint8_t pin;
|
||||||
|
int inverted;
|
||||||
relay_driver_t driver;
|
relay_driver_t driver;
|
||||||
} config_relay_t;
|
} config_relay_t;
|
||||||
|
|
||||||
|
|
|
@ -13,13 +13,18 @@ runner_test(controller_t *controller)
|
||||||
{
|
{
|
||||||
for(uint_fast8_t i = 0; i < controller->relay_count; ++i)
|
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)
|
switch(global_config.relay_configs[i].driver)
|
||||||
{
|
{
|
||||||
case RELAY_DRIVER_GPIO:
|
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;
|
break;
|
||||||
case RELAY_DRIVER_PIFACE:
|
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;
|
break;
|
||||||
default:
|
default:
|
||||||
LOG_WARN("relay %d is not using a driver", i);
|
LOG_WARN("relay %d is not using a driver", i);
|
||||||
|
|
Loading…
Reference in a new issue