2023-11-28 15:11:30 -05:00
|
|
|
/*
|
|
|
|
* Copyright (C) 2014 Jared Boone, ShareBrained Technology, Inc.
|
|
|
|
* Copyright (C) 2017 Furrtek
|
|
|
|
*
|
|
|
|
* This file is part of PortaPack.
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation; either version 2, or (at your option)
|
|
|
|
* any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program; see the file COPYING. If not, write to
|
|
|
|
* the Free Software Foundation, Inc., 51 Franklin Street,
|
|
|
|
* Boston, MA 02110-1301, USA.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "ui_weatherstation.hpp"
|
|
|
|
#include "modems.hpp"
|
|
|
|
#include "audio.hpp"
|
|
|
|
#include "baseband_api.hpp"
|
|
|
|
#include "string_format.hpp"
|
|
|
|
#include "portapack_persistent_memory.hpp"
|
|
|
|
|
|
|
|
using namespace portapack;
|
|
|
|
using namespace ui;
|
|
|
|
|
|
|
|
namespace ui {
|
|
|
|
|
|
|
|
void WeatherRecentEntryDetailView::update_data() {
|
|
|
|
// set text elements
|
|
|
|
text_type.set(WeatherView::getWeatherSensorTypeName((FPROTO_WEATHER_SENSOR)entry_.sensorType));
|
Subghz decoder (#1646)
* Initial commit - wip
* Half part of the transition of baseband processor.
* More SGD
* WIP, Weather refactor, UI improv
* Rename
* Added 4msps, and fixes
* Fixes
* princeton working
* Renamed proc_weather, bc now multifunctional
* Proto: bett
* FPS_CAME = 4,
FPS_PRASTEL = 5,
FPS_AIRFORCE = 6,
* Came Atomo, fixes
* Separate weather and sgd, bc of baseband size limit
* Fix display
* Save space
* More protos
* Dooya proto added
* More protos
* add protos
* More protos
* Move weather to ext app
* nw
* Revert "Move weather to ext app"
This reverts commit 8a84aac2f59274b72de7c7803deb137a21838076.
* revert
* Fix merge
* Better naming
* More protos
* More protos
* Add protos
* Fix warning
* Add NeroRadio
* more protos
* more protos
* More protos
* Shrink a bit
* fixes
* More protos
* Nicer code
* Fix naming
* Fix format
* Remove unused
* Fix some protos, that needs a LOOOONG part with the same lo/high
* Modify key calculation
2023-12-16 17:37:51 -05:00
|
|
|
if (entry_.id != WS_NO_ID)
|
|
|
|
text_id.set("0x" + to_string_hex(entry_.id));
|
|
|
|
else
|
|
|
|
text_id.set("-");
|
|
|
|
if (entry_.temp != WS_NO_TEMPERATURE)
|
|
|
|
text_temp.set(weather_units_fahr ? to_string_decimal((entry_.temp * 9 / 5) + 32, 1) + STR_DEGREES_F : to_string_decimal(entry_.temp, 2) + STR_DEGREES_C);
|
|
|
|
else
|
|
|
|
text_temp.set("-");
|
|
|
|
if (entry_.humidity != WS_NO_HUMIDITY)
|
|
|
|
text_hum.set(to_string_dec_uint(entry_.humidity) + "%");
|
|
|
|
else
|
|
|
|
text_hum.set("-");
|
|
|
|
if (entry_.channel != WS_NO_CHANNEL)
|
|
|
|
text_ch.set(to_string_dec_uint(entry_.channel));
|
|
|
|
else
|
|
|
|
text_ch.set("-");
|
|
|
|
if (entry_.battery_low != WS_NO_BATT)
|
|
|
|
text_batt.set(to_string_dec_uint(entry_.battery_low) + " " + ((entry_.battery_low == 0) ? "OK" : "LOW"));
|
|
|
|
else
|
|
|
|
text_batt.set("-");
|
2023-11-30 06:36:59 -05:00
|
|
|
text_age.set(to_string_dec_uint(entry_.age) + " sec");
|
2023-11-28 15:11:30 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
WeatherRecentEntryDetailView::WeatherRecentEntryDetailView(NavigationView& nav, const WeatherRecentEntry& entry)
|
|
|
|
: nav_{nav},
|
|
|
|
entry_{entry} {
|
|
|
|
add_children({&button_done,
|
|
|
|
&text_type,
|
|
|
|
&text_id,
|
|
|
|
&text_temp,
|
|
|
|
&text_hum,
|
|
|
|
&text_ch,
|
|
|
|
&text_batt,
|
2023-11-30 06:36:59 -05:00
|
|
|
&text_age,
|
2023-11-28 15:11:30 -05:00
|
|
|
&labels});
|
|
|
|
|
|
|
|
button_done.on_select = [&nav](const ui::Button&) {
|
|
|
|
nav.pop();
|
|
|
|
};
|
|
|
|
update_data();
|
|
|
|
}
|
|
|
|
|
|
|
|
void WeatherRecentEntryDetailView::focus() {
|
|
|
|
button_done.focus();
|
|
|
|
}
|
|
|
|
|
|
|
|
void WeatherView::focus() {
|
|
|
|
field_frequency.focus();
|
|
|
|
}
|
|
|
|
|
|
|
|
WeatherView::WeatherView(NavigationView& nav)
|
|
|
|
: nav_{nav} {
|
|
|
|
add_children({&rssi,
|
|
|
|
&field_rf_amp,
|
|
|
|
&field_lna,
|
|
|
|
&field_vga,
|
|
|
|
&field_frequency,
|
2023-11-29 11:37:01 -05:00
|
|
|
&options_temperature,
|
2023-11-28 15:11:30 -05:00
|
|
|
&button_clear_list,
|
|
|
|
&recent_entries_view});
|
|
|
|
|
|
|
|
baseband::run_image(portapack::spi_flash::image_tag_weather);
|
|
|
|
|
|
|
|
button_clear_list.on_select = [this](Button&) {
|
|
|
|
recent.clear();
|
|
|
|
recent_entries_view.set_dirty();
|
|
|
|
};
|
2023-11-29 11:37:01 -05:00
|
|
|
field_frequency.set_step(100000);
|
|
|
|
|
|
|
|
options_temperature.on_change = [this](size_t, int32_t i) {
|
|
|
|
weather_units_fahr = (bool)i;
|
|
|
|
recent_entries_view.set_dirty();
|
|
|
|
};
|
|
|
|
options_temperature.set_selected_index(weather_units_fahr, false);
|
|
|
|
|
2023-11-28 15:11:30 -05:00
|
|
|
const Rect content_rect{0, header_height, screen_width, screen_height - header_height};
|
|
|
|
recent_entries_view.set_parent_rect(content_rect);
|
|
|
|
recent_entries_view.on_select = [this](const WeatherRecentEntry& entry) {
|
|
|
|
nav_.push<WeatherRecentEntryDetailView>(entry);
|
|
|
|
};
|
2023-12-21 13:33:06 -05:00
|
|
|
baseband::set_subghzd_config(0, receiver_model.sampling_rate()); // 0=am
|
2023-11-28 15:11:30 -05:00
|
|
|
receiver_model.enable();
|
2023-11-30 06:36:59 -05:00
|
|
|
signal_token_tick_second = rtc_time::signal_tick_second += [this]() {
|
|
|
|
on_tick_second();
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
void WeatherView::on_tick_second() {
|
|
|
|
for (auto& entry : recent) {
|
|
|
|
entry.inc_age(1);
|
|
|
|
}
|
|
|
|
recent_entries_view.set_dirty();
|
2023-11-28 15:11:30 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
void WeatherView::on_data(const WeatherDataMessage* data) {
|
|
|
|
WeatherRecentEntry key{data->sensorType, data->id, data->temp, data->humidity, data->channel, data->battery_low};
|
|
|
|
auto matching_recent = find(recent, key.key());
|
|
|
|
if (matching_recent != std::end(recent)) {
|
|
|
|
// Found within. Move to front of list, increment counter.
|
2023-11-30 06:36:59 -05:00
|
|
|
(*matching_recent).reset_age();
|
2023-11-28 15:11:30 -05:00
|
|
|
recent.push_front(*matching_recent);
|
|
|
|
recent.erase(matching_recent);
|
|
|
|
} else {
|
|
|
|
recent.emplace_front(key);
|
|
|
|
truncate_entries(recent, 64);
|
|
|
|
}
|
|
|
|
recent_entries_view.set_dirty();
|
|
|
|
}
|
|
|
|
|
|
|
|
WeatherView::~WeatherView() {
|
2023-11-30 06:36:59 -05:00
|
|
|
rtc_time::signal_tick_second -= signal_token_tick_second;
|
2023-11-28 15:11:30 -05:00
|
|
|
receiver_model.disable();
|
|
|
|
baseband::shutdown();
|
|
|
|
}
|
|
|
|
|
|
|
|
const char* WeatherView::getWeatherSensorTypeName(FPROTO_WEATHER_SENSOR type) {
|
|
|
|
switch (type) {
|
|
|
|
case FPW_NexusTH:
|
|
|
|
return "NexusTH";
|
|
|
|
case FPW_Acurite592TXR:
|
|
|
|
return "Acurite592TXR";
|
|
|
|
case FPW_Acurite606TX:
|
|
|
|
return "Acurite606TX";
|
|
|
|
case FPW_Acurite609TX:
|
|
|
|
return "Acurite609TX";
|
|
|
|
case FPW_Ambient:
|
|
|
|
return "Ambient";
|
|
|
|
case FPW_AuriolAhfl:
|
|
|
|
return "AuriolAhfl";
|
|
|
|
case FPW_AuriolTH:
|
|
|
|
return "AuriolTH";
|
|
|
|
case FPW_GTWT02:
|
|
|
|
return "GT-WT02";
|
|
|
|
case FPW_GTWT03:
|
|
|
|
return "GT-WT03";
|
|
|
|
case FPW_INFACTORY:
|
|
|
|
return "InFactory";
|
|
|
|
case FPW_LACROSSETX:
|
|
|
|
return "LaCrosse TX";
|
|
|
|
case FPW_LACROSSETX141thbv2:
|
|
|
|
return "LaCrosse TX141THBv2";
|
|
|
|
case FPW_OREGON2:
|
|
|
|
return "Oregon2";
|
|
|
|
case FPW_OREGON3:
|
|
|
|
return "Oregon3";
|
|
|
|
case FPW_OREGONv1:
|
|
|
|
return "OregonV1";
|
|
|
|
case FPW_THERMOPROTX4:
|
|
|
|
return "ThermoPro TX4";
|
|
|
|
case FPW_TX_8300:
|
|
|
|
return "TX 8300";
|
|
|
|
case FPW_WENDOX_W6726:
|
|
|
|
return "Wendox W6726";
|
2023-11-30 06:36:59 -05:00
|
|
|
case FPW_Acurite986:
|
|
|
|
return "Acurite986";
|
2023-11-28 15:11:30 -05:00
|
|
|
|
|
|
|
case FPW_Invalid:
|
|
|
|
default:
|
|
|
|
return "Unknown";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
std::string WeatherView::pad_string_with_spaces(int snakes) {
|
|
|
|
std::string paddedStr(snakes, ' ');
|
|
|
|
return paddedStr;
|
|
|
|
}
|
|
|
|
|
|
|
|
template <>
|
|
|
|
void RecentEntriesTable<ui::WeatherRecentEntries>::draw(
|
|
|
|
const Entry& entry,
|
|
|
|
const Rect& target_rect,
|
|
|
|
Painter& painter,
|
|
|
|
const Style& style) {
|
|
|
|
std::string line{};
|
|
|
|
line.reserve(30);
|
|
|
|
|
|
|
|
line = WeatherView::getWeatherSensorTypeName((FPROTO_WEATHER_SENSOR)entry.sensorType);
|
2023-11-30 06:36:59 -05:00
|
|
|
if (line.length() < 10) {
|
|
|
|
line += WeatherView::pad_string_with_spaces(10 - line.length());
|
2023-11-28 15:11:30 -05:00
|
|
|
} else {
|
2023-11-30 06:36:59 -05:00
|
|
|
line = truncate(line, 10);
|
2023-11-28 15:11:30 -05:00
|
|
|
}
|
|
|
|
|
2023-11-30 06:36:59 -05:00
|
|
|
std::string temp = (weather_units_fahr ? to_string_decimal((entry.temp * 9 / 5) + 32, 1) : to_string_decimal(entry.temp, 1));
|
Subghz decoder (#1646)
* Initial commit - wip
* Half part of the transition of baseband processor.
* More SGD
* WIP, Weather refactor, UI improv
* Rename
* Added 4msps, and fixes
* Fixes
* princeton working
* Renamed proc_weather, bc now multifunctional
* Proto: bett
* FPS_CAME = 4,
FPS_PRASTEL = 5,
FPS_AIRFORCE = 6,
* Came Atomo, fixes
* Separate weather and sgd, bc of baseband size limit
* Fix display
* Save space
* More protos
* Dooya proto added
* More protos
* add protos
* More protos
* Move weather to ext app
* nw
* Revert "Move weather to ext app"
This reverts commit 8a84aac2f59274b72de7c7803deb137a21838076.
* revert
* Fix merge
* Better naming
* More protos
* More protos
* Add protos
* Fix warning
* Add NeroRadio
* more protos
* more protos
* More protos
* Shrink a bit
* fixes
* More protos
* Nicer code
* Fix naming
* Fix format
* Remove unused
* Fix some protos, that needs a LOOOONG part with the same lo/high
* Modify key calculation
2023-12-16 17:37:51 -05:00
|
|
|
std::string humStr = (entry.humidity != WS_NO_HUMIDITY) ? to_string_dec_uint(entry.humidity) + "%" : "-";
|
|
|
|
std::string chStr = (entry.channel != WS_NO_CHANNEL) ? to_string_dec_uint(entry.channel) : "-";
|
2023-11-30 06:36:59 -05:00
|
|
|
std::string ageStr = to_string_dec_uint(entry.age);
|
2023-11-28 15:11:30 -05:00
|
|
|
|
2023-11-30 06:36:59 -05:00
|
|
|
line += WeatherView::pad_string_with_spaces(6 - temp.length()) + temp;
|
2023-11-28 15:11:30 -05:00
|
|
|
line += WeatherView::pad_string_with_spaces(5 - humStr.length()) + humStr;
|
|
|
|
line += WeatherView::pad_string_with_spaces(4 - chStr.length()) + chStr;
|
2023-12-10 11:57:21 -05:00
|
|
|
line += WeatherView::pad_string_with_spaces(5 - ageStr.length()) + ageStr;
|
2023-11-28 15:11:30 -05:00
|
|
|
|
|
|
|
line.resize(target_rect.width() / 8, ' ');
|
|
|
|
painter.draw_string(target_rect.location(), style, line);
|
|
|
|
}
|
|
|
|
|
2023-12-21 13:33:06 -05:00
|
|
|
} // namespace ui
|