2024-02-23 22:56:10 -08:00
|
|
|
/*
|
|
|
|
* util.h - Utility functions
|
|
|
|
* Copyright (C) 2024 Alexander Rosenberg
|
|
|
|
*
|
|
|
|
* This program is free software: you can redistribute it and/or modify it under
|
|
|
|
* the terms of the GNU General Public License as published by the Free Software
|
|
|
|
* Foundation, either version 3 of the License, or (at your option) any later
|
|
|
|
* version. See the LICENSE file for more information.
|
|
|
|
*/
|
|
|
|
#ifndef INCLUDED_UTIL_H
|
|
|
|
#define INCLUDED_UTIL_H
|
|
|
|
|
|
|
|
#include <stdlib.h>
|
2024-02-25 23:59:26 -08:00
|
|
|
#include <stdint.h>
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <time.h>
|
|
|
|
#include <stdbool.h>
|
|
|
|
#include <sys/types.h>
|
|
|
|
#include <libgpio.h>
|
2024-02-23 22:56:10 -08:00
|
|
|
|
2024-02-25 23:59:26 -08:00
|
|
|
typedef struct {
|
|
|
|
char *config_path; // path to config file
|
|
|
|
bool strict_config; // exit if unknown config options is found
|
|
|
|
bool verbose; // be more verbose
|
|
|
|
|
|
|
|
char *gpio_path; // path of GPIO device file to use
|
|
|
|
gpio_pin_t en_pin;
|
|
|
|
gpio_pin_t rs_pin;
|
|
|
|
gpio_pin_t rw_pin;
|
|
|
|
gpio_pin_t data_pins[8];
|
|
|
|
char *lcd_version; // Is LCD jp or eu
|
|
|
|
char *temp_key; // sysctl key for temperature
|
|
|
|
char *humid_key; // sysctl key for humidity
|
|
|
|
char *fail_key; // sysctl key for number of fails
|
|
|
|
uint32_t fail_limit; // limit for number of failures before exit
|
2024-02-28 12:09:18 -08:00
|
|
|
uint32_t refresh_time; // time between temp and humid refresh
|
2024-03-01 00:21:20 -08:00
|
|
|
|
|
|
|
// menu navigation pins
|
|
|
|
gpio_pin_t up_pin;
|
|
|
|
gpio_pin_t down_pin;
|
|
|
|
gpio_pin_t back_pin;
|
|
|
|
gpio_pin_t sel_pin;
|
2024-02-25 23:59:26 -08:00
|
|
|
} Options;
|
|
|
|
extern Options GLOBAL_OPTS;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Cleanup an Options struct.
|
|
|
|
*/
|
|
|
|
void cleanup_options(Options *opts);
|
2024-02-23 22:56:10 -08:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Like malloc(3), except that if allocation fails, an error will be written to
|
|
|
|
* standard error and abort(3) called
|
|
|
|
*/
|
|
|
|
void *malloc_checked(size_t n);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Like realloc(3), except that if allocation fails, an error will be written to
|
|
|
|
* standard error and abort(3) called
|
|
|
|
*/
|
|
|
|
void *realloc_checked(void *old_ptr, size_t n);
|
|
|
|
|
2024-02-25 23:59:26 -08:00
|
|
|
/*
|
|
|
|
* Like strdup(3), except that if allocation fails, an error will be written to
|
|
|
|
* standard error and abort(3) called
|
|
|
|
*/
|
|
|
|
void *strdup_checked(const char *str);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Like free(3), but do nothing if P is NULL.
|
|
|
|
*/
|
|
|
|
#define FREE_CHECKED(p) if (p) {free(p);}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Call fprintf(3) to stderr only if verbose mode was enabled.
|
|
|
|
*/
|
|
|
|
#define LOG_VERBOSE(...) if (GLOBAL_OPTS.verbose) {fprintf(stderr, __VA_ARGS__);}
|
|
|
|
|
2024-02-23 22:56:10 -08:00
|
|
|
#endif
|