add: choose initial relay mode
This commit is contained in:
parent
5e05d603c1
commit
d7c274ca86
11 changed files with 57 additions and 27 deletions
src
27
src/main.c
27
src/main.c
|
@ -77,6 +77,9 @@ main(int argc, const char** argv)
|
|||
global_config.discovery_port = 4421;
|
||||
global_config.mqtt_port = 1885;
|
||||
|
||||
global_config.relay_count = 0;
|
||||
global_config.relay_init = -1;
|
||||
|
||||
global_config.log_level = LOG_INFO;
|
||||
global_config.log_file = stdout;
|
||||
|
||||
|
@ -138,15 +141,29 @@ main(int argc, const char** argv)
|
|||
|
||||
for(uint_fast8_t i = 0; i < global_controller->relay_count; ++i)
|
||||
{
|
||||
int relay_default = global_config.relay_configs[i].init
|
||||
if(relay_default == -1)
|
||||
{
|
||||
relay_default = global_config.relays_init;
|
||||
}
|
||||
if(relay_default == -1)
|
||||
{
|
||||
relay_default = global_config.relay_configs[i].inverted
|
||||
}
|
||||
|
||||
if(global_config.relay_configs[i].driver == RELAY_DRIVER_GPIO)
|
||||
{
|
||||
pinMode(global_config.relay_configs[i].pin, OUTPUT);
|
||||
digitalWrite(global_config.relay_configs[i].pin, global_config.relay_configs[i].inverted);
|
||||
driver_gpio_set(global_config.relay_configs[i].pin, relay_default);
|
||||
}
|
||||
if((global_config.relay_configs[i].driver == RELAY_DRIVER_PIFACE) && !piface_setup)
|
||||
if(global_config.relay_configs[i].driver == RELAY_DRIVER_PIFACE)
|
||||
{
|
||||
piFaceSetup(PIFACE_GPIO_BASE);
|
||||
piface_setup = 1;
|
||||
if(!piface_setup)
|
||||
{
|
||||
piFaceSetup(PIFACE_GPIO_BASE);
|
||||
piface_setup = 1;
|
||||
}
|
||||
driver_piface_set(global_config.relay_configs[i].pin, relay_default);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -162,7 +179,7 @@ main(int argc, const char** argv)
|
|||
|
||||
/******************** START MAIN LOOP ********************/
|
||||
|
||||
time_t timer = time(NULL);
|
||||
time_t timer = 0;
|
||||
|
||||
for (;;)
|
||||
{
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue