Heat index

by ClementGre
This commit is contained in:
MX 2023-06-25 00:38:26 +03:00
parent 34ff4c7dfa
commit 35f95336ed
No known key found for this signature in database
GPG Key ID: 7CCC66B7DBDD1C83
7 changed files with 109 additions and 11 deletions

View File

@ -624,11 +624,16 @@ UnitempStatus unitemp_sensor_updateData(Sensor* sensor) {
UNITEMP_DEBUG("Sensor %s update status %d", sensor->name, sensor->status);
}
if(app->settings.temp_unit == UT_TEMP_FAHRENHEIT && sensor->status == UT_SENSORSTATUS_OK) {
uintemp_celsiumToFarengate(sensor);
}
if(sensor->status == UT_SENSORSTATUS_OK) {
if(app->settings.heat_index &&
((sensor->type->datatype & (UT_TEMPERATURE | UT_HUMIDITY)) ==
(UT_TEMPERATURE | UT_HUMIDITY))) {
unitemp_calculate_heat_index(sensor);
}
if(app->settings.temp_unit == UT_TEMP_FAHRENHEIT) {
uintemp_celsiumToFarengate(sensor);
}
sensor->temp += sensor->temp_offset / 10.f;
if(app->settings.pressure_unit == UT_PRESSURE_MM_HG) {
unitemp_pascalToMmHg(sensor);

View File

@ -119,6 +119,7 @@ typedef struct Sensor {
char* name;
//Температура
float temp;
float heat_index;
//Относительная влажность
float hum;
//Атмосферное давление

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.2 KiB

View File

@ -28,8 +28,31 @@ Unitemp* app;
void uintemp_celsiumToFarengate(Sensor* sensor) {
sensor->temp = sensor->temp * (9.0 / 5.0) + 32;
sensor->heat_index = sensor->heat_index * (9.0 / 5.0) + 32;
}
static float heat_index_consts[9] = {
-42.379f,
2.04901523f,
10.14333127f,
-0.22475541f,
-0.00683783f,
-0.05481717f,
0.00122874f,
0.00085282f,
-0.00000199f};
void unitemp_calculate_heat_index(Sensor* sensor) {
// temp should be in Celsius, heat index will be in Celsius
float temp = sensor->temp * (9.0 / 5.0) + 32.0f;
float hum = sensor->hum;
sensor->heat_index =
(heat_index_consts[0] + heat_index_consts[1] * temp + heat_index_consts[2] * hum +
heat_index_consts[3] * temp * hum + heat_index_consts[4] * temp * temp +
heat_index_consts[5] * hum * hum + heat_index_consts[6] * temp * temp * hum +
heat_index_consts[7] * temp * hum * hum + heat_index_consts[8] * temp * temp * hum * hum -
32.0f) *
(5.0 / 9.0);
}
void unitemp_pascalToMmHg(Sensor* sensor) {
sensor->pressure = sensor->pressure * 0.007500638;
}
@ -71,6 +94,7 @@ bool unitemp_saveSettings(void) {
app->file_stream, "INFINITY_BACKLIGHT %d\n", app->settings.infinityBacklight);
stream_write_format(app->file_stream, "TEMP_UNIT %d\n", app->settings.temp_unit);
stream_write_format(app->file_stream, "PRESSURE_UNIT %d\n", app->settings.pressure_unit);
stream_write_format(app->file_stream, "HEAT_INDEX %d\n", app->settings.heat_index);
//Закрытие потока и освобождение памяти
file_stream_close(app->file_stream);
@ -166,6 +190,11 @@ bool unitemp_loadSettings(void) {
int p = 0;
sscanf(((char*)(file_buf + line_end)), "\nPRESSURE_UNIT %d", &p);
app->settings.pressure_unit = p;
} else if(!strcmp(buff, "HEAT_INDEX")) {
//Чтение значения параметра
int p = 0;
sscanf(((char*)(file_buf + line_end)), "\nHEAT_INDEX %d", &p);
app->settings.heat_index = p;
} else {
FURI_LOG_W(APP_NAME, "Unknown settings parameter: %s", buff);
}
@ -203,6 +232,7 @@ static bool unitemp_alloc(void) {
app->settings.infinityBacklight = true; //Подсветка горит всегда
app->settings.temp_unit = UT_TEMP_CELSIUS; //Единица измерения температуры - градусы Цельсия
app->settings.pressure_unit = UT_PRESSURE_MM_HG; //Единица измерения давления - мм рт. ст.
app->settings.heat_index = false;
app->gui = furi_record_open(RECORD_GUI);
//Диспетчер окон

View File

@ -40,7 +40,7 @@
//Имя приложения
#define APP_NAME "Unitemp"
//Версия приложения
#define UNITEMP_APP_VER "1.3"
#define UNITEMP_APP_VER "1.4"
//Путь хранения файлов плагина
#define APP_PATH_FOLDER "/ext/unitemp"
//Имя файла с настройками
@ -80,6 +80,8 @@ typedef struct {
tempMeasureUnit temp_unit;
//Единица измерения давления
pressureMeasureUnit pressure_unit;
// Do calculate and show heat index
bool heat_index;
//Последнее состояние OTG
bool lastOTGState;
} UnitempSettings;
@ -111,6 +113,13 @@ typedef struct {
/* Объявление прототипов функций */
/**
* @brief Calculates the heat index in Celsius from the temperature and humidity and stores it in the sensor heat_index field
*
* @param sensor The sensor struct, with temperature in Celcius and humidity in percent
*/
void unitemp_calculate_heat_index(Sensor* sensor);
/**
* @brief Перевод значения температуры датчика из Цельсия в Фаренгейты
*

View File

@ -113,6 +113,33 @@ static void _draw_humidity(Canvas* canvas, Sensor* sensor, const uint8_t pos[2])
canvas_draw_str(canvas, pos[0] + 27 + int_len / 2 + 4, pos[1] + 10 + 7, "%");
}
static void _draw_heat_index(Canvas* canvas, Sensor* sensor, const uint8_t pos[2]) {
canvas_draw_rframe(canvas, pos[0], pos[1], 54, 20, 3);
canvas_draw_rframe(canvas, pos[0], pos[1], 54, 19, 3);
canvas_draw_icon(canvas, pos[0] + 3, pos[1] + 3, &I_heat_index_11x14);
int16_t heat_index_int = sensor->heat_index;
int8_t heat_index_dec = abs((int16_t)(sensor->heat_index * 10) % 10);
snprintf(app->buff, BUFF_SIZE, "%d", heat_index_int);
canvas_set_font(canvas, FontBigNumbers);
canvas_draw_str_aligned(
canvas,
pos[0] + 27 + ((sensor->heat_index <= -10 || sensor->heat_index > 99) ? 5 : 0),
pos[1] + 10,
AlignCenter,
AlignCenter,
app->buff);
if(heat_index_int <= 99) {
uint8_t int_len = canvas_string_width(canvas, app->buff);
snprintf(app->buff, BUFF_SIZE, ".%d", heat_index_dec);
canvas_set_font(canvas, FontPrimary);
canvas_draw_str(canvas, pos[0] + 27 + int_len / 2 + 2, pos[1] + 10 + 7, app->buff);
}
}
static void _draw_pressure(Canvas* canvas, Sensor* sensor) {
const uint8_t x = 29, y = 39;
//Рисование рамки
@ -320,12 +347,23 @@ static void _draw_carousel_values(Canvas* canvas) {
ColorWhite);
break;
case UT_DATA_TYPE_TEMP_HUM:
_draw_temperature(
canvas,
unitemp_sensor_getActive(generalview_sensor_index),
temp_positions[1][0],
temp_positions[1][1],
ColorWhite);
if(!app->settings.heat_index) {
_draw_temperature(
canvas,
unitemp_sensor_getActive(generalview_sensor_index),
temp_positions[1][0],
temp_positions[1][1],
ColorWhite);
} else {
_draw_temperature(
canvas,
unitemp_sensor_getActive(generalview_sensor_index),
temp_positions[2][0],
temp_positions[2][1],
ColorWhite);
_draw_heat_index(
canvas, unitemp_sensor_getActive(generalview_sensor_index), hum_positions[1]);
}
_draw_humidity(
canvas, unitemp_sensor_getActive(generalview_sensor_index), hum_positions[0]);
break;

View File

@ -26,6 +26,7 @@ static VariableItemList* variable_item_list;
static const char states[2][9] = {"Auto", "Infinity"};
static const char temp_units[UT_TEMP_COUNT][3] = {"*C", "*F"};
static const char pressure_units[UT_PRESSURE_COUNT][6] = {"mm Hg", "in Hg", "kPa", "hPA"};
static const char heat_index_bool[2][4] = {"OFF", "ON"};
//Элемент списка - бесконечная подсветка
VariableItem* infinity_backlight_item;
@ -33,6 +34,8 @@ VariableItem* infinity_backlight_item;
VariableItem* temperature_unit_item;
//Единица измерения давления
VariableItem* pressure_unit_item;
VariableItem* heat_index_item;
#define VIEW_ID UnitempViewSettings
/**
@ -57,6 +60,7 @@ static uint32_t _exit_callback(void* context) {
(bool)variable_item_get_current_value_index(infinity_backlight_item);
app->settings.temp_unit = variable_item_get_current_value_index(temperature_unit_item);
app->settings.pressure_unit = variable_item_get_current_value_index(pressure_unit_item);
app->settings.heat_index = variable_item_get_current_value_index(heat_index_item);
unitemp_saveSettings();
unitemp_loadSettings();
@ -90,6 +94,11 @@ static void _setting_change_callback(VariableItem* item) {
pressure_unit_item,
pressure_units[variable_item_get_current_value_index(pressure_unit_item)]);
}
if(item == heat_index_item) {
variable_item_set_current_value_text(
heat_index_item,
heat_index_bool[variable_item_get_current_value_index(heat_index_item)]);
}
}
/**
@ -106,6 +115,8 @@ void unitemp_Settings_alloc(void) {
variable_item_list_add(variable_item_list, "Temp. unit", 2, _setting_change_callback, app);
pressure_unit_item = variable_item_list_add(
variable_item_list, "Press. unit", UT_PRESSURE_COUNT, _setting_change_callback, app);
heat_index_item = variable_item_list_add(
variable_item_list, "Calc. heat index", 2, _setting_change_callback, app);
//Добавление колбека на нажатие средней кнопки
variable_item_list_set_enter_callback(variable_item_list, _enter_callback, app);
@ -139,6 +150,10 @@ void unitemp_Settings_switch(void) {
pressure_unit_item,
pressure_units[variable_item_get_current_value_index(pressure_unit_item)]);
variable_item_set_current_value_index(heat_index_item, (uint8_t)app->settings.heat_index);
variable_item_set_current_value_text(
heat_index_item, heat_index_bool[variable_item_get_current_value_index(heat_index_item)]);
view_dispatcher_switch_to_view(app->view_dispatcher, VIEW_ID);
}