Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 0 additions & 3 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
{
"editor.formatOnSave": true,
"files.associations": {
"ui_style.h": "c"
},
}
4 changes: 4 additions & 0 deletions conf/ui.h
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,8 @@ extern "C" {
#define UI_STORAGE_ROWS 60, 60, 60, 60, 60, 60, 60, 40, LV_GRID_TEMPLATE_LAST
#define UI_VERSION_COLS 160, 160, 160, 160, 160, 160, 160, LV_GRID_TEMPLATE_LAST
#define UI_VERSION_ROWS 60, 60, 60, 60, 60, 60, 60, 60, 60, 60, LV_GRID_TEMPLATE_LAST
#define UI_ANALOG_RSSI_COLS 160, 160, 160, 160, 160, 160, LV_GRID_TEMPLATE_LAST
#define UI_ANALOG_RSSI_ROWS 60, 60, 60, 60, 60, 60, 60, 60, 60, 60, LV_GRID_TEMPLATE_LAST
#define UI_VERSION_RELEASE_NOTES_MIN_SIZE 600
#define UI_VERSION_RELEASE_NOTES_MAX_SIZE 1280
#define UI_VERSION_FIRMWARE_MIN_SIZE UI_VERSION_RELEASE_NOTES_MIN_SIZE
Expand Down Expand Up @@ -216,6 +218,8 @@ static inline int UI_STATUS_BAR_LABEL_WIDTH() {
#define UI_STORAGE_ROWS 40, 40, 40, 40, 40, 40, 40, 26, LV_GRID_TEMPLATE_LAST
#define UI_VERSION_COLS 106, 106, 106, 106, 106, 106, LV_GRID_TEMPLATE_LAST
#define UI_VERSION_ROWS 40, 40, 40, 40, 40, 40, 40, 26, LV_GRID_TEMPLATE_LAST
#define UI_ANALOG_RSSI_COLS 106, 106, 106, 106, 106, 106, LV_GRID_TEMPLATE_LAST
#define UI_ANALOG_RSSI_ROWS 40, 40, 40, 40, 40, 40, 40, 26, LV_GRID_TEMPLATE_LAST
#define UI_VERSION_RELEASE_NOTES_MIN_SIZE 600
#define UI_VERSION_RELEASE_NOTES_MAX_SIZE 1280
#define UI_VERSION_FIRMWARE_MIN_SIZE UI_VERSION_RELEASE_NOTES_MIN_SIZE
Expand Down
4 changes: 4 additions & 0 deletions mkapp/app/setting.ini
Original file line number Diff line number Diff line change
Expand Up @@ -179,5 +179,9 @@ element_goggle_temp_right_pos_4_3_y=50
element_goggle_temp_right_pos_16_9_x=370
element_goggle_temp_right_pos_16_9_y=50

[analog_rssi]
calib_min = 1600
calib_max = 2100

[language]
lang = 0
31 changes: 14 additions & 17 deletions src/core/osd.c
Original file line number Diff line number Diff line change
Expand Up @@ -344,23 +344,20 @@ void osd_analog_rssi_show(bool bShow) {

lv_obj_clear_flag(analog_rssi_bar, LV_OBJ_FLAG_HIDDEN);

int rssi_volt_mv = RTC6715_GetRssi();
/*
1600 -> 0%
2200 -> 100%
*/

// if (cnt == 19)
// LOGI(" rssi rssi_volt_mv:%d", rssi_volt_mv);

rssi_volt_mv -= 1600;
rssi_volt_mv = (rssi_volt_mv < 0) ? 0 : rssi_volt_mv;
rssi_volt_mv /= 6;
// cnt++;
// if (cnt == 20) {
// cnt = 0;
// LOGI(" rssi pct:%d", rssi_volt_mv);
// }
int rssi_volt_mv;

if (g_setting.analog_rssi.calib_min == g_setting.analog_rssi.calib_max)
rssi_volt_mv = 0;
else {
rssi_volt_mv = RTC6715_GetRssi();
if (rssi_volt_mv <= g_setting.analog_rssi.calib_min)
rssi_volt_mv = 0;
else if (rssi_volt_mv >= g_setting.analog_rssi.calib_max)
rssi_volt_mv = 100;
else
rssi_volt_mv = (rssi_volt_mv - g_setting.analog_rssi.calib_min) * 100 / (g_setting.analog_rssi.calib_max - g_setting.analog_rssi.calib_min);
}

lv_bar_set_value(analog_rssi_bar, rssi_volt_mv, LV_ANIM_OFF);
}

Expand Down
8 changes: 8 additions & 0 deletions src/core/settings.c
Original file line number Diff line number Diff line change
Expand Up @@ -233,6 +233,10 @@ const setting_t g_setting_defaults = {
.language = {
.lang = LANG_ENGLISH_DEFAULT,
},
.analog_rssi = {
.calib_min = 1600,
.calib_max = 2100,
},
.has_all_features = true,
};

Expand Down Expand Up @@ -477,6 +481,10 @@ void settings_load(void) {
// storage
g_setting.storage.logging = settings_get_bool("storage", "logging", g_setting_defaults.storage.logging);

// analog rssi
g_setting.analog_rssi.calib_min = ini_getl("analog_rssi", "calib_min", g_setting_defaults.analog_rssi.calib_min, SETTING_INI);
g_setting.analog_rssi.calib_max = ini_getl("analog_rssi", "calib_max", g_setting_defaults.analog_rssi.calib_max, SETTING_INI);

// language
if (!language_config()) {
g_setting.language.lang = ini_getl("language", "lang", g_setting_defaults.language.lang, SETTING_INI);
Expand Down
6 changes: 6 additions & 0 deletions src/core/settings.h
Original file line number Diff line number Diff line change
Expand Up @@ -278,6 +278,11 @@ typedef struct {
uint16_t lang;
} language_t;

typedef struct {
uint16_t calib_min;
uint16_t calib_max;
} setting_analog_rssi_t;

typedef struct {
setting_scan_t scan;
setting_fan_t fans;
Expand All @@ -295,6 +300,7 @@ typedef struct {
ease_use_t ease;
setting_storage_t storage;
language_t language;
setting_analog_rssi_t analog_rssi;
bool has_all_features;
} setting_t;

Expand Down
4 changes: 2 additions & 2 deletions src/driver/hardware-boxpro.c
Original file line number Diff line number Diff line change
Expand Up @@ -685,7 +685,7 @@ void Source_AV(source_t mode) // 0=rtc6715; 1=AV_in
{
pthread_mutex_lock(&hardware_mutex);
Screen_Display(0);
I2C_Write(ADDR_FPGA, 0x8C, 0x00);
// I2C_Write(ADDR_FPGA, 0x8C, 0x00);

g_hw_stat.av_chid = SOURCE_AV_MODULE == mode ? 0 : 1;

Expand All @@ -712,7 +712,7 @@ void Source_AV(source_t mode) // 0=rtc6715; 1=AV_in
else
I2C_Write(ADDR_FPGA, 0x8f, 0x00); // bit[7]: 0=15:9, 1=original

I2C_Write(ADDR_FPGA, 0x8c, 0x02);
// I2C_Write(ADDR_FPGA, 0x8c, 0x02);

g_hw_stat.source_mode = SOURCE_MODE_AV;
Display_VO_SWITCH(1);
Expand Down
3 changes: 2 additions & 1 deletion src/driver/rtc6715.c
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ void MM_Write(uint8_t addr, uint32_t dat) {
void RTC6715_Open(int on) {
gpio_set(GPIO_RTC6715_ON, on);
gpadc_on(on);
I2C_Write(ADDR_FPGA, 0x8C, (on << 1));
LOGI("RTC6715_Open:%d", on);
}

Expand Down Expand Up @@ -98,7 +99,7 @@ int RTC6715_GetRssi() {
return rssi_adc;

rssi_adc = 3300 * value / 4096;
LOGI("rssi voltage: %02f", (float)rssi_adc / 1000);
// LOGI("rssi voltage: %02f", (float)rssi_adc / 1000);
return rssi_adc;
}

Expand Down
175 changes: 175 additions & 0 deletions src/ui/page_analog_rssi.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,175 @@
#include "page_analog_rssi.h"

#include <stdio.h>
#include <unistd.h>

#include <log/log.h>
#include <minIni.h>

#include "../conf/ui.h"

#include "core/app_state.h"
#include "core/battery.h"
#include "core/common.hh"
#include "driver/dm5680.h"
#include "driver/hardware.h"
#include "driver/mcp3021.h"
#include "driver/rtc6715.h"
#include "lang/language.h"
#include "page_common.h"
#include "ui/ui_style.h"

#ifdef HDZBOXPRO

enum {
ROW_CALIBRATE_RSSI_MIN = 0,
ROW_CALIBRATE_RSSI_MAX,
ROW_BACK,
ROW_COUNT
};

static lv_coord_t col_dsc[] = {UI_ANALOG_RSSI_COLS};
static lv_coord_t row_dsc[] = {UI_ANALOG_RSSI_ROWS};

static lv_obj_t *calibrate_rssi_min_obj;
static lv_obj_t *calibrate_rssi_max_obj;

static lv_obj_t *page_analog_rssi_create(lv_obj_t *parent, panel_arr_t *arr) {
char buf[1024];

lv_obj_t *page = lv_menu_page_create(parent, NULL);
lv_obj_clear_flag(page, LV_OBJ_FLAG_SCROLLABLE);
lv_obj_set_size(page, UI_PAGE_VIEW_SIZE);
lv_obj_add_style(page, &style_subpage, LV_PART_MAIN);

lv_obj_t *section = lv_menu_section_create(page);
lv_obj_add_style(section, &style_submenu, LV_PART_MAIN);
lv_obj_set_size(section, UI_PAGE_VIEW_SIZE);

snprintf(buf, sizeof(buf), "%s:", _lang("Analog RSSI"));
create_text(NULL, section, false, buf, LV_MENU_ITEM_BUILDER_VARIANT_2);

lv_obj_t *cont = lv_obj_create(section);
lv_obj_set_size(cont, UI_PAGE_VIEW_SIZE);
lv_obj_set_pos(cont, 0, 0);
lv_obj_set_layout(cont, LV_LAYOUT_GRID);
lv_obj_clear_flag(cont, LV_OBJ_FLAG_SCROLLABLE);
lv_obj_add_style(cont, &style_context, LV_PART_MAIN);

lv_obj_set_style_grid_column_dsc_array(cont, col_dsc, 0);
lv_obj_set_style_grid_row_dsc_array(cont, row_dsc, 0);

create_select_item(arr, cont);

snprintf(buf, sizeof(buf), "%s", _lang("Calibrate RSSI Min"));
calibrate_rssi_min_obj = create_label_item(cont, buf, 1, ROW_CALIBRATE_RSSI_MIN, 3);
snprintf(buf, sizeof(buf), "%s", _lang("Calibrate RSSI Max"));
calibrate_rssi_max_obj = create_label_item(cont, buf, 1, ROW_CALIBRATE_RSSI_MAX, 3);

snprintf(buf, sizeof(buf), "< %s", _lang("Back"));
create_label_item(cont, buf, 1, ROW_BACK, 1);

lv_obj_t *note = lv_label_create(cont);
snprintf(buf, sizeof(buf), "%s:\n -%s\n -%s\n%s:\n -%s\n -%s\n -%s",
_lang("Before calibrating RSSI min"),
_lang("Remove the BoxPro antenna"),
_lang("Turn off all VTX"),
_lang("Before calibrating RSSI max"),
_lang("Remove the BoxPro antenna"),
_lang("Turn on the analog VTX to R1 25mw"),
_lang("Place the VTX 2 meters away from the BoxPro"));
lv_label_set_text(note, buf);

lv_obj_set_style_text_font(note, UI_PAGE_LABEL_FONT, 0);
lv_obj_set_style_text_align(note, LV_TEXT_ALIGN_LEFT, 0);
lv_obj_set_style_text_color(note, lv_color_make(255, 255, 255), 0);
lv_obj_set_style_pad_top(note, UI_PAGE_TEXT_PAD, 0);
lv_label_set_long_mode(note, LV_LABEL_LONG_WRAP);
lv_obj_set_grid_cell(note, LV_GRID_ALIGN_START, 1, 4, LV_GRID_ALIGN_START, 7, 2);

return page;
}

static void on_enter() {
RTC6715_Open(1);
usleep(100 * 1000);
RTC6715_SetCH(32); // R1
}

static void on_exit() {
RTC6715_Open(0);
}

static void on_created() {
}

static void on_update(uint32_t delta_ms) {
}

static void on_roller(uint8_t key) {
lv_label_set_text(calibrate_rssi_min_obj, _lang("Calibrate RSSI Min"));
lv_label_set_text(calibrate_rssi_max_obj, _lang("Calibrate RSSI Max"));
}

static void on_click(uint8_t key, int sel) {
char buf[128];
int volt_mv = 0;

switch (sel) {
case ROW_CALIBRATE_RSSI_MIN:
LOGI("capture rssi voltage");

for (int i = 0; i < 8; i++) {
volt_mv += RTC6715_GetRssi();
}

volt_mv = volt_mv >> 3;
ini_putl("analog_rssi", "calib_min", (uint16_t)volt_mv, SETTING_INI);
g_setting.analog_rssi.calib_min = ini_getl("analog_rssi", "calib_min", g_setting_defaults.analog_rssi.calib_max, SETTING_INI);

snprintf(buf, sizeof(buf), "%s #FFFF00 %s#", _lang("Calibrate RSSI Min"), _lang("Complete"));
lv_label_set_text(calibrate_rssi_min_obj, buf);

LOGI("result: calib_min=%dmv", g_setting.analog_rssi.calib_min);
break;

case ROW_CALIBRATE_RSSI_MAX:
LOGI("capture rssi voltage");

for (int i = 0; i < 8; i++) {
volt_mv += RTC6715_GetRssi();
}

volt_mv = volt_mv >> 3;
ini_putl("analog_rssi", "calib_max", (uint16_t)volt_mv, SETTING_INI);
g_setting.analog_rssi.calib_max = ini_getl("analog_rssi", "calib_max", g_setting_defaults.analog_rssi.calib_max, SETTING_INI);

snprintf(buf, sizeof(buf), "%s #FFFF00 %s#", _lang("Calibrate RSSI Max"), _lang("Complete"));
lv_label_set_text(calibrate_rssi_max_obj, buf);

LOGI("result: calib_max=%dmv", g_setting.analog_rssi.calib_max);
break;
default:
break;
}
}

static void on_right_button(bool is_short) {
}

page_pack_t pp_analog_rssi = {
.p_arr = {
.cur = 0,
.max = ROW_COUNT,
},
.name = "Analog RSSI",
.create = page_analog_rssi_create,
.enter = on_enter,
.exit = on_exit,
.on_created = NULL,
.on_update = NULL,
.on_roller = on_roller,
.on_click = on_click,
.on_right_button = NULL,
};
#endif
13 changes: 13 additions & 0 deletions src/ui/page_analog_rssi.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
#pragma once

#ifdef __cplusplus
extern "C" {
#endif

#include "ui/ui_main_menu.h"
#ifdef HDZBOXPRO
extern page_pack_t pp_analog_rssi;
#endif
#ifdef __cplusplus
}
#endif
2 changes: 1 addition & 1 deletion src/ui/page_power.c
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ static slider_group_t *selected_slider_group = NULL;

static lv_coord_t col_dsc[] = {UI_POWER_COLS};
static lv_coord_t row_dsc[] = {UI_POWER_ROWS};
lv_obj_t *label_cell_count;
static lv_obj_t *label_cell_count;

static void page_power_update_cell_count() {
char str[10];
Expand Down
11 changes: 10 additions & 1 deletion src/ui/ui_main_menu.c
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
#include "driver/mcp3021.h"
#include "driver/screen.h"
#include "lang/language.h"
#include "ui/page_analog_rssi.h"
#include "ui/page_autoscan.h"
#include "ui/page_clock.h"
#include "ui/page_common.h"
Expand Down Expand Up @@ -47,7 +48,10 @@ static lv_obj_t *root_page;
/**
* To contain all menu pages.
*/
static page_pack_t *page_packs[18];

#define PAGE_PACK_MAX_NUM 19

static page_pack_t *page_packs[PAGE_PACK_MAX_NUM];
static size_t page_packs_count = 0;
static page_pack_t *post_bootup_actions[18];
static size_t post_bootup_actions_count = 0;
Expand Down Expand Up @@ -130,6 +134,7 @@ void submenu_roller(uint8_t key) {
pp->p_arr.cur = pp->p_arr.max - 1;
} while (!lv_obj_has_flag(pp->p_arr.panel[pp->p_arr.cur], FLAG_SELECTABLE));
}
LOGI("submenu_roller %d", pp->p_arr.cur);
set_select_item(&pp->p_arr, pp->p_arr.cur);
}

Expand Down Expand Up @@ -269,6 +274,7 @@ static void main_menu_create_entry(lv_obj_t *menu, lv_obj_t *section, page_pack_
if (pp->on_created) {
pp->on_created();
}
LOGD("Done");
}

static int post_bootup_actions_cmp(const void *lhs, const void *rhs) {
Expand Down Expand Up @@ -307,6 +313,9 @@ void main_menu_init(void) {
page_packs[page_packs_count++] = &pp_focus_chart;
page_packs[page_packs_count++] = &pp_clock;
page_packs[page_packs_count++] = &pp_input;
#ifdef HDZBOXPRO
page_packs[page_packs_count++] = &pp_analog_rssi;
#endif
page_packs[page_packs_count++] = &pp_sleep;

menu = lv_menu_create(lv_scr_act());
Expand Down