Skip to content

Commit

Permalink
feat(color): add color options for radio info widget battery level in…
Browse files Browse the repository at this point in the history
…dicator (#4845)
  • Loading branch information
philmoz authored May 5, 2024
1 parent 117fe18 commit dd9a620
Show file tree
Hide file tree
Showing 21 changed files with 158 additions and 19 deletions.
51 changes: 37 additions & 14 deletions radio/src/gui/colorlcd/widgets/radio_info.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -85,13 +85,8 @@ class RadioInfoWidget : public TopBarWidget
batteryFill = lv_obj_create(lvobj);
lv_obj_set_pos(batteryFill, W_AUDIO_X + 1, 26);
lv_obj_set_size(batteryFill, 20, 9);
lv_obj_set_style_bg_color(batteryFill, lv_palette_main(LV_PALETTE_GREEN),
LV_PART_MAIN);
lv_obj_set_style_bg_color(batteryFill, lv_palette_main(LV_PALETTE_AMBER),
LV_PART_MAIN | LV_STATE_USER_1);
lv_obj_set_style_bg_color(batteryFill, lv_palette_main(LV_PALETTE_RED),
LV_PART_MAIN | LV_STATE_USER_2);
lv_obj_set_style_bg_opa(batteryFill, LV_OPA_COVER, LV_PART_MAIN);
update();

// RSSI bars
const uint8_t rssiBarsHeight[] = {5, 10, 15, 21, 31};
Expand All @@ -107,6 +102,21 @@ class RadioInfoWidget : public TopBarWidget
checkEvents();
}

void update() override
{
lv_color_t color;

// get colors from options
color.full = persistentData->options[2].value.unsignedValue;
lv_obj_set_style_bg_color(batteryFill, color, LV_PART_MAIN);

color.full = persistentData->options[1].value.unsignedValue;
lv_obj_set_style_bg_color(batteryFill, color, LV_PART_MAIN | LV_STATE_USER_1);

color.full = persistentData->options[0].value.unsignedValue;
lv_obj_set_style_bg_color(batteryFill, color, LV_PART_MAIN | LV_STATE_USER_2);
}

void checkEvents() override
{
TopBarWidget::checkEvents();
Expand Down Expand Up @@ -175,6 +185,8 @@ class RadioInfoWidget : public TopBarWidget
}
}

static const ZoneOption options[];

protected:
uint8_t lastVol = 0;
uint8_t lastBatt = 0;
Expand All @@ -194,8 +206,14 @@ class RadioInfoWidget : public TopBarWidget
#endif
};

BaseWidgetFactory<RadioInfoWidget> RadioInfoWidget("Radio Info", nullptr,
"Radio Info");
const ZoneOption RadioInfoWidget::options[] = {
{STR_LOW_BATT_COLOR, ZoneOption::Color, RGB(0xF4, 0x43, 0x36)},
{STR_MID_BATT_COLOR, ZoneOption::Color, RGB(0xFF, 0xC1, 0x07)},
{STR_HIGH_BATT_COLOR, ZoneOption::Color, RGB(0x4C, 0xAF, 0x50)},
{nullptr, ZoneOption::Bool}};

BaseWidgetFactory<RadioInfoWidget> RadioInfoWidget("Radio Info", RadioInfoWidget::options,
STR_RADIO_INFO_WIDGET);

// Adjustment to make main view date/time align with model/radio settings views
#if LCD_W > LCD_H
Expand All @@ -212,6 +230,7 @@ class DateTimeWidget : public TopBarWidget
TopBarWidget(factory, parent, rect, persistentData)
{
dateTime = new HeaderDateTime(lvobj, DT_OFFSET, 3);
update();
}

void checkEvents() override
Expand All @@ -224,13 +243,17 @@ class DateTimeWidget : public TopBarWidget
if (t.tm_min != lastMinute) {
lastMinute = t.tm_min;
dateTime->update();
// get color from options
LcdFlags color =
COLOR2FLAGS(persistentData->options[0].value.unsignedValue);
dateTime->setColor(color);
}
}

void update() override
{
// get color from options
LcdFlags color =
COLOR2FLAGS(persistentData->options[0].value.unsignedValue);
dateTime->setColor(color);
}

HeaderDateTime* dateTime = nullptr;
int8_t lastMinute = -1;

Expand All @@ -244,7 +267,7 @@ const ZoneOption DateTimeWidget::options[] = {

BaseWidgetFactory<DateTimeWidget> DateTimeWidget("Date Time",
DateTimeWidget::options,
"Date Time");
STR_DATE_TIME_WIDGET);

#if defined(INTERNAL_GPS)

Expand Down Expand Up @@ -285,6 +308,6 @@ class InternalGPSWidget : public TopBarWidget
};

BaseWidgetFactory<InternalGPSWidget> InternalGPSWidget("Internal GPS", nullptr,
"Internal GPS");
STR_INT_GPS_LABEL);

#endif
6 changes: 6 additions & 0 deletions radio/src/translations.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1095,6 +1095,12 @@ ISTR(SORT_ORDERS);
const char STR_SORT_MODELS_BY[] = TR_SORT_MODELS_BY;
const char STR_CREATE_NEW[] = TR_CREATE_NEW;
const char STR_THEME_EXISTS[] = TR_THEME_EXISTS;

const char STR_DATE_TIME_WIDGET[] = TR_DATE_TIME_WIDGET;
const char STR_RADIO_INFO_WIDGET[] = TR_RADIO_INFO_WIDGET;
const char STR_LOW_BATT_COLOR[] = TR_LOW_BATT_COLOR;
const char STR_MID_BATT_COLOR[] = TR_MID_BATT_COLOR;
const char STR_HIGH_BATT_COLOR[] = TR_HIGH_BATT_COLOR;
#endif

const char STR_MIX_SLOW_PREC[] = TR_MIX_SLOW_PREC;
12 changes: 7 additions & 5 deletions radio/src/translations.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,7 @@
* GNU General Public License for more details.
*/

#ifndef _TRANSLATIONS_H_
#define _TRANSLATIONS_H_
#pragma once

#include <limits.h>
#include "opentx_types.h"
Expand Down Expand Up @@ -1286,9 +1285,12 @@ extern const char* const STR_SORT_ORDERS[];
extern const char STR_SORT_MODELS_BY[];
extern const char STR_CREATE_NEW[];
extern const char STR_THEME_EXISTS[];

extern const char STR_DATE_TIME_WIDGET[];
extern const char STR_RADIO_INFO_WIDGET[];
extern const char STR_LOW_BATT_COLOR[];
extern const char STR_MID_BATT_COLOR[];
extern const char STR_HIGH_BATT_COLOR[];
#endif

extern const char STR_MIX_SLOW_PREC[];

#endif // _TRANSLATIONS_H_

6 changes: 6 additions & 0 deletions radio/src/translations/cn.h
Original file line number Diff line number Diff line change
Expand Up @@ -1287,3 +1287,9 @@
#define TR_THEME_EXISTS "已存在同名主题目录 !"

#define ROTORFLIGHT_LUA_CH "按败板半保备闭标表并波补不菜参叉差偿超车持池出存打大带待怠单到等低地点电调定动度舵二翻方放飞副复负高跟关管航号何合后护环缓回混火或机积集几计加间减件降交角教接阶截进救距开控宽馈拉来累类连练量零灵率滤螺落门面敏模目逆爬盘偏频平其启器前曲取确然入刹上设身升失时使式释试数衰水瞬顺速缩他态体停通退陀微尾位文稳误息熄下陷限线相响向消小校斜新心信型行悬旋循压页一移仪益翼因应用油右预援源载增针正直值止置制中重轴主转准子自踪总最左耦"

#define TR_DATE_TIME_WIDGET "日期和时间"
#define TR_RADIO_INFO_WIDGET "遥控器信息"
#define TR_LOW_BATT_COLOR "低电量"
#define TR_MID_BATT_COLOR "中电量"
#define TR_HIGH_BATT_COLOR "高电量"
6 changes: 6 additions & 0 deletions radio/src/translations/cz.h
Original file line number Diff line number Diff line change
Expand Up @@ -1300,3 +1300,9 @@
#define TR_MIX_SLOW_PREC TR("Přesnost zpomal", "Přesnost zpomalení")

#define TR_THEME_EXISTS "Adresář vzhledu s tímto názvem již existuje."

#define TR_DATE_TIME_WIDGET "Datum a čas"
#define TR_RADIO_INFO_WIDGET "Informace o vysílačce"
#define TR_LOW_BATT_COLOR "Vybitá baterie"
#define TR_MID_BATT_COLOR "Středně nabitá baterie"
#define TR_HIGH_BATT_COLOR "Plně nabitá baterie"
6 changes: 6 additions & 0 deletions radio/src/translations/da.h
Original file line number Diff line number Diff line change
Expand Up @@ -1300,3 +1300,9 @@
#define TR_MIX_SLOW_PREC TR("Træg præc", "Træg op/ned præcision")

#define TR_THEME_EXISTS "Der findes allerede et katalog med samme navn."

#define TR_DATE_TIME_WIDGET "Dato & Klokke"
#define TR_RADIO_INFO_WIDGET "Radio info"
#define TR_LOW_BATT_COLOR "Batteri lavt"
#define TR_MID_BATT_COLOR "Batteri medio"
#define TR_HIGH_BATT_COLOR "Batteri højt"
6 changes: 6 additions & 0 deletions radio/src/translations/de.h
Original file line number Diff line number Diff line change
Expand Up @@ -1296,3 +1296,9 @@
#define TR_MIX_SLOW_PREC TR("Langs. Vorlauf", "Langs. Vor-/Rücklauf")

#define TR_THEME_EXISTS "Ein Theme-Verzeichnis mit demselben Namen existiert bereits"

#define TR_DATE_TIME_WIDGET "Datum & Uhrzeit"
#define TR_RADIO_INFO_WIDGET "Fernst. Info"
#define TR_LOW_BATT_COLOR "Farbe Akku fast leer"
#define TR_MID_BATT_COLOR "Farbe Akku mittel"
#define TR_HIGH_BATT_COLOR "Farbe Akku voll"
6 changes: 6 additions & 0 deletions radio/src/translations/en.h
Original file line number Diff line number Diff line change
Expand Up @@ -1288,3 +1288,9 @@
#define TR_MIX_SLOW_PREC TR("Slow prec", "Slow up/dn prec")

#define TR_THEME_EXISTS "A theme directory with the same name already exists."

#define TR_DATE_TIME_WIDGET "Date & Time"
#define TR_RADIO_INFO_WIDGET "Radio Info"
#define TR_LOW_BATT_COLOR "Low battery"
#define TR_MID_BATT_COLOR "Mid battery"
#define TR_HIGH_BATT_COLOR "High battery"
6 changes: 6 additions & 0 deletions radio/src/translations/es.h
Original file line number Diff line number Diff line change
Expand Up @@ -1288,3 +1288,9 @@
#define TR_MIX_SLOW_PREC TR("Slow prec", "Slow up/dn prec")

#define TR_THEME_EXISTS "A theme directory with the same name already exists."

#define TR_DATE_TIME_WIDGET "Date & Time"
#define TR_RADIO_INFO_WIDGET "Radio Info"
#define TR_LOW_BATT_COLOR "Low battery"
#define TR_MID_BATT_COLOR "Mid battery"
#define TR_HIGH_BATT_COLOR "High battery"
6 changes: 6 additions & 0 deletions radio/src/translations/fi.h
Original file line number Diff line number Diff line change
Expand Up @@ -1304,3 +1304,9 @@
#define TR_MIX_SLOW_PREC TR("Slow prec", "Slow up/dn prec")

#define TR_THEME_EXISTS "A theme directory with the same name already exists."

#define TR_DATE_TIME_WIDGET "Date & Time"
#define TR_RADIO_INFO_WIDGET "Radio Info"
#define TR_LOW_BATT_COLOR "Low battery"
#define TR_MID_BATT_COLOR "Mid battery"
#define TR_HIGH_BATT_COLOR "High battery"
6 changes: 6 additions & 0 deletions radio/src/translations/fr.h
Original file line number Diff line number Diff line change
Expand Up @@ -1305,3 +1305,9 @@
#define TR_MIX_SLOW_PREC TR("Slow prec", "Slow up/dn prec")

#define TR_THEME_EXISTS "Un thème avec le même nom existe déjà."

#define TR_DATE_TIME_WIDGET "Date & Time"
#define TR_RADIO_INFO_WIDGET "Radio Info"
#define TR_LOW_BATT_COLOR "Low battery"
#define TR_MID_BATT_COLOR "Mid battery"
#define TR_HIGH_BATT_COLOR "High battery"
6 changes: 6 additions & 0 deletions radio/src/translations/he.h
Original file line number Diff line number Diff line change
Expand Up @@ -1291,3 +1291,9 @@
#define TR_MIX_SLOW_PREC TR("Slow prec", "Slow up/dn prec")

#define TR_THEME_EXISTS "כבר קיימת ערכת נושא עם אותו שם"

#define TR_DATE_TIME_WIDGET "תאריך ושעה"
#define TR_RADIO_INFO_WIDGET "מידע השלט"
#define TR_LOW_BATT_COLOR "מתח סוללה נמוך"
#define TR_MID_BATT_COLOR "מתח סוללה בינוני"
#define TR_HIGH_BATT_COLOR "מתח סוללה גבוה"
6 changes: 6 additions & 0 deletions radio/src/translations/it.h
Original file line number Diff line number Diff line change
Expand Up @@ -1283,3 +1283,9 @@
#define TR_MIX_SLOW_PREC TR("Prec. lenta", "Prec. su/giù lenta")

#define TR_THEME_EXISTS "Esiste già una cartella di temi con lo stesso nome."

#define TR_DATE_TIME_WIDGET "Data & Ora"
#define TR_RADIO_INFO_WIDGET "Radio Info"
#define TR_LOW_BATT_COLOR "Batteria scarica"
#define TR_MID_BATT_COLOR "Batteria media"
#define TR_HIGH_BATT_COLOR "Batteria carica"
6 changes: 6 additions & 0 deletions radio/src/translations/jp.h
Original file line number Diff line number Diff line change
Expand Up @@ -1287,3 +1287,9 @@
#define TR_MIX_SLOW_PREC TR("Slow prec", "Slow up/dn prec")

#define TR_THEME_EXISTS "同じ名前のテーマディレクトリが既に存在します。"

#define TR_DATE_TIME_WIDGET "日付と時刻"
#define TR_RADIO_INFO_WIDGET "送信機情報"
#define TR_LOW_BATT_COLOR "バッテリー低"
#define TR_MID_BATT_COLOR "バッテリー中"
#define TR_HIGH_BATT_COLOR "バッテリー高"
6 changes: 6 additions & 0 deletions radio/src/translations/nl.h
Original file line number Diff line number Diff line change
Expand Up @@ -1295,3 +1295,9 @@
#define TR_MIX_SLOW_PREC TR("Slow prec", "Slow up/dn prec")

#define TR_THEME_EXISTS "A theme directory with the same name already exists."

#define TR_DATE_TIME_WIDGET "Date & Time"
#define TR_RADIO_INFO_WIDGET "Radio Info"
#define TR_LOW_BATT_COLOR "Low battery"
#define TR_MID_BATT_COLOR "Mid battery"
#define TR_HIGH_BATT_COLOR "High battery"
6 changes: 6 additions & 0 deletions radio/src/translations/pl.h
Original file line number Diff line number Diff line change
Expand Up @@ -1287,3 +1287,9 @@
#define TR_MIX_SLOW_PREC TR("Wolna prec.", "Wolna prec. góra/dół")

#define TR_THEME_EXISTS "Folder szablonów o takiej samej nazwie już istnieje."

#define TR_DATE_TIME_WIDGET "Data i czas"
#define TR_RADIO_INFO_WIDGET "Informacje o radiu"
#define TR_LOW_BATT_COLOR "Rozładowana bateria"
#define TR_MID_BATT_COLOR "Średni stan baterii"
#define TR_HIGH_BATT_COLOR "Naładowana bateria"
6 changes: 6 additions & 0 deletions radio/src/translations/pt.h
Original file line number Diff line number Diff line change
Expand Up @@ -1291,3 +1291,9 @@
#define TR_MIX_SLOW_PREC TR("Prec. Lento", "Prec. mais/menos lento")

#define TR_THEME_EXISTS "Já existe um diretório de tema com o mesmo nome."

#define TR_DATE_TIME_WIDGET "Data & Hora"
#define TR_RADIO_INFO_WIDGET "Inf do Rádio"
#define TR_LOW_BATT_COLOR "Bateria Baixa"
#define TR_MID_BATT_COLOR "Bateria Média"
#define TR_HIGH_BATT_COLOR "Bateria Alta"
6 changes: 6 additions & 0 deletions radio/src/translations/ru.h
Original file line number Diff line number Diff line change
Expand Up @@ -1290,3 +1290,9 @@
#define TR_MIX_SLOW_PREC TR("Точн замедл", "Точность замедления")

#define TR_THEME_EXISTS "Уже есть каталог с таким названием"

#define TR_DATE_TIME_WIDGET "Date & Time"
#define TR_RADIO_INFO_WIDGET "Radio Info"
#define TR_LOW_BATT_COLOR "Low battery"
#define TR_MID_BATT_COLOR "Mid battery"
#define TR_HIGH_BATT_COLOR "High battery"
6 changes: 6 additions & 0 deletions radio/src/translations/se.h
Original file line number Diff line number Diff line change
Expand Up @@ -1324,3 +1324,9 @@
#define TR_MIX_SLOW_PREC TR("Dröj preci.", "Fördröj upp/ner precision")

#define TR_THEME_EXISTS "Det finns redan ett tema med samma namn"

#define TR_DATE_TIME_WIDGET "Datum & Tid"
#define TR_RADIO_INFO_WIDGET "Radioinformation"
#define TR_LOW_BATT_COLOR "Lågt batteri"
#define TR_MID_BATT_COLOR "Medium batteri"
#define TR_HIGH_BATT_COLOR "Högt batteri"
6 changes: 6 additions & 0 deletions radio/src/translations/tw.h
Original file line number Diff line number Diff line change
Expand Up @@ -1292,3 +1292,9 @@
#define TR_THEME_EXISTS "已存在同名主題目錄 !"

#define ROTORFLIGHT_LUA_CH "按敗板半保備閉標表並波補不菜參叉差償超車持池出存打大帶待怠單到等低地點電調定動度舵二翻方放飛副復負高跟關管航號何合后護環緩回混火或機積集幾計加間減件降交角教接階截進救距開控寬饋拉來累類連練量零靈率濾螺落門面敏模目逆爬盤偏頻平其啟器前曲取確然入剎上設身升失時使式釋試數衰水瞬順速縮他態體停通退陀微尾位文穩誤息熄下陷限線相響向消小校斜新心信型行懸旋循壓頁一移儀益翼因應用油右預援源載增針正直值止置制中重軸主轉准子自蹤總最左耦"

#define TR_DATE_TIME_WIDGET "日期和時間"
#define TR_RADIO_INFO_WIDGET "遙控器信息"
#define TR_LOW_BATT_COLOR "低電量"
#define TR_MID_BATT_COLOR "中電量"
#define TR_HIGH_BATT_COLOR "高電量"
6 changes: 6 additions & 0 deletions radio/src/translations/ua.h
Original file line number Diff line number Diff line change
Expand Up @@ -1280,3 +1280,9 @@
#define TR_MIX_SLOW_PREC TR("Точн. уповільн.", "Точність уповільнення")

#define TR_THEME_EXISTS "A theme directory with the same name already exists."

#define TR_DATE_TIME_WIDGET "Date & Time"
#define TR_RADIO_INFO_WIDGET "Radio Info"
#define TR_LOW_BATT_COLOR "Low battery"
#define TR_MID_BATT_COLOR "Mid battery"
#define TR_HIGH_BATT_COLOR "High battery"

0 comments on commit dd9a620

Please sign in to comment.