mirror of
https://github.com/eried/portapack-mayhem.git
synced 2025-08-01 19:16:29 -04:00
Weather improvements (#1615)
* Added Acurite986 protocol * Added signal age * Added myself to about screen
This commit is contained in:
parent
8846926b68
commit
cca0e18f5a
7 changed files with 201 additions and 21 deletions
|
@ -37,7 +37,7 @@ void AboutView::update() {
|
|||
break;
|
||||
case 2:
|
||||
console.writeln("NotherNgineer,zxkmm,u-foka");
|
||||
console.writeln("Netro");
|
||||
console.writeln("Netro,HTotoo");
|
||||
console.writeln("");
|
||||
break;
|
||||
|
||||
|
|
|
@ -40,12 +40,7 @@ void WeatherRecentEntryDetailView::update_data() {
|
|||
text_hum.set(to_string_dec_uint(entry_.humidity) + "%");
|
||||
text_ch.set(to_string_dec_uint(entry_.channel));
|
||||
text_batt.set(to_string_dec_uint(entry_.battery_low) + " " + ((entry_.battery_low == 0) ? "OK" : "LOW"));
|
||||
}
|
||||
|
||||
void WeatherRecentEntryDetailView::set_entry(const WeatherRecentEntry& entry) {
|
||||
entry_ = entry;
|
||||
update_data();
|
||||
set_dirty();
|
||||
text_age.set(to_string_dec_uint(entry_.age) + " sec");
|
||||
}
|
||||
|
||||
WeatherRecentEntryDetailView::WeatherRecentEntryDetailView(NavigationView& nav, const WeatherRecentEntry& entry)
|
||||
|
@ -58,6 +53,7 @@ WeatherRecentEntryDetailView::WeatherRecentEntryDetailView(NavigationView& nav,
|
|||
&text_hum,
|
||||
&text_ch,
|
||||
&text_batt,
|
||||
&text_age,
|
||||
&labels});
|
||||
|
||||
button_done.on_select = [&nav](const ui::Button&) {
|
||||
|
@ -106,6 +102,16 @@ WeatherView::WeatherView(NavigationView& nav)
|
|||
};
|
||||
baseband::set_weather();
|
||||
receiver_model.enable();
|
||||
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();
|
||||
}
|
||||
|
||||
void WeatherView::on_data(const WeatherDataMessage* data) {
|
||||
|
@ -113,6 +119,7 @@ void WeatherView::on_data(const WeatherDataMessage* data) {
|
|||
auto matching_recent = find(recent, key.key());
|
||||
if (matching_recent != std::end(recent)) {
|
||||
// Found within. Move to front of list, increment counter.
|
||||
(*matching_recent).reset_age();
|
||||
recent.push_front(*matching_recent);
|
||||
recent.erase(matching_recent);
|
||||
} else {
|
||||
|
@ -123,6 +130,7 @@ void WeatherView::on_data(const WeatherDataMessage* data) {
|
|||
}
|
||||
|
||||
WeatherView::~WeatherView() {
|
||||
rtc_time::signal_tick_second -= signal_token_tick_second;
|
||||
receiver_model.disable();
|
||||
baseband::shutdown();
|
||||
}
|
||||
|
@ -165,6 +173,8 @@ const char* WeatherView::getWeatherSensorTypeName(FPROTO_WEATHER_SENSOR type) {
|
|||
return "TX 8300";
|
||||
case FPW_WENDOX_W6726:
|
||||
return "Wendox W6726";
|
||||
case FPW_Acurite986:
|
||||
return "Acurite986";
|
||||
|
||||
case FPW_Invalid:
|
||||
default:
|
||||
|
@ -187,19 +197,21 @@ void RecentEntriesTable<ui::WeatherRecentEntries>::draw(
|
|||
line.reserve(30);
|
||||
|
||||
line = WeatherView::getWeatherSensorTypeName((FPROTO_WEATHER_SENSOR)entry.sensorType);
|
||||
if (line.length() < 13) {
|
||||
line += WeatherView::pad_string_with_spaces(13 - line.length());
|
||||
if (line.length() < 10) {
|
||||
line += WeatherView::pad_string_with_spaces(10 - line.length());
|
||||
} else {
|
||||
line = truncate(line, 13);
|
||||
line = truncate(line, 10);
|
||||
}
|
||||
|
||||
std::string temp = (weather_units_fahr ? to_string_decimal((entry.temp * 9 / 5) + 32, 1) : to_string_decimal(entry.temp, 2));
|
||||
std::string temp = (weather_units_fahr ? to_string_decimal((entry.temp * 9 / 5) + 32, 1) : to_string_decimal(entry.temp, 1));
|
||||
std::string humStr = to_string_dec_uint(entry.humidity) + "%";
|
||||
std::string chStr = to_string_dec_uint(entry.channel);
|
||||
std::string ageStr = to_string_dec_uint(entry.age);
|
||||
|
||||
line += WeatherView::pad_string_with_spaces(7 - temp.length()) + temp;
|
||||
line += WeatherView::pad_string_with_spaces(6 - temp.length()) + temp;
|
||||
line += WeatherView::pad_string_with_spaces(5 - humStr.length()) + humStr;
|
||||
line += WeatherView::pad_string_with_spaces(4 - chStr.length()) + chStr;
|
||||
line += WeatherView::pad_string_with_spaces(4 - ageStr.length()) + ageStr;
|
||||
|
||||
line.resize(target_rect.width() / 8, ' ');
|
||||
painter.draw_string(target_rect.location(), style, line);
|
||||
|
|
|
@ -48,6 +48,7 @@ struct WeatherRecentEntry {
|
|||
uint8_t humidity = 0xFF;
|
||||
uint8_t battery_low = 0xFF;
|
||||
uint8_t channel = 0xFF;
|
||||
uint16_t age = 0; // updated on each seconds, show how long the signal was last seen
|
||||
|
||||
WeatherRecentEntry() {}
|
||||
WeatherRecentEntry(
|
||||
|
@ -71,6 +72,12 @@ struct WeatherRecentEntry {
|
|||
(static_cast<uint64_t>(battery_low) & 0xF) << 4 |
|
||||
(static_cast<uint64_t>(channel) & 0xF);
|
||||
}
|
||||
void inc_age(int delta) {
|
||||
if (UINT16_MAX - delta > age) age += delta;
|
||||
}
|
||||
void reset_age() {
|
||||
age = 0;
|
||||
}
|
||||
};
|
||||
using WeatherRecentEntries = RecentEntries<WeatherRecentEntry>;
|
||||
using WeatherRecentEntriesView = RecentEntriesView<WeatherRecentEntries>;
|
||||
|
@ -87,6 +94,7 @@ class WeatherView : public View {
|
|||
static std::string pad_string_with_spaces(int snakes);
|
||||
|
||||
private:
|
||||
void on_tick_second();
|
||||
void on_data(const WeatherDataMessage* data);
|
||||
|
||||
NavigationView& nav_;
|
||||
|
@ -122,6 +130,8 @@ class WeatherView : public View {
|
|||
{0 * 8, 0 * 16},
|
||||
nav_};
|
||||
|
||||
SignalToken signal_token_tick_second{};
|
||||
|
||||
Button button_clear_list{
|
||||
{0, 16, 7 * 8, 32},
|
||||
"Clear"};
|
||||
|
@ -129,11 +139,11 @@ class WeatherView : public View {
|
|||
static constexpr auto header_height = 3 * 16;
|
||||
|
||||
const RecentEntriesColumns columns{{
|
||||
{"Type", 13},
|
||||
{"Temp", 6},
|
||||
{"Type", 10},
|
||||
{"Temp", 5},
|
||||
{"Hum", 4},
|
||||
{"Ch", 3},
|
||||
|
||||
{"Age", 3},
|
||||
}};
|
||||
WeatherRecentEntriesView recent_entries_view{columns, recent};
|
||||
|
||||
|
@ -149,9 +159,6 @@ class WeatherRecentEntryDetailView : public View {
|
|||
public:
|
||||
WeatherRecentEntryDetailView(NavigationView& nav, const WeatherRecentEntry& entry);
|
||||
|
||||
void set_entry(const WeatherRecentEntry& new_entry);
|
||||
const WeatherRecentEntry& entry() const { return entry_; };
|
||||
|
||||
void update_data();
|
||||
void focus() override;
|
||||
|
||||
|
@ -164,6 +171,7 @@ class WeatherRecentEntryDetailView : public View {
|
|||
Text text_hum{{11 * 8, 4 * 16, 6 * 8, 16}, "?"};
|
||||
Text text_ch{{11 * 8, 5 * 16, 6 * 8, 16}, "?"};
|
||||
Text text_batt{{11 * 8, 6 * 16, 6 * 8, 16}, "?"};
|
||||
Text text_age{{11 * 8, 7 * 16, 6 * 8, 16}, "?"};
|
||||
|
||||
Labels labels{
|
||||
{{0 * 8, 0 * 16}, "Weather station type:", Color::light_grey()},
|
||||
|
@ -172,6 +180,7 @@ class WeatherRecentEntryDetailView : public View {
|
|||
{{0 * 8, 4 * 16}, "Humidity:", Color::light_grey()},
|
||||
{{0 * 8, 5 * 16}, "Channel:", Color::light_grey()},
|
||||
{{0 * 8, 6 * 16}, "Battery:", Color::light_grey()},
|
||||
{{0 * 8, 7 * 16}, "Age:", Color::light_grey()},
|
||||
};
|
||||
|
||||
Button button_done{
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue