add: database in config file
fix: set pinMode only on start
This commit is contained in:
parent
fd2f5acbb3
commit
6e3b1d52a4
10 changed files with 24 additions and 9 deletions
|
@ -2,6 +2,7 @@
|
|||
name = new emgauwa device
|
||||
discovery-port = 4421
|
||||
relay-count = 10
|
||||
database = db.lmdb
|
||||
|
||||
[relay-0]
|
||||
driver = piface
|
||||
|
|
|
@ -3,10 +3,11 @@
|
|||
#include <stdio.h>
|
||||
#include <lmdb.h>
|
||||
|
||||
#include <config.h>
|
||||
#include <constants.h>
|
||||
|
||||
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);
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -35,4 +35,6 @@
|
|||
*/
|
||||
#define ACCEPT_TIMEOUT_MSECONDS 1000
|
||||
|
||||
#define PIFACE_GPIO_BASE 200
|
||||
|
||||
#endif /* CONTROLLER_CONTANTS_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 */
|
||||
|
|
|
@ -4,8 +4,6 @@
|
|||
#include <models/relay.h>
|
||||
#include <enums.h>
|
||||
|
||||
#define DRIVER_PIFACE_GPIO_BASE 200
|
||||
|
||||
void
|
||||
driver_piface_set(int pin, int value);
|
||||
|
||||
|
|
12
main.c
12
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 ********************/
|
||||
|
|
Loading…
Reference in a new issue