mirror of
https://github.com/portapack-mayhem/mayhem-firmware.git
synced 2026-09-10 08:39:29 +00:00
WIP, Weather refactor, UI improv
This commit is contained in:
@@ -35,11 +35,7 @@ void SubGhzDRecentEntryDetailView::update_data() {
|
||||
// set text elements
|
||||
text_type.set(SubGhzDView::getSensorTypeName((FPROTO_SUBGHZD_SENSOR)entry_.sensorType));
|
||||
text_id.set("0x" + to_string_hex(entry_.id));
|
||||
text_temp.set(to_string_decimal(entry_.temp, 2));
|
||||
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"));
|
||||
text_age.set(to_string_dec_uint(entry_.age) + " sec");
|
||||
// text_temp.set(to_string_decimal(entry_.temp, 2));
|
||||
}
|
||||
|
||||
SubGhzDRecentEntryDetailView::SubGhzDRecentEntryDetailView(NavigationView& nav, const SubGhzDRecentEntry& entry)
|
||||
@@ -49,10 +45,6 @@ SubGhzDRecentEntryDetailView::SubGhzDRecentEntryDetailView(NavigationView& nav,
|
||||
&text_type,
|
||||
&text_id,
|
||||
&text_temp,
|
||||
&text_hum,
|
||||
&text_ch,
|
||||
&text_batt,
|
||||
&text_age,
|
||||
&labels});
|
||||
|
||||
button_done.on_select = [&nav](const ui::Button&) {
|
||||
@@ -92,7 +84,7 @@ SubGhzDView::SubGhzDView(NavigationView& nav)
|
||||
recent_entries_view.on_select = [this](const SubGhzDRecentEntry& entry) {
|
||||
nav_.push<SubGhzDRecentEntryDetailView>(entry);
|
||||
};
|
||||
baseband::set_subghzd(0);
|
||||
baseband::set_subghzd(0); // am
|
||||
receiver_model.enable();
|
||||
signal_token_tick_second = rtc_time::signal_tick_second += [this]() {
|
||||
on_tick_second();
|
||||
@@ -107,7 +99,7 @@ void SubGhzDView::on_tick_second() {
|
||||
}
|
||||
|
||||
void SubGhzDView::on_data(const WeatherDataMessage* data) {
|
||||
SubGhzDRecentEntry key{data->sensorType, data->id, data->temp, data->humidity, data->channel, data->battery_low};
|
||||
SubGhzDRecentEntry key{data->sensorType, data->id};
|
||||
auto matching_recent = find(recent, key.key());
|
||||
if (matching_recent != std::end(recent)) {
|
||||
// Found within. Move to front of list, increment counter.
|
||||
@@ -129,6 +121,10 @@ SubGhzDView::~SubGhzDView() {
|
||||
|
||||
const char* SubGhzDView::getSensorTypeName(FPROTO_SUBGHZD_SENSOR type) {
|
||||
switch (type) {
|
||||
case FPS_ANSONIC:
|
||||
return "Ansonic";
|
||||
case FPS_PRINCETON:
|
||||
return "Princeton";
|
||||
case FPS_Invalid:
|
||||
default:
|
||||
return "Unknown";
|
||||
@@ -150,20 +146,19 @@ void RecentEntriesTable<ui::SubGhzDRecentEntries>::draw(
|
||||
line.reserve(30);
|
||||
|
||||
line = SubGhzDView::getSensorTypeName((FPROTO_SUBGHZD_SENSOR)entry.sensorType);
|
||||
if (line.length() < 10) {
|
||||
line += SubGhzDView::pad_string_with_spaces(10 - line.length());
|
||||
if (line.length() < 14) {
|
||||
line += SubGhzDView::pad_string_with_spaces(14 - line.length());
|
||||
} else {
|
||||
line = truncate(line, 10);
|
||||
line = truncate(line, 14);
|
||||
}
|
||||
// TODO
|
||||
|
||||
std::string temp = 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 idStr = to_string_hex(entry.id);
|
||||
std::string ageStr = to_string_dec_uint(entry.age);
|
||||
|
||||
line += SubGhzDView::pad_string_with_spaces(6 - temp.length()) + temp;
|
||||
line += SubGhzDView::pad_string_with_spaces(5 - humStr.length()) + humStr;
|
||||
line += SubGhzDView::pad_string_with_spaces(4 - chStr.length()) + chStr;
|
||||
// line += SubGhzDView::pad_string_with_spaces(6 - id.length()) + temp;
|
||||
// line += SubGhzDView::pad_string_with_spaces(5 - humStr.length()) + humStr;
|
||||
// line += SubGhzDView::pad_string_with_spaces(4 - chStr.length()) + chStr;
|
||||
line += SubGhzDView::pad_string_with_spaces(4 - ageStr.length()) + ageStr;
|
||||
|
||||
line.resize(target_rect.width() / 8, ' ');
|
||||
|
||||
@@ -43,33 +43,19 @@ struct SubGhzDRecentEntry {
|
||||
static constexpr Key invalid_key = 0x0fffffff; // todo calc the invalid all
|
||||
uint8_t sensorType = FPS_Invalid;
|
||||
uint32_t id = 0xFFFFFFFF;
|
||||
float temp = -273.0f;
|
||||
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
|
||||
|
||||
SubGhzDRecentEntry() {}
|
||||
SubGhzDRecentEntry(
|
||||
uint8_t sensorType,
|
||||
uint32_t id,
|
||||
float temp,
|
||||
uint8_t humidity,
|
||||
uint8_t channel,
|
||||
uint8_t battery_low = 0xff)
|
||||
uint32_t id)
|
||||
: sensorType{sensorType},
|
||||
id{id},
|
||||
temp{temp},
|
||||
humidity{humidity},
|
||||
battery_low{battery_low},
|
||||
channel{channel} {
|
||||
id{id} {
|
||||
}
|
||||
Key key() const {
|
||||
return (((static_cast<uint64_t>(temp * 10) & 0xFFFF) << 48) ^ static_cast<uint64_t>(id) << 24) |
|
||||
(static_cast<uint64_t>(sensorType) & 0xFF) << 16 |
|
||||
(static_cast<uint64_t>(humidity) & 0xFF) << 8 |
|
||||
(static_cast<uint64_t>(battery_low) & 0xF) << 4 |
|
||||
(static_cast<uint64_t>(channel) & 0xF);
|
||||
return (static_cast<uint64_t>(id) << 32) |
|
||||
(static_cast<uint64_t>(sensorType) & 0xFF) << 0;
|
||||
}
|
||||
void inc_age(int delta) {
|
||||
if (UINT16_MAX - delta > age) age += delta;
|
||||
@@ -156,20 +142,12 @@ class SubGhzDRecentEntryDetailView : public View {
|
||||
SubGhzDRecentEntry entry_{};
|
||||
Text text_type{{0 * 8, 1 * 16, 15 * 8, 16}, "?"};
|
||||
Text text_id{{6 * 8, 2 * 16, 10 * 8, 16}, "?"};
|
||||
Text text_temp{{6 * 8, 3 * 16, 8 * 8, 16}, "?"};
|
||||
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}, "?"};
|
||||
Text text_temp{{6 * 8, 3 * 16, 8 * 8, 7 * 16}, "?"};
|
||||
|
||||
Labels labels{
|
||||
{{0 * 8, 0 * 16}, "Station type:", Color::light_grey()},
|
||||
{{0 * 8, 0 * 16}, "Tpe:", Color::light_grey()},
|
||||
{{0 * 8, 2 * 16}, "Id: ", Color::light_grey()},
|
||||
{{0 * 8, 3 * 16}, "Temp:", Color::light_grey()},
|
||||
{{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()},
|
||||
{{0 * 8, 3 * 16}, "Data:", Color::light_grey()},
|
||||
};
|
||||
|
||||
Button button_done{
|
||||
|
||||
@@ -35,11 +35,26 @@ namespace ui {
|
||||
void WeatherRecentEntryDetailView::update_data() {
|
||||
// set text elements
|
||||
text_type.set(WeatherView::getWeatherSensorTypeName((FPROTO_WEATHER_SENSOR)entry_.sensorType));
|
||||
text_id.set("0x" + to_string_hex(entry_.id));
|
||||
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);
|
||||
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"));
|
||||
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("-");
|
||||
text_age.set(to_string_dec_uint(entry_.age) + " sec");
|
||||
}
|
||||
|
||||
@@ -204,8 +219,8 @@ void RecentEntriesTable<ui::WeatherRecentEntries>::draw(
|
||||
}
|
||||
|
||||
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 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) : "-";
|
||||
std::string ageStr = to_string_dec_uint(entry.age);
|
||||
|
||||
line += WeatherView::pad_string_with_spaces(6 - temp.length()) + temp;
|
||||
|
||||
@@ -43,11 +43,11 @@ struct WeatherRecentEntry {
|
||||
using Key = uint64_t;
|
||||
static constexpr Key invalid_key = 0x0fffffff; // todo calc the invalid all
|
||||
uint8_t sensorType = FPW_Invalid;
|
||||
uint32_t id = 0xFFFFFFFF;
|
||||
float temp = -273.0f;
|
||||
uint8_t humidity = 0xFF;
|
||||
uint8_t battery_low = 0xFF;
|
||||
uint8_t channel = 0xFF;
|
||||
uint32_t id = WS_NO_ID;
|
||||
float temp = WS_NO_TEMPERATURE;
|
||||
uint8_t humidity = WS_NO_HUMIDITY;
|
||||
uint8_t battery_low = WS_NO_BATT;
|
||||
uint8_t channel = WS_NO_CHANNEL;
|
||||
uint16_t age = 0; // updated on each seconds, show how long the signal was last seen
|
||||
|
||||
WeatherRecentEntry() {}
|
||||
@@ -57,7 +57,7 @@ struct WeatherRecentEntry {
|
||||
float temp,
|
||||
uint8_t humidity,
|
||||
uint8_t channel,
|
||||
uint8_t battery_low = 0xff)
|
||||
uint8_t battery_low = WS_NO_BATT)
|
||||
: sensorType{sensorType},
|
||||
id{id},
|
||||
temp{temp},
|
||||
|
||||
Reference in New Issue
Block a user