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
4 changes: 4 additions & 0 deletions mkapp/app/setting.ini
Original file line number Diff line number Diff line change
Expand Up @@ -178,5 +178,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 @@ -309,23 +309,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 @@ -226,6 +226,10 @@ const setting_t g_setting_defaults = {
.language = {
.lang = LANG_ENGLISH_DEFAULT,
},
.analog_rssi = {
.calib_min = 1600,
.calib_max = 2100,
},
};

int settings_put_osd_element_shown(bool show, char *config_name) {
Expand Down Expand Up @@ -472,6 +476,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
8 changes: 7 additions & 1 deletion src/core/settings.h
Original file line number Diff line number Diff line change
Expand Up @@ -252,7 +252,7 @@ typedef struct {
setting_sources_analog_module_t analog_module;
setting_sources_analog_format_t analog_format; // 0=NTSC, 1= PAL
uint8_t analog_channel;
setting_sources_analog_ratio_t analog_ratio; // 0=4:3, 1=16:9
setting_sources_analog_ratio_t analog_ratio; // 0=4:3, 1=16:9
setting_sources_hdzero_band_t hdzero_band;
setting_sources_hdzero_bw_t hdzero_bw;
} setting_sources_t;
Expand All @@ -275,6 +275,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 @@ -292,6 +297,7 @@ typedef struct {
ease_use_t ease;
setting_storage_t storage;
language_t language;
setting_analog_rssi_t analog_rssi;
} setting_t;

extern setting_t g_setting;
Expand Down
3 changes: 3 additions & 0 deletions src/driver/rtc6715.c
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

#include "../core/common.hh"
#include "../core/defines.h"
#include "driver/dm5680.h"
#include "driver/gpio.h"
#include "gpadc.h"
#include "i2c.h"
Expand Down Expand Up @@ -40,10 +41,12 @@ void RTC6715_SetAudio(int is_on) {
}

void RTC6715_Open(int power_on, int audio_on) {
DM5680_InternalAnalog_Power(power_on);
gpadc_on(power_on);
if (power_on) {
usleep(200 * 1000);
RTC6715_SetAudio(audio_on);
I2C_Write(ADDR_FPGA, 0x8C, 0x02);
}
LOGI("RTC6715_Open:%d, audio:%d", power_on, audio_on);
}
Expand Down
209 changes: 78 additions & 131 deletions src/image/img_arrow.c

Large diffs are not rendered by default.

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

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

#include <log/log.h>
#include <minIni.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"

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

static lv_coord_t col_dsc[] = {160, 160, 160, 160, 160, 160, LV_GRID_TEMPLATE_LAST};
static lv_coord_t row_dsc[] = {60, 60, 60, 60, 60, 60, 60, 60, 60, 60, LV_GRID_TEMPLATE_LAST};

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, 1053, 900);
lv_obj_add_style(page, &style_subpage, LV_PART_MAIN);
lv_obj_set_style_pad_top(page, 94, 0);

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

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, 960, 894);
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, &lv_font_montserrat_16, 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, 12, 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, 0);
usleep(100 * 1000);
RTC6715_SetCH(32); // R1
}

static void on_exit() {
RTC6715_Open(0, 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,
};
11 changes: 11 additions & 0 deletions src/ui/page_analog_rssi.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#pragma once

#ifdef __cplusplus
extern "C" {
#endif

#include "ui/ui_main_menu.h"
extern page_pack_t pp_analog_rssi;
#ifdef __cplusplus
}
#endif
2 changes: 1 addition & 1 deletion src/ui/page_source.c
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ static lv_obj_t *page_source_create(lv_obj_t *parent, panel_arr_t *arr) {

lv_obj_t *section = lv_menu_section_create(page);
lv_obj_add_style(section, &style_submenu, LV_PART_MAIN);
lv_obj_set_size(section, 960, 894);
lv_obj_set_size(section, 1053, 894);

snprintf(buf, sizeof(buf), "%s:", _lang("Source"));
create_text(NULL, section, false, buf, LV_MENU_ITEM_BUILDER_VARIANT_2);
Expand Down
14 changes: 8 additions & 6 deletions src/ui/ui_main_menu.c
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
#include "driver/mcp3021.h"
#include "driver/oled.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 @@ -64,6 +65,7 @@ static page_pack_t *page_packs[] = {
&pp_focus_chart,
&pp_clock,
&pp_input,
&pp_analog_rssi,
&pp_sleep,
};

Expand Down Expand Up @@ -276,24 +278,24 @@ static void main_menu_create_entry(lv_obj_t *menu, lv_obj_t *section, page_pack_

pp->label = lv_label_create(cont);
lv_label_set_text(pp->label, _lang(pp->name));
lv_obj_set_style_text_font(pp->label, &lv_font_montserrat_26, 0);
lv_obj_set_style_text_font(pp->label, &lv_font_montserrat_24, 0);
lv_label_set_long_mode(pp->label, LV_LABEL_LONG_SCROLL_CIRCULAR);

pp->icon = lv_img_create(cont);
lv_img_set_src(pp->icon, &img_arrow);
lv_obj_add_flag(pp->icon, LV_OBJ_FLAG_HIDDEN);

lv_obj_set_style_text_font(cont, &lv_font_montserrat_26, 0);
lv_obj_set_style_text_font(cont, &lv_font_montserrat_24, 0);
lv_menu_set_load_page_event(menu, cont, pp->page);

if (pp->on_created) {
pp->on_created();
}
}

static int post_bootup_actions_cmp(const void * lhs, const void * rhs) {
const int32_t leftPriority = ((page_pack_t*) lhs)->post_bootup_run_priority;
const int32_t rightPriority = ((page_pack_t*) rhs)->post_bootup_run_priority;
static int post_bootup_actions_cmp(const void *lhs, const void *rhs) {
const int32_t leftPriority = ((page_pack_t *)lhs)->post_bootup_run_priority;
const int32_t rightPriority = ((page_pack_t *)rhs)->post_bootup_run_priority;

if (leftPriority < rightPriority) {
return -1;
Expand Down Expand Up @@ -329,7 +331,7 @@ void main_menu_init(void) {
}

// Resort based on priority
qsort(post_bootup_actions, post_bootup_actions_count, sizeof(page_pack_t*), post_bootup_actions_cmp);
qsort(post_bootup_actions, post_bootup_actions_count, sizeof(page_pack_t *), post_bootup_actions_cmp);

lv_obj_add_style(section, &style_rootmenu, LV_PART_MAIN);
lv_obj_set_size(section, 250, 975);
Expand Down