Sensor Watch 0.0.2
A board replacement for the classic Casio F-91W wristwatch, powered by a Microchip SAM L22 microcontroller.
Loading...
Searching...
No Matches
watch_utility.h
1/*
2 * MIT License
3 *
4 * Copyright (c) 2021 Joey Castillo
5 *
6 * Permission is hereby granted, free of charge, to any person obtaining a copy
7 * of this software and associated documentation files (the "Software"), to deal
8 * in the Software without restriction, including without limitation the rights
9 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10 * copies of the Software, and to permit persons to whom the Software is
11 * furnished to do so, subject to the following conditions:
12 *
13 * The above copyright notice and this permission notice shall be included in all
14 * copies or substantial portions of the Software.
15 *
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22 * SOFTWARE.
23 */
24
25#ifndef _WATCH_UTILITY_H_INCLUDED
26#define _WATCH_UTILITY_H_INCLUDED
28
29/*
30 * Define use_iso_8601_weeknumber as 1 to let weeknumbers start on Monday, 0 to start on Sunday.
31 */
32#define use_iso_8601_weeknumber 0
33
34#include "watch.h"
35
40
41typedef struct {
42 uint8_t seconds; // 0-59
43 uint8_t minutes; // 0-59
44 uint8_t hours; // 0-23
45 uint32_t days; // 0-4294967295
47
52const char * watch_utility_get_weekday(watch_date_time date_time);
53
59uint8_t watch_utility_get_iso8601_weekday_number(uint16_t year, uint8_t month, uint8_t day);
60
61
67uint8_t watch_utility_get_weeknumber(uint16_t year, uint8_t month, uint8_t day);
68
74uint16_t watch_utility_days_since_new_year(uint16_t year, uint8_t month, uint8_t day);
75
79uint8_t is_leap(uint16_t year);
80
94uint32_t watch_utility_convert_to_unix_time(uint16_t year, uint8_t month, uint8_t day, uint8_t hour, uint8_t minute, uint8_t second, uint32_t utc_offset);
95
101uint32_t watch_utility_date_time_to_unix_time(watch_date_time date_time, uint32_t utc_offset);
102
108
117watch_date_time watch_utility_date_time_from_unix_time(uint32_t timestamp, uint32_t utc_offset);
118
131
141watch_date_time watch_utility_date_time_convert_zone(watch_date_time date_time, uint32_t origin_utc_offset, uint32_t destination_utc_offset);
142
157float watch_utility_thermistor_temperature(uint16_t value, bool highside, float b_coefficient, float nominal_temperature, float nominal_resistance, float series_resistance);
158
165uint32_t watch_utility_offset_timestamp(uint32_t now, int8_t hours, int8_t minutes, int8_t seconds);
166
171uint8_t days_in_month(uint8_t month, uint16_t year);
172
173#endif
uint32_t watch_utility_offset_timestamp(uint32_t now, int8_t hours, int8_t minutes, int8_t seconds)
Offset a timestamp by a given amount.
Definition watch_utility.c:311
uint8_t watch_utility_get_weeknumber(uint16_t year, uint8_t month, uint8_t day)
Returns a number between 1-53 representing the weeknumber according to ISO8601 : First week of the ye...
Definition watch_utility.c:45
float watch_utility_thermistor_temperature(uint16_t value, bool highside, float b_coefficient, float nominal_temperature, float nominal_resistance, float series_resistance)
Returns a temperature in degrees Celsius for a given thermistor voltage divider circuit.
Definition watch_utility.c:291
uint8_t watch_utility_get_iso8601_weekday_number(uint16_t year, uint8_t month, uint8_t day)
Returns a number between 1-7 representing the weekday according to ISO8601 : week starts on Monday an...
Definition watch_utility.c:34
uint16_t watch_utility_days_since_new_year(uint16_t year, uint8_t month, uint8_t day)
Returns a number between 1-366 representing the elapsed days since January 1st the same year.
Definition watch_utility.c:86
watch_date_time watch_utility_date_time_from_unix_time(uint32_t timestamp, uint32_t utc_offset)
Returns a watch_date_time struct for a given UNIX time and UTC offset.
Definition watch_utility.c:198
bool watch_utility_convert_to_12_hour(watch_date_time *date_time)
Converts a watch_date_time for 12-hour display.
Definition watch_utility.c:284
watch_duration_t watch_utility_seconds_to_duration(uint32_t seconds)
Converts a duration in seconds to a watch_duration_t struct.
Definition watch_utility.c:273
watch_date_time watch_utility_date_time_convert_zone(watch_date_time date_time, uint32_t origin_utc_offset, uint32_t destination_utc_offset)
Converts a time from a given time zone to another time zone.
Definition watch_utility.c:268
uint32_t watch_utility_convert_to_unix_time(uint16_t year, uint8_t month, uint8_t day, uint8_t hour, uint8_t minute, uint8_t second, uint32_t utc_offset)
Returns the UNIX time (seconds since 1970) for a given date/time in UTC.
Definition watch_utility.c:170
const char * watch_utility_get_weekday(watch_date_time date_time)
Returns a two-letter weekday for the given timestamp, suitable for display in positions 0-1 of the wa...
Definition watch_utility.c:28
uint8_t days_in_month(uint8_t month, uint16_t year)
Returns the number of days in a month. It also handles Leap Years for February.
Definition watch_utility.c:319
uint8_t is_leap(uint16_t year)
Returns 1 if year is leap and 0 otherwise.
Definition watch_utility.c:80
uint32_t watch_utility_date_time_to_unix_time(watch_date_time date_time, uint32_t utc_offset)
Returns the UNIX time (seconds since 1970) for a given watch_date_time struct.
Definition watch_utility.c:188
Definition watch_utility.h:41
Definition watch_rtc.h:44