LaundrySorcery

Log | Files | Refs

commit 6f059807d18124f9087afe826b4bd43a725900be
parent f8b82eaff11ef173d579cb61a5c7b04cf5553c54
Author: Dominik Schmidt <das1993@hotmail.com>
Date:   Mon, 11 Jun 2018 01:29:16 +0000

Allow to write a log-file, which captures the turn-on and -off events with unix timestamps

Diffstat:
src/laundrysorcery.c | 22++++++++++++++++++++--
1 file changed, 20 insertions(+), 2 deletions(-)

diff --git a/src/laundrysorcery.c b/src/laundrysorcery.c @@ -45,6 +45,19 @@ struct timespec timestamp; double running_mean; char *on_file; +char *log_file; + +void write_log_file(char *term){ + if(!log_file) + return; + FILE *f=fopen(log_file, "a"); + if(!f){ + perror("fopen of log file"); + return; + } + fprintf(f, "%lu%s", time(NULL), term); + fclose(f); +} void write_on_file(char *prefix){ FILE *f=fopen(on_file, "w"); @@ -57,10 +70,12 @@ void write_on_file(char *prefix){ void turn_on(void){ write_on_file(""); + write_log_file(" "); } void turn_off(void){ write_on_file("-"); + write_log_file("\n"); } void toggle_on_off(void){ @@ -152,11 +167,14 @@ int main(int argc, char **argv) wiringPiSetup () ; pinMode (0, OUTPUT) ; pinMode (1, INPUT) ; - if(argc != 2){ - printf("Usage: %s </path/to/onfile>\n", argv[0]); + if(!(argc == 2 || argc == 3)){ + printf("Usage: %s </path/to/onfile> [/path/to/log_file]\n", argv[0]); return 0; } on_file=argv[1]; + if(argc == 3){ + log_file=argv[2]; + } digitalWrite (0, LOW); delay(5);