commit 345c0981a9aa056b77434547b2b6198aa40802d5
parent e7976530c0eb435943b5d15011c91f7bfb694d57
Author: Paco Esteban <paco@e1e0.net>
Date: Thu, 5 Nov 2020 19:06:41 +0100
add alternate TZ when pressing BUTTON2
while here, reorder getopts to be in alphabetical order.
Diffstat:
M | clock.c | | | 46 | ++++++++++++++++++++++++++++++++-------------- |
1 file changed, 32 insertions(+), 14 deletions(-)
diff --git a/clock.c b/clock.c
@@ -34,13 +34,14 @@
#define LCD_LINES 2
#define I2C_ADDRESS 0x3f
#define BUTTON1 0
+#define BUTTON2 2
#define DEF_R_INTER 120 /* default 30s (250ms * 120) */
#define DEF_SLEEP_INTER 250
#define DEF_BL_BEFORE 0
#define DEF_BL_AFTER 7
#define TAG_MAX_LEN 7
-#define PIC_VERSION "v0.5.1"
+#define PIC_VERSION "v0.6.0"
lcd_i2c_t *init_lcd(void);
char * setmonth(int);
@@ -56,37 +57,40 @@ main(int argc, char *argv[])
time_t t;
struct tm *tm;
char *linebuff = NULL, *str_wday = NULL, *str_month = NULL,
- *extFile = NULL, *script = NULL, *extTag = NULL;
+ *extFile = NULL, *script = NULL, *extTag = NULL, *tz = NULL;
long gmt_offset;
uint8_t backlight_status = 0, vflag = 0, eflag = 0;
int readCount = 0, tmp_on_cycles = 0, ch;
int bl_before = DEF_BL_BEFORE, bl_after = DEF_BL_AFTER,
readInterval = DEF_R_INTER, sleepInterval = DEF_SLEEP_INTER;
- while ((ch = getopt(argc, argv, "b:a:s:S:r:e:v")) != -1) {
+ while ((ch = getopt(argc, argv, "S:a:b:e:r:s:t:v")) != -1) {
switch (ch) {
- case 'b':
- bl_before = atoi(optarg);
+ case 'S':
+ sleepInterval = atoi(optarg);
break;
case 'a':
bl_after = atoi(optarg);
break;
- case 's':
+ case 'b':
+ bl_before = atoi(optarg);
+ break;
+ case 'e':
+ eflag = 1;
if (strlen(optarg) > PATH_MAX)
err(1, "path too long");
- script = strdup(optarg);
- break;
- case 'S':
- sleepInterval = atoi(optarg);
+ extFile = strdup(optarg);
break;
case 'r':
readInterval = atoi(optarg);
break;
- case 'e':
- eflag = 1;
+ case 's':
if (strlen(optarg) > PATH_MAX)
err(1, "path too long");
- extFile = strdup(optarg);
+ script = strdup(optarg);
+ break;
+ case 't':
+ tz = strdup(optarg);
break;
case 'v':
vflag = 1;
@@ -185,6 +189,17 @@ main(int argc, char *argv[])
}
delay(250);
}
+ if (digitalRead(BUTTON2) == LOW) {
+ eflag = 0;
+ if (tz == NULL)
+ tz = strdup("PST8PDT");
+ if (getenv("TZ"))
+ unsetenv("TZ");
+ else
+ setenv("TZ", tz, 1);
+ tzset();
+ delay(250);
+ }
if (tmp_on_cycles > 0)
tmp_on_cycles--;
@@ -250,7 +265,8 @@ usage(void)
{
fprintf(stderr,
"usage: clock [-v] [-b <hour>] [-a <hour>] [-s <script>] \n "
- "\t[-S <miliseconds>] [-r <readCount>] [-e <tagfile>]\n");
+ "\t[-S <miliseconds>] [-r <readCount>] [-e <tagfile>]\n"
+ "\t[-t <alt_timezone>]\n");
exit(1);
}
@@ -276,6 +292,8 @@ init_pins(void)
pinMode(BUTTON1, INPUT);
pullUpDnControl(BUTTON1, PUD_UP);
+ pinMode(BUTTON2, INPUT);
+ pullUpDnControl(BUTTON2, PUD_UP);
return 0;
}