Makefile, options, and lcd stuff

This commit is contained in:
Alexander Rosenberg 2024-02-28 05:31:35 -08:00
parent 58e7bc053e
commit 56e5fc7a6d
Signed by: school-rpi4
GPG Key ID: 5CCFC80B0B47B04B
9 changed files with 32 additions and 15 deletions

View File

@ -1,20 +1,22 @@
CC=clang CC=clang
CFLAGS=-std=c99 -g CFLAGS=-std=c99
LD=clang LD=clang
LDFLAGS=-lgpio -lfigpar LDFLAGS=-lgpio -lfigpar
OBJS=main.o util.o lcd.o ths.o SRCS=src/main.c src/util.c src/lcd.c src/ths.c
OUTFILE=rpi4b-temp-humidity PROG=rpi4b-temp-humidity
.include "config.mk" .include "config.mk"
${OUTFILE}: ${OBJS} OBJS=${SRCS:C/^src/bin/:C/.c$/.o/}
${LD} ${LDFLAGS} -o $@ ${OBJS} bin/${PROG}: ${OBJS}
${LD} ${LDFLAGS} -o ${@} ${OBJS}
main.o util.o lcd.o ths.o: util.h main.o util.o lcd.o ths.o: util.h
main.o lcd.o: lcd.h main.o lcd.o: lcd.h
main.o ths.o: ths.h main.o ths.o: ths.h
.c.o: ${OBJS}: ${.TARGET:C/^bin/src/:C/.o$/.c/}
@mkdir -p bin/
${CC} ${CFLAGS} -c\ ${CC} ${CFLAGS} -c\
-DDEFAULT_CONFIG_PATH="\"${DEFAULT_CONFIG_PATH}\""\ -DDEFAULT_CONFIG_PATH="\"${DEFAULT_CONFIG_PATH}\""\
-DDEFAULT_GPIO_DEVICE="\"${DEFAULT_GPIO_DEVICE}\""\ -DDEFAULT_GPIO_DEVICE="\"${DEFAULT_GPIO_DEVICE}\""\
@ -23,10 +25,10 @@ main.o ths.o: ths.h
-DDEFAULT_FAIL_KEY="\"${DEFAULT_FAIL_KEY}\""\ -DDEFAULT_FAIL_KEY="\"${DEFAULT_FAIL_KEY}\""\
-DDEFAULT_FAIL_LIMIT="${DEFAULT_FAIL_LIMIT}"\ -DDEFAULT_FAIL_LIMIT="${DEFAULT_FAIL_LIMIT}"\
-DDEFAULT_LCD_VERSION="\"${DEFAULT_LCD_VERSION}\""\ -DDEFAULT_LCD_VERSION="\"${DEFAULT_LCD_VERSION}\""\
$< -o ${@} ${.ALLSRC}
clean: clean:
rm -f ${OUTFILE} ${OBJS} rm -rf bin/
.SUFFIXES: .c .o .SUFFIXES: .c .o
.PHONY: clean .PHONY: clean

View File

@ -2,6 +2,7 @@ DEFAULT_CONFIG_PATH=config.conf
DEFAULT_GPIO_DEVICE=/dev/gpioc0 DEFAULT_GPIO_DEVICE=/dev/gpioc0
DEFAULT_TEMP_KEY=dev.gpioths.0.temperature DEFAULT_TEMP_KEY=dev.gpioths.0.temperature
DEFAULT_HUMID_KEY=dev.gpioths.0.humidity DEFAULT_HUMID_KEY=dev.gpioths.0.humidity
DEFAULT_FAIL_KEY=dev.gpioths.0.fails #DEFAULT_FAIL_KEY=dev.gpioths.0.fails
DEFAULT_FAIL_KEY=
DEFAULT_FAIL_LIMIT=5 DEFAULT_FAIL_LIMIT=5
DEFAULT_LCD_VERSION=jp DEFAULT_LCD_VERSION=jp

View File

@ -61,7 +61,9 @@ LCD *lcd_open(gpio_handle_t handle, gpio_pin_t rs, gpio_pin_t rw, gpio_pin_t en,
lcd->d5 = d5; lcd->d5 = d5;
lcd->d6 = d6; lcd->d6 = d6;
lcd->d7 = d7; lcd->d7 = d7;
lcd_set_read(lcd, true, true); gpio_pin_output(lcd->handle, lcd->rw);
gpio_pin_output(lcd->handle, lcd->en);
gpio_pin_output(lcd->handle, lcd->rs);
lcd_clear(lcd); lcd_clear(lcd);
lcd_call(lcd, 0, 0, 0, 0, 1, 1, 1, 0, 0); // 5x8 font, 2 lines, 8bit lcd_call(lcd, 0, 0, 0, 0, 1, 1, 1, 0, 0); // 5x8 font, 2 lines, 8bit
lcd_entry_mode(lcd, LCD_INCREMENT, LCD_CURSOR_MOVE); lcd_entry_mode(lcd, LCD_INCREMENT, LCD_CURSOR_MOVE);

View File

View File

@ -54,8 +54,11 @@ int main(int argc, char *const *argv) {
lcd_display_control(lcd, LCD_CURSOR_BLINK, LCD_CURSOR_ON, LCD_DISPLAY_ON); lcd_display_control(lcd, LCD_CURSOR_BLINK, LCD_CURSOR_ON, LCD_DISPLAY_ON);
THS *ths = ths_open(GLOBAL_OPTS.temp_key, GLOBAL_OPTS.humid_key, THS *ths = ths_open(GLOBAL_OPTS.temp_key, GLOBAL_OPTS.humid_key,
GLOBAL_OPTS.fail_key); GLOBAL_OPTS.fail_key);
if (!GLOBAL_OPTS.fail_key) {
warnx("it's probably a bad idea to not set fail_key");
}
while (true) { while (true) {
if (ths_read_fails(ths) > GLOBAL_OPTS.fail_limit) { if (GLOBAL_OPTS.fail_key && ths_read_fails(ths) > GLOBAL_OPTS.fail_limit) {
errx(1, "THS fail limit reached"); errx(1, "THS fail limit reached");
} }
lcd_clear(lcd); lcd_clear(lcd);
@ -79,7 +82,7 @@ int main(int argc, char *const *argv) {
} }
void print_help(const char *exec_name) { void print_help(const char *exec_name) {
printf("usage: %s [-h] [-v] [-s] [-f CONFIG_PATH]", exec_name); printf("usage: %s [-h] [-v] [-s] [-f CONFIG_PATH]\n", exec_name);
} }
void parse_arguments(int argc, char *const *argv) { void parse_arguments(int argc, char *const *argv) {
@ -196,6 +199,15 @@ static int parse_str_callback(struct figpar_config *opt, uint32_t line,
return 0; return 0;
} }
static char *steal_opt_if_set(char *str) {
if (str && !*str) {
free(str);
return NULL;
}
return str;
}
#define REQUIRE_KEY(ind, name) if (entries[ind].type == FIGPAR_TYPE_NONE) {\ #define REQUIRE_KEY(ind, name) if (entries[ind].type == FIGPAR_TYPE_NONE) {\
errx(1, "%s must be specified", # name);\ errx(1, "%s must be specified", # name);\
} }
@ -222,15 +234,15 @@ static void set_options_from_entries(struct figpar_config *entries,
memcpy(GLOBAL_OPTS.data_pins, arr->arr, sizeof(uint32_t) * 8); memcpy(GLOBAL_OPTS.data_pins, arr->arr, sizeof(uint32_t) * 8);
entries[5].type = FIGPAR_TYPE_NONE; entries[5].type = FIGPAR_TYPE_NONE;
GLOBAL_OPTS.temp_key = entries[5].value.str; GLOBAL_OPTS.temp_key = steal_opt_if_set(entries[5].value.str);
LOG_VERBOSE("Using temp_key: \"%s\"\n", GLOBAL_OPTS.temp_key); LOG_VERBOSE("Using temp_key: \"%s\"\n", GLOBAL_OPTS.temp_key);
entries[6].type = FIGPAR_TYPE_NONE; entries[6].type = FIGPAR_TYPE_NONE;
GLOBAL_OPTS.humid_key = entries[6].value.str; GLOBAL_OPTS.humid_key = steal_opt_if_set(entries[6].value.str);
LOG_VERBOSE("Using humid_key: \"%s\"\n", GLOBAL_OPTS.humid_key); LOG_VERBOSE("Using humid_key: \"%s\"\n", GLOBAL_OPTS.humid_key);
entries[7].type = FIGPAR_TYPE_NONE; entries[7].type = FIGPAR_TYPE_NONE;
GLOBAL_OPTS.fail_key = entries[7].value.str; GLOBAL_OPTS.fail_key = steal_opt_if_set(entries[7].value.str);
LOG_VERBOSE("Using fail_key: \"%s\"\n", GLOBAL_OPTS.fail_key); LOG_VERBOSE("Using fail_key: \"%s\"\n", GLOBAL_OPTS.fail_key);
GLOBAL_OPTS.fail_limit = entries[8].value.u_num; GLOBAL_OPTS.fail_limit = entries[8].value.u_num;

View File

View File

View File

View File