Commit f401849f authored by Hermann Mayer's avatar Hermann Mayer

[Utils][Config][Binary] Made all hard coded timeouts configurable. (See #11)

parent 9deedb16
......@@ -88,6 +88,14 @@ int switch_action_off(struct config *c)
return ret;
}
void sleep_nz(int secs)
{
if (secs > 0) {
utlog(LOG_NOTICE, " Sleep for %d secs\n", secs);
sleep(secs);
}
}
void detect_motions(struct config *conf)
{
int allvl = 0;
......@@ -117,7 +125,7 @@ void detect_motions(struct config *conf)
utlog(LOG_INFO, " %s (%d) %s (%d), %s\n", "The ambient light level",
allvl, "passed the threshold", conf->tholds.light_sensor,
"it's too bright in here");
sleep(30);
sleep_nz(conf->tholds.too_bright_timeout);
pirmtn_reset();
continue;
}
......@@ -129,10 +137,15 @@ void detect_motions(struct config *conf)
if (0 < switch_action(conf)) {
// Something went wrong, so wait a little while and try again
sleep(1);
utlog(LOG_ERR, " %s %s\n", "Something went wrong while performing",
"the action on the actor, give it one last chance");
sleep_nz(conf->tholds.backup_action_timeout);
if (0 < switch_action(conf)) {
// The second try wasn't successful either, so skip this cicle
sleep(30);
utlog(LOG_ERR, " %s %s\n", "Something went wrong while",
"performing the action on the actor, again, giving up");
sleep_nz(conf->tholds.failed_backup_action_timeout);
pirmtn_reset();
continue;
}
......
......@@ -52,6 +52,9 @@ struct config* init_config(struct config *conf)
conf->tholds.light_sensor = 0;
conf->tholds.motion_locktime = 30;
conf->tholds.too_bright_timeout= 30;
conf->tholds.backup_action_timeout = 1;
conf->tholds.failed_backup_action_timeout = 30;
conf->sensor.motion_gpio = 0;
conf->sensor.light_dev = "/dev/spidev0.0";
......@@ -110,6 +113,10 @@ struct config get_config(const char *path)
*/
config_lookup_int(c, "light_sensor_thold", &conf.tholds.light_sensor);
config_lookup_int(c, "motion_sensor_locktime", &conf.tholds.motion_locktime);
config_lookup_int(c, "too_bright_timeout", &conf.tholds.too_bright_timeout);
config_lookup_int(c, "backup_action_timeout", &conf.tholds.backup_action_timeout);
config_lookup_int(c, "failed_backup_action_timeout",
&conf.tholds.failed_backup_action_timeout);
/*
* Sensor ports section settings
......
......@@ -38,6 +38,11 @@ struct config {
struct config_tholds {
int light_sensor;
int motion_locktime;
int too_bright_timeout;
int backup_action_timeout;
int failed_backup_action_timeout;
} tholds;
struct config_sensor {
int motion_gpio;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment