Sensor-Watch/group__utility.html
2021-12-14 17:06:59 +00:00

348 lines
18 KiB
HTML

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "https://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
<meta http-equiv="X-UA-Compatible" content="IE=9"/>
<meta name="generator" content="Doxygen 1.9.1"/>
<meta name="viewport" content="width=device-width, initial-scale=1"/>
<title>Sensor Watch: Utility Functions</title>
<link href="tabs.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="jquery.js"></script>
<script type="text/javascript" src="dynsections.js"></script>
<link href="search/search.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="search/searchdata.js"></script>
<script type="text/javascript" src="search/search.js"></script>
<link href="doxygen.css" rel="stylesheet" type="text/css" />
</head>
<body>
<div id="top"><!-- do not remove this div, it is closed by doxygen! -->
<div id="titlearea">
<table cellspacing="0" cellpadding="0">
<tbody>
<tr style="height: 56px;">
<td id="projectalign" style="padding-left: 0.5em;">
<div id="projectname">Sensor Watch
&#160;<span id="projectnumber">0.0.0</span>
</div>
<div id="projectbrief">A board replacement for the classic Casio F-91W wristwatch, powered by a Microchip SAM L22 microcontroller.</div>
</td>
</tr>
</tbody>
</table>
</div>
<!-- end header part -->
<!-- Generated by Doxygen 1.9.1 -->
<script type="text/javascript">
/* @license magnet:?xt=urn:btih:cf05388f2679ee054f2beb29a391d25f4e673ac3&amp;dn=gpl-2.0.txt GPL-v2 */
var searchBox = new SearchBox("searchBox", "search",false,'Search','.html');
/* @license-end */
</script>
<script type="text/javascript" src="menudata.js"></script>
<script type="text/javascript" src="menu.js"></script>
<script type="text/javascript">
/* @license magnet:?xt=urn:btih:cf05388f2679ee054f2beb29a391d25f4e673ac3&amp;dn=gpl-2.0.txt GPL-v2 */
$(function() {
initMenu('',true,false,'search.php','Search');
$(document).ready(function() { init_search(); });
});
/* @license-end */</script>
<div id="main-nav"></div>
</div><!-- top -->
<!-- window showing the filter options -->
<div id="MSearchSelectWindow"
onmouseover="return searchBox.OnSearchSelectShow()"
onmouseout="return searchBox.OnSearchSelectHide()"
onkeydown="return searchBox.OnSearchSelectKey(event)">
</div>
<!-- iframe showing the search results (closed by default) -->
<div id="MSearchResultsWindow">
<iframe src="javascript:void(0)" frameborder="0"
name="MSearchResults" id="MSearchResults">
</iframe>
</div>
<div class="header">
<div class="summary">
<a href="#func-members">Functions</a> </div>
<div class="headertitle">
<div class="title">Utility Functions</div> </div>
</div><!--header-->
<div class="contents">
<p>This section covers various useful functions that don't fit anywhere else.
<a href="#details">More...</a></p>
<table class="memberdecls">
<tr class="heading"><td colspan="2"><h2 class="groupheader"><a name="func-members"></a>
Functions</h2></td></tr>
<tr class="memitem:ga8f3d6ddf5f22bc61e1dc4b569009b127"><td class="memItemLeft" align="right" valign="top">const char *&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="group__utility.html#ga8f3d6ddf5f22bc61e1dc4b569009b127">watch_utility_get_weekday</a> (<a class="el" href="unionwatch__date__time.html">watch_date_time</a> date_time)</td></tr>
<tr class="memdesc:ga8f3d6ddf5f22bc61e1dc4b569009b127"><td class="mdescLeft">&#160;</td><td class="mdescRight">Returns a two-letter weekday for the given timestamp, suitable for display in positions 0-1 of the watch face. <a href="group__utility.html#ga8f3d6ddf5f22bc61e1dc4b569009b127">More...</a><br /></td></tr>
<tr class="separator:ga8f3d6ddf5f22bc61e1dc4b569009b127"><td class="memSeparator" colspan="2">&#160;</td></tr>
<tr class="memitem:ga94f5cc404949bf4c0ac4bc4770ec8eda"><td class="memItemLeft" align="right" valign="top">uint32_t&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="group__utility.html#ga94f5cc404949bf4c0ac4bc4770ec8eda">watch_utility_convert_to_unix_time</a> (uint16_t year, uint8_t month, uint8_t day, uint8_t hour, uint8_t minute, uint8_t second, uint32_t utc_offset)</td></tr>
<tr class="memdesc:ga94f5cc404949bf4c0ac4bc4770ec8eda"><td class="mdescLeft">&#160;</td><td class="mdescRight">Returns the UNIX time (seconds since 1970) for a given date/time in UTC. <a href="group__utility.html#ga94f5cc404949bf4c0ac4bc4770ec8eda">More...</a><br /></td></tr>
<tr class="separator:ga94f5cc404949bf4c0ac4bc4770ec8eda"><td class="memSeparator" colspan="2">&#160;</td></tr>
<tr class="memitem:gaffafef58755ff2704cf93fe1a0849a27"><td class="memItemLeft" align="right" valign="top">uint32_t&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="group__utility.html#gaffafef58755ff2704cf93fe1a0849a27">watch_utility_date_time_to_unix_time</a> (<a class="el" href="unionwatch__date__time.html">watch_date_time</a> date_time, uint32_t utc_offset)</td></tr>
<tr class="memdesc:gaffafef58755ff2704cf93fe1a0849a27"><td class="mdescLeft">&#160;</td><td class="mdescRight">Returns the UNIX time (seconds since 1970) for a given <a class="el" href="unionwatch__date__time.html">watch_date_time</a> struct. <a href="group__utility.html#gaffafef58755ff2704cf93fe1a0849a27">More...</a><br /></td></tr>
<tr class="separator:gaffafef58755ff2704cf93fe1a0849a27"><td class="memSeparator" colspan="2">&#160;</td></tr>
<tr class="memitem:ga396e56109234aaa00993c3dd84f3f43c"><td class="memItemLeft" align="right" valign="top"><a class="el" href="unionwatch__date__time.html">watch_date_time</a>&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="group__utility.html#ga396e56109234aaa00993c3dd84f3f43c">watch_utility_date_time_from_unix_time</a> (uint32_t timestamp, uint32_t utc_offset)</td></tr>
<tr class="memdesc:ga396e56109234aaa00993c3dd84f3f43c"><td class="mdescLeft">&#160;</td><td class="mdescRight">Returns the UNIX time (seconds since 1970) for a given <a class="el" href="unionwatch__date__time.html">watch_date_time</a> struct. <a href="group__utility.html#ga396e56109234aaa00993c3dd84f3f43c">More...</a><br /></td></tr>
<tr class="separator:ga396e56109234aaa00993c3dd84f3f43c"><td class="memSeparator" colspan="2">&#160;</td></tr>
<tr class="memitem:ga2753ff031c28202d23b0f3e80de2c920"><td class="memItemLeft" align="right" valign="top">float&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="group__utility.html#ga2753ff031c28202d23b0f3e80de2c920">watch_utility_thermistor_temperature</a> (uint16_t value, bool highside, float b_coefficient, float nominal_temperature, float nominal_resistance, float series_resistance)</td></tr>
<tr class="memdesc:ga2753ff031c28202d23b0f3e80de2c920"><td class="mdescLeft">&#160;</td><td class="mdescRight">Returns a temperature in degrees Celsius for a given thermistor voltage divider circuit. <a href="group__utility.html#ga2753ff031c28202d23b0f3e80de2c920">More...</a><br /></td></tr>
<tr class="separator:ga2753ff031c28202d23b0f3e80de2c920"><td class="memSeparator" colspan="2">&#160;</td></tr>
</table>
<a name="details" id="details"></a><h2 class="groupheader">Detailed Description</h2>
<p>This section covers various useful functions that don't fit anywhere else. </p>
<h2 class="groupheader">Function Documentation</h2>
<a id="ga94f5cc404949bf4c0ac4bc4770ec8eda"></a>
<h2 class="memtitle"><span class="permalink"><a href="#ga94f5cc404949bf4c0ac4bc4770ec8eda">&#9670;&nbsp;</a></span>watch_utility_convert_to_unix_time()</h2>
<div class="memitem">
<div class="memproto">
<table class="memname">
<tr>
<td class="memname">uint32_t watch_utility_convert_to_unix_time </td>
<td>(</td>
<td class="paramtype">uint16_t&#160;</td>
<td class="paramname"><em>year</em>, </td>
</tr>
<tr>
<td class="paramkey"></td>
<td></td>
<td class="paramtype">uint8_t&#160;</td>
<td class="paramname"><em>month</em>, </td>
</tr>
<tr>
<td class="paramkey"></td>
<td></td>
<td class="paramtype">uint8_t&#160;</td>
<td class="paramname"><em>day</em>, </td>
</tr>
<tr>
<td class="paramkey"></td>
<td></td>
<td class="paramtype">uint8_t&#160;</td>
<td class="paramname"><em>hour</em>, </td>
</tr>
<tr>
<td class="paramkey"></td>
<td></td>
<td class="paramtype">uint8_t&#160;</td>
<td class="paramname"><em>minute</em>, </td>
</tr>
<tr>
<td class="paramkey"></td>
<td></td>
<td class="paramtype">uint8_t&#160;</td>
<td class="paramname"><em>second</em>, </td>
</tr>
<tr>
<td class="paramkey"></td>
<td></td>
<td class="paramtype">uint32_t&#160;</td>
<td class="paramname"><em>utc_offset</em>&#160;</td>
</tr>
<tr>
<td></td>
<td>)</td>
<td></td><td></td>
</tr>
</table>
</div><div class="memdoc">
<p>Returns the UNIX time (seconds since 1970) for a given date/time in UTC. </p>
<dl class="params"><dt>Parameters</dt><dd>
<table class="params">
<tr><td class="paramname">date_time</td><td>The <a class="el" href="unionwatch__date__time.html">watch_date_time</a> that you wish to convert. </td></tr>
<tr><td class="paramname">year</td><td>The year of the date you wish to convert. </td></tr>
<tr><td class="paramname">month</td><td>The month of the date you wish to convert. </td></tr>
<tr><td class="paramname">day</td><td>The day of the date you wish to convert. </td></tr>
<tr><td class="paramname">hour</td><td>The hour of the date you wish to convert. </td></tr>
<tr><td class="paramname">minute</td><td>The minute of the date you wish to convert. </td></tr>
<tr><td class="paramname">second</td><td>The second of the date you wish to convert. </td></tr>
<tr><td class="paramname">utc_offset</td><td>The number of seconds that date_time is offset from UTC, or 0 if the time is UTC. </td></tr>
</table>
</dd>
</dl>
<dl class="section return"><dt>Returns</dt><dd>A UNIX timestamp for the given date/time and UTC offset. </dd></dl>
<dl class="section note"><dt>Note</dt><dd>Implemented by Wesley Ellis (tahnok) and based on BSD-licensed code by Josh Haberman: <a href="https://blog.reverberate.org/2020/05/12/optimizing-date-algorithms.html">https://blog.reverberate.org/2020/05/12/optimizing-date-algorithms.html</a> </dd></dl>
</div>
</div>
<a id="ga396e56109234aaa00993c3dd84f3f43c"></a>
<h2 class="memtitle"><span class="permalink"><a href="#ga396e56109234aaa00993c3dd84f3f43c">&#9670;&nbsp;</a></span>watch_utility_date_time_from_unix_time()</h2>
<div class="memitem">
<div class="memproto">
<table class="memname">
<tr>
<td class="memname"><a class="el" href="unionwatch__date__time.html">watch_date_time</a> watch_utility_date_time_from_unix_time </td>
<td>(</td>
<td class="paramtype">uint32_t&#160;</td>
<td class="paramname"><em>timestamp</em>, </td>
</tr>
<tr>
<td class="paramkey"></td>
<td></td>
<td class="paramtype">uint32_t&#160;</td>
<td class="paramname"><em>utc_offset</em>&#160;</td>
</tr>
<tr>
<td></td>
<td>)</td>
<td></td><td></td>
</tr>
</table>
</div><div class="memdoc">
<p>Returns the UNIX time (seconds since 1970) for a given <a class="el" href="unionwatch__date__time.html">watch_date_time</a> struct. </p>
<dl class="params"><dt>Parameters</dt><dd>
<table class="params">
<tr><td class="paramname">timestamp</td><td>The UNIX timestamp that you wish to convert. </td></tr>
<tr><td class="paramname">utc_offset</td><td>The number of seconds that you wish date_time to be offset from UTC. </td></tr>
</table>
</dd>
</dl>
<dl class="section return"><dt>Returns</dt><dd>A <a class="el" href="unionwatch__date__time.html">watch_date_time</a> for the given UNIX timestamp and UTC offset, or if outside the range that <a class="el" href="unionwatch__date__time.html">watch_date_time</a> can represent, a <a class="el" href="unionwatch__date__time.html">watch_date_time</a> with all fields set to 0. </dd></dl>
<dl class="section note"><dt>Note</dt><dd>Adapted from MIT-licensed code from musl, Copyright © 2005-2014 Rich Felker, et al.: <a href="https://github.com/esmil/musl/blob/1cc81f5cb0df2b66a795ff0c26d7bbc4d16e13c6/src/time/__secs_to_tm.c">https://github.com/esmil/musl/blob/1cc81f5cb0df2b66a795ff0c26d7bbc4d16e13c6/src/time/__secs_to_tm.c</a> </dd></dl>
</div>
</div>
<a id="gaffafef58755ff2704cf93fe1a0849a27"></a>
<h2 class="memtitle"><span class="permalink"><a href="#gaffafef58755ff2704cf93fe1a0849a27">&#9670;&nbsp;</a></span>watch_utility_date_time_to_unix_time()</h2>
<div class="memitem">
<div class="memproto">
<table class="memname">
<tr>
<td class="memname">uint32_t watch_utility_date_time_to_unix_time </td>
<td>(</td>
<td class="paramtype"><a class="el" href="unionwatch__date__time.html">watch_date_time</a>&#160;</td>
<td class="paramname"><em>date_time</em>, </td>
</tr>
<tr>
<td class="paramkey"></td>
<td></td>
<td class="paramtype">uint32_t&#160;</td>
<td class="paramname"><em>utc_offset</em>&#160;</td>
</tr>
<tr>
<td></td>
<td>)</td>
<td></td><td></td>
</tr>
</table>
</div><div class="memdoc">
<p>Returns the UNIX time (seconds since 1970) for a given <a class="el" href="unionwatch__date__time.html">watch_date_time</a> struct. </p>
<dl class="params"><dt>Parameters</dt><dd>
<table class="params">
<tr><td class="paramname">date_time</td><td>The <a class="el" href="unionwatch__date__time.html">watch_date_time</a> that you wish to convert. </td></tr>
<tr><td class="paramname">utc_offset</td><td>The number of seconds that date_time is offset from UTC, or 0 if the time is UTC. </td></tr>
</table>
</dd>
</dl>
<dl class="section return"><dt>Returns</dt><dd>A UNIX timestamp for the given <a class="el" href="unionwatch__date__time.html">watch_date_time</a> and UTC offset. </dd></dl>
</div>
</div>
<a id="ga8f3d6ddf5f22bc61e1dc4b569009b127"></a>
<h2 class="memtitle"><span class="permalink"><a href="#ga8f3d6ddf5f22bc61e1dc4b569009b127">&#9670;&nbsp;</a></span>watch_utility_get_weekday()</h2>
<div class="memitem">
<div class="memproto">
<table class="memname">
<tr>
<td class="memname">const char* watch_utility_get_weekday </td>
<td>(</td>
<td class="paramtype"><a class="el" href="unionwatch__date__time.html">watch_date_time</a>&#160;</td>
<td class="paramname"><em>date_time</em></td><td>)</td>
<td></td>
</tr>
</table>
</div><div class="memdoc">
<p>Returns a two-letter weekday for the given timestamp, suitable for display in positions 0-1 of the watch face. </p>
<dl class="params"><dt>Parameters</dt><dd>
<table class="params">
<tr><td class="paramname">date_time</td><td>The <a class="el" href="unionwatch__date__time.html">watch_date_time</a> whose weekday you want. </td></tr>
</table>
</dd>
</dl>
</div>
</div>
<a id="ga2753ff031c28202d23b0f3e80de2c920"></a>
<h2 class="memtitle"><span class="permalink"><a href="#ga2753ff031c28202d23b0f3e80de2c920">&#9670;&nbsp;</a></span>watch_utility_thermistor_temperature()</h2>
<div class="memitem">
<div class="memproto">
<table class="memname">
<tr>
<td class="memname">float watch_utility_thermistor_temperature </td>
<td>(</td>
<td class="paramtype">uint16_t&#160;</td>
<td class="paramname"><em>value</em>, </td>
</tr>
<tr>
<td class="paramkey"></td>
<td></td>
<td class="paramtype">bool&#160;</td>
<td class="paramname"><em>highside</em>, </td>
</tr>
<tr>
<td class="paramkey"></td>
<td></td>
<td class="paramtype">float&#160;</td>
<td class="paramname"><em>b_coefficient</em>, </td>
</tr>
<tr>
<td class="paramkey"></td>
<td></td>
<td class="paramtype">float&#160;</td>
<td class="paramname"><em>nominal_temperature</em>, </td>
</tr>
<tr>
<td class="paramkey"></td>
<td></td>
<td class="paramtype">float&#160;</td>
<td class="paramname"><em>nominal_resistance</em>, </td>
</tr>
<tr>
<td class="paramkey"></td>
<td></td>
<td class="paramtype">float&#160;</td>
<td class="paramname"><em>series_resistance</em>&#160;</td>
</tr>
<tr>
<td></td>
<td>)</td>
<td></td><td></td>
</tr>
</table>
</div><div class="memdoc">
<p>Returns a temperature in degrees Celsius for a given thermistor voltage divider circuit. </p>
<dl class="params"><dt>Parameters</dt><dd>
<table class="params">
<tr><td class="paramname">value</td><td>The raw analog reading from the thermistor pin (0-65535) </td></tr>
<tr><td class="paramname">highside</td><td>True if the thermistor is connected to VCC and the series resistor is connected to GND; false if the thermistor is connected to GND and the series resistor is connected to VCC. </td></tr>
<tr><td class="paramname">b_coefficient</td><td>From your thermistor's data sheet, the B25/85 coefficient. A typical value will be between 2000 and 5000. </td></tr>
<tr><td class="paramname">nominal_temperature</td><td>From your thermistor's data sheet, the temperature (in Celsius) at which the thermistor's resistance is at its nominal value. </td></tr>
<tr><td class="paramname">nominal_resistance</td><td>The thermistor's resistance at the nominal temperature. </td></tr>
<tr><td class="paramname">series_resistance</td><td>The value of the other resistor in the voltage divider. </td></tr>
</table>
</dd>
</dl>
<dl class="section note"><dt>Note</dt><dd>Ported from Adafruit's MIT-licensed CircuitPython thermistor code, (c) 2017 Scott Shawcroft: <a href="https://github.com/adafruit/Adafruit_CircuitPython_Thermistor/blob/main/adafruit_thermistor.py">https://github.com/adafruit/Adafruit_CircuitPython_Thermistor/blob/main/adafruit_thermistor.py</a> </dd></dl>
</div>
</div>
</div><!-- contents -->
<!-- start footer part -->
<hr class="footer"/><address class="footer"><small>
Generated by&#160;<a href="https://www.doxygen.org/index.html"><img class="footer" src="doxygen.svg" width="104" height="31" alt="doxygen"/></a> 1.9.1
</small></address>
</body>
</html>