pi_clock

Crude and unpolished clock for Raspberry Pi
git clone https://git.e1e0.net/pi_clock.git
Log | Files | Refs | README | LICENSE

commit 01d44d92294b276f65c73c99d3cb74178cebcc9b
parent 8596da5599f29122b8847eb1b19806de6672b76c
Author: Paco Esteban <paco@e1e0.net>
Date:   Mon, 23 Mar 2020 20:08:50 +0100

turn light on at night per push button.

Pushing the button while in backlight off mode it toggles it for
16 * sleepInterval (by default 250ms, so 4s)

Diffstat:
Mclock.c | 27++++++++++++++++++---------
1 file changed, 18 insertions(+), 9 deletions(-)

diff --git a/clock.c b/clock.c @@ -30,7 +30,7 @@ #define I2C_ADDRESS 0x3f #define BUTTON1 3 -const char *version = "v0.3.0"; +const char *version = "v0.4.0"; void setmonth(char *, int); void setwday(char *, int); @@ -58,6 +58,7 @@ main(int argc, char *argv[]) int readCount = 0; int readInterval = 120; // default 30s (250ms * 120) int sleepInterval = 250; + int tmp_on_cycles = 0; int ch; while ((ch = getopt(argc, argv, "b:a:s:S:r:e:v")) != -1) { @@ -122,7 +123,7 @@ main(int argc, char *argv[]) tm = *localtime(&t); if (tm.tm_hour >= bl_before && tm.tm_hour <= bl_after) { - if (backlight_status) { + if (backlight_status && !tmp_on_cycles) { LCD_I2C_BACKLIGHT_OFF(&lcd); backlight_status = 0; } @@ -165,19 +166,27 @@ main(int argc, char *argv[]) lcd_i2c_puts(&lcd, line1); if (digitalRead(BUTTON1) == LOW) { - if (strlen(script) > 2) { - fprintf(stderr, "calling '%s'\n", script); - system(script); - } else { - if (strlen(extFile) > 2) { - eflag = !eflag; + if (backlight_status) { + if (strlen(script) > 2) { + fprintf(stderr, "calling '%s'\n", + script); + system(script); } else { - fprintf(stderr, "Nothing to do\n"); + if (strlen(extFile) > 2) { + eflag = !eflag; + } } + } else { + LCD_I2C_BACKLIGHT_ON(&lcd); + backlight_status = 1; + tmp_on_cycles = 16; } delay(250); } + if (tmp_on_cycles > 0) + tmp_on_cycles--; + delay(sleepInterval); }