Flesh out time module
This commit is contained in:
parent
8be7ec1e28
commit
cee2e368dc
@ -7,7 +7,7 @@
|
||||
|
||||
#include "display_driver.h"
|
||||
#include "fatal.h"
|
||||
#include "time.h"
|
||||
#include "time_manager.h"
|
||||
|
||||
#include "esp_log.h"
|
||||
#include "esp_timer.h"
|
||||
@ -57,7 +57,7 @@ static void show_time(unsigned hour, unsigned minute)
|
||||
static void update_time(void *arg)
|
||||
{
|
||||
(void)arg;
|
||||
const Time time = time_get();
|
||||
const Time time = get_time();
|
||||
show_time(time.hour, time.minute);
|
||||
}
|
||||
|
||||
|
@ -1,5 +1,5 @@
|
||||
idf_component_register(
|
||||
SRCS "time.c"
|
||||
SRCS "time_manager.c"
|
||||
INCLUDE_DIRS "."
|
||||
REQUIRES
|
||||
REQUIRES config
|
||||
)
|
||||
|
@ -1,15 +0,0 @@
|
||||
/*
|
||||
* SPDX-License-Identifier: AGPL-3.0-only
|
||||
* Copyright (c) Camden Dixie O'Brien
|
||||
*/
|
||||
|
||||
#include "time.h"
|
||||
|
||||
void time_init(void)
|
||||
{
|
||||
}
|
||||
|
||||
Time time_get(void)
|
||||
{
|
||||
return (Time){ .hour = 13, .minute = 37 };
|
||||
}
|
33
components/time/time_manager.c
Normal file
33
components/time/time_manager.c
Normal file
@ -0,0 +1,33 @@
|
||||
/*
|
||||
* SPDX-License-Identifier: AGPL-3.0-only
|
||||
* Copyright (c) Camden Dixie O'Brien
|
||||
*/
|
||||
|
||||
#include "time_manager.h"
|
||||
|
||||
#include "config.h"
|
||||
|
||||
#include <time.h>
|
||||
|
||||
static void handle_timezone_update(const char *timezone)
|
||||
{
|
||||
setenv("TZ", timezone, 1);
|
||||
tzset();
|
||||
}
|
||||
|
||||
void time_manager_init(void)
|
||||
{
|
||||
char timezone[CONFIG_MAX_VALUE_SIZE];
|
||||
(void)config_get_timezone(timezone, CONFIG_MAX_VALUE_SIZE);
|
||||
handle_timezone_update(timezone);
|
||||
|
||||
config_add_timezone_callback(&handle_timezone_update);
|
||||
}
|
||||
|
||||
Time get_time(void)
|
||||
{
|
||||
const time_t now = time(NULL);
|
||||
struct tm timeinfo;
|
||||
(void)localtime_r(&now, &timeinfo);
|
||||
return (Time) { .hour = timeinfo.tm_hour, .minute = timeinfo.tm_min };
|
||||
}
|
@ -3,8 +3,8 @@
|
||||
* Copyright (c) Camden Dixie O'Brien
|
||||
*/
|
||||
|
||||
#ifndef TIME_H
|
||||
#define TIME_H
|
||||
#ifndef TIME_MANAGER_H
|
||||
#define TIME_MANAGER_H
|
||||
|
||||
typedef struct {
|
||||
unsigned hour;
|
||||
@ -14,11 +14,11 @@ typedef struct {
|
||||
/**
|
||||
* Initialize the time module.
|
||||
*/
|
||||
void time_init(void);
|
||||
void time_manager_init(void);
|
||||
|
||||
/**
|
||||
* Get the current time.
|
||||
*/
|
||||
Time time_get(void);
|
||||
Time get_time(void);
|
||||
|
||||
#endif
|
Loading…
x
Reference in New Issue
Block a user