diff --git a/controller.ini b/controller.ini index dd1b389..900ea0f 100644 --- a/controller.ini +++ b/controller.ini @@ -2,6 +2,7 @@ name = new emgauwa device discovery-port = 4421 relay-count = 10 +database = db.lmdb [relay-0] driver = piface diff --git a/database.c b/database.c index e294a89..4d85944 100644 --- a/database.c +++ b/database.c @@ -3,10 +3,11 @@ #include #include +#include #include void -database_setup(MDB_env **mdb_env) +database_setup(MDB_env **mdb_env, config_t *config) { int err; @@ -22,7 +23,7 @@ database_setup(MDB_env **mdb_env) exit(1); } - if(mdb_env_open(*mdb_env, "db.lmdb", MDB_NOSUBDIR, 0700) != 0) + if(mdb_env_open(*mdb_env, config->database, MDB_NOSUBDIR, 0700) != 0) { perror("Can't open mdb file"); exit(1); diff --git a/drivers/gpio.c b/drivers/gpio.c index 833d9f7..0fd78b9 100644 --- a/drivers/gpio.c +++ b/drivers/gpio.c @@ -10,6 +10,5 @@ driver_gpio_set(int pin, int value) // disable "unused parameter" warning (happens when using wiring_debug) (void)pin; (void)value; - pinMode(pin, OUTPUT); digitalWrite(pin, value); } diff --git a/drivers/piface.c b/drivers/piface.c index d3a1313..d26eec9 100644 --- a/drivers/piface.c +++ b/drivers/piface.c @@ -10,5 +10,5 @@ driver_piface_set(int pin, int value) // disable "unused parameter" warning (happens when using wiring_debug) (void)pin; (void)value; - digitalWrite(DRIVER_PIFACE_GPIO_BASE + pin, value); + digitalWrite(PIFACE_GPIO_BASE + pin, value); } diff --git a/helpers/load_config.c b/helpers/load_config.c index e66df6e..4c95c7d 100644 --- a/helpers/load_config.c +++ b/helpers/load_config.c @@ -24,6 +24,11 @@ helper_load_config(IniDispatch *disp, void *config_void) config->name[MAX_NAME_LENGTH] = '\0'; return 0; } + if(CONFINI_IS_KEY("controller", "database")) + { + config->database = disp->value; + return 0; + } if(CONFINI_IS_KEY("controller", "discovery-port")) { config->discovery_port = atoi(disp->value); diff --git a/include/config.h b/include/config.h index 6979b42..3c74c4f 100644 --- a/include/config.h +++ b/include/config.h @@ -16,6 +16,7 @@ typedef struct typedef struct { char *file; + char *database; run_type_t run_type; char name[MAX_NAME_LENGTH + 1]; uint16_t discovery_port; diff --git a/include/constants.h b/include/constants.h index 6f8e4d1..a9bb525 100644 --- a/include/constants.h +++ b/include/constants.h @@ -35,4 +35,6 @@ */ #define ACCEPT_TIMEOUT_MSECONDS 1000 +#define PIFACE_GPIO_BASE 200 + #endif /* CONTROLLER_CONTANTS_H */ diff --git a/include/database.h b/include/database.h index 110159f..1c79f44 100644 --- a/include/database.h +++ b/include/database.h @@ -12,6 +12,6 @@ * @param mdb_env Source variable will be set to new MDB_env */ void -database_setup(MDB_env **mdb_env); +database_setup(MDB_env **mdb_env, config_t *config); #endif /* CONTROLLER_DATABASE_H */ diff --git a/include/drivers.h b/include/drivers.h index 6539f7b..2abf97d 100644 --- a/include/drivers.h +++ b/include/drivers.h @@ -4,8 +4,6 @@ #include #include -#define DRIVER_PIFACE_GPIO_BASE 200 - void driver_piface_set(int pin, int value); diff --git a/main.c b/main.c index db59fd0..360391b 100644 --- a/main.c +++ b/main.c @@ -93,7 +93,7 @@ main(int argc, const char** argv) /******************** SETUP DATABASE AND THIS CONTROLLER ********************/ - database_setup(&mdb_env); + database_setup(&mdb_env, &global_config); this_controller = controller_load(mdb_env); @@ -108,7 +108,15 @@ main(int argc, const char** argv) /******************** SETUP WIRINGPI ********************/ wiringPiSetup(); - piFaceSetup(200); + piFaceSetup(PIFACE_GPIO_BASE); + + for(uint_fast8_t i = 0; i < this_controller->relay_count; ++i) + { + if(global_config.relay_configs[i].driver == RELAY_DRIVER_GPIO) + { + pinMode(global_config.relay_configs[i].pin, OUTPUT); + } + } /******************** SETUP SOCKETS ********************/