Loading...
Searching...
No Matches
weather_reading.c File Reference

Turns one weather message into the reading a store keeps. More...

#include "weather/weather_reading.h"
#include <limits.h>
#include "math/scale.h"
#include "text/cstring_fit.h"

Macros

#define SECONDS_PER_READING_HOUR   3600
 Seconds in an hour, for placing a strip's first column.
#define SECONDS_PER_READING_DAY   86400
 Seconds in a day, for placing a strip's first day.
#define MINUTES_PER_READING_DAY   1440
 Minutes in a day, the range a sunrise or sunset is held to.
#define TEMP_LOWEST   (-99)
 The lowest temperature kept, the most a three digit label shows below zero.
#define TEMP_HIGHEST   199
 The highest temperature kept, the most a three digit label shows.

Functions

static int or_none (int value, int none)
static int temp_or_none (int value)
static int16_t day_minute_or_none (int value)
bool weather_reading_apply (WeatherState *state, const WeatherMessage *msg, const WeatherClock *clock)
 Put a message's readings into the kept weather.
static int div_nearest (int numerator, int denominator)
static int convert_temp (int value, bool to_fahrenheit)
void weather_reading_convert (WeatherState *state, bool to_fahrenheit)
 Convert every temperature in the kept weather to the other unit.

Detailed Description

Turns one weather message into the reading a store keeps.

Function Documentation

◆ convert_temp()

int convert_temp ( int value,
bool to_fahrenheit )
static

One temperature in the other unit, or no data left as it is.

◆ day_minute_or_none()

int16_t day_minute_or_none ( int value)
static

A time of day in minutes, or -1 for one the message left out or one no clock can read.

◆ div_nearest()

int div_nearest ( int numerator,
int denominator )
static

Divides to the nearest whole number. Neither a fifth nor a ninth lands on a half, so nothing ties.

◆ or_none()

int or_none ( int value,
int none )
static

A number the message left out, as the store's own no-data value.

◆ temp_or_none()

int temp_or_none ( int value)
static

A temperature held to TEMP_LOWEST to TEMP_HIGHEST, so a wild one cannot run past a three digit label or overflow the current temperature's int16, or no data for one the message left out. The store's own no-data value counts as left out too, since clamping it would turn it into a real -99.

Parameters
valueThe temperature from the message, or INT_MIN when it left one out.
Returns
The temperature held to the range, or WEATHER_NO_TEMP.