Skip to content

Commit

Permalink
feat(color): Add OneBit option to color radios (and Companion!!) (#1994)
Browse files Browse the repository at this point in the history
* Added OneBit option also to color radios

* Try to work around GH repo owner issue

Original by @raphaelcoeffic in EdgeTX/edgetx@bf4b5d8

* Add Companion support for radios with external module

* Companion housekeeping - do not display unnecessary hardware section headings

* fix: Rebase cleanup

* fix: LVGL changes

* feat: Move sample mode to a new Ext RF block

Co-authored-by: elecpower <[email protected]>
Co-authored-by: Peter Feerick <[email protected]>
  • Loading branch information
3 people authored Jul 22, 2022
1 parent 54aaf5b commit 2ee7503
Show file tree
Hide file tree
Showing 10 changed files with 167 additions and 9 deletions.
3 changes: 3 additions & 0 deletions companion/src/firmwares/boards.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -497,6 +497,9 @@ int Boards::getCapability(Board::Type board, Board::Capability capability)
case HasInternalModuleSupport:
return (IS_STM32(board) && !IS_TARANIS_X9(board));

case HasExternalModuleSupport:
return (IS_STM32(board) && !IS_RADIOMASTER_T8(board));

case SportMaxBaudRate:
if (IS_FAMILY_T16(board) || IS_FLYSKY_NV14(board) || IS_TARANIS_X7_ACCESS(board) ||
(IS_TARANIS(board) && !IS_TARANIS_XLITE(board) && !IS_TARANIS_X7(board) && !IS_TARANIS_X9LITE(board)))
Expand Down
1 change: 1 addition & 0 deletions companion/src/firmwares/boards.h
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,7 @@ namespace Board {
HasColorLcd,
HasSDCard,
HasInternalModuleSupport,
HasExternalModuleSupport,
SportMaxBaudRate
};

Expand Down
32 changes: 32 additions & 0 deletions companion/src/firmwares/generalsettings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -606,6 +606,38 @@ AbstractStaticItemModel * GeneralSettings::stickDeadZoneItemModel()
return mdl;
}

QString GeneralSettings::uartSampleModeToString() const
{
return uartSampleModeToString(uartSampleMode);
}

// static
QString GeneralSettings::uartSampleModeToString(int value)
{
switch(value) {
case UART_SAMPLE_MODE_NORMAL:
return tr("Normal");
case UART_SAMPLE_MODE_ONEBIT:
return tr("OneBit");
default:
return CPN_STR_UNKNOWN_ITEM;
}
}

// static
AbstractStaticItemModel * GeneralSettings::uartSampleModeItemModel()
{
AbstractStaticItemModel * mdl = new AbstractStaticItemModel();
mdl->setName(AIM_GS_UARTSAMPLEMODE);

for (int i = 0; i < UART_SAMPLE_MODE_COUNT; i++) {
mdl->appendToItemList(uartSampleModeToString(i), i);
}

mdl->loadItemList();
return mdl;
}

/*
TrainerMix
*/
Expand Down
11 changes: 11 additions & 0 deletions companion/src/firmwares/generalsettings.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ constexpr char AIM_GS_BLUETOOTHMODE[] {"gs.bluetoothmode"};
constexpr char AIM_GS_SERIALMODE[] {"gs.serialmode%1"};
constexpr char AIM_GS_INTMODULEBAUDRATE[] {"gs.intmodulebaudrate"};
constexpr char AIM_GS_STICKDEADZONE[] {"gs.stickdeadzone"};
constexpr char AIM_GS_UARTSAMPLEMODE[] {"gs.uartsamplemode"};
constexpr char AIM_TRAINERMIX_MODE[] {"trainermix.mode"};
constexpr char AIM_TRAINERMIX_SRC[] {"trainermix.src"};

Expand Down Expand Up @@ -153,6 +154,12 @@ class GeneralSettings {
SP_COUNT,
};

enum UartSampleMode {
UART_SAMPLE_MODE_NORMAL,
UART_SAMPLE_MODE_ONEBIT,
UART_SAMPLE_MODE_COUNT
};

GeneralSettings() { clear(); }
void clear();
void init();
Expand Down Expand Up @@ -274,16 +281,20 @@ class GeneralSettings {
QString bluetoothModeToString() const;
QString serialPortModeToString(int port_nr) const;
QString internalModuleBaudrateToString() const;
QString uartSampleModeToString() const;

static QString antennaModeToString(int value);
static QString bluetoothModeToString(int value);
static QString serialModeToString(int value);
static QString moduleBaudrateToString(int value);
static FieldRange getPPM_MultiplierRange();
static FieldRange getTxCurrentCalibration();
static QString uartSampleModeToString(int value);

static AbstractStaticItemModel * antennaModeItemModel();
static AbstractStaticItemModel * bluetoothModeItemModel();
static AbstractStaticItemModel * serialModeItemModel(int port_nr);
static AbstractStaticItemModel * internalModuleBaudrateItemModel();
static AbstractStaticItemModel * stickDeadZoneItemModel();
static AbstractStaticItemModel * uartSampleModeItemModel();
};
21 changes: 14 additions & 7 deletions companion/src/generaledit/hardware.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@ HardwarePanel::HardwarePanel(QWidget * parent, GeneralSettings & generalSettings
int auxmodelid = editorItemModels->registerItemModel(GeneralSettings::serialModeItemModel(GeneralSettings::SP_AUX1));
int vcpmodelid = editorItemModels->registerItemModel(GeneralSettings::serialModeItemModel(GeneralSettings::SP_VCP));
int baudmodelid = editorItemModels->registerItemModel(GeneralSettings::internalModuleBaudrateItemModel());
int uartmodelid = editorItemModels->registerItemModel(GeneralSettings::uartSampleModeItemModel());

id = editorItemModels->registerItemModel(ModuleData::internalModuleItemModel());
tabFilteredModels->registerItemModel(new FilteredItemModel(editorItemModels->getItemModel(id)), FIM_INTERNALMODULES);
Expand All @@ -123,29 +124,26 @@ HardwarePanel::HardwarePanel(QWidget * parent, GeneralSettings & generalSettings
addParams(row, spnStickDeadZone);
}

addSection(tr("Pots"), row);

count = Boards::getCapability(board, Board::Pots);
count -= firmware->getCapability(HasFlySkyGimbals) ? 2 : 0;
if (count > 0) {
addSection(tr("Pots"), row);
for (int i = 0; i < count; i++) {
addPot(i, row);
}
}

addSection(tr("Sliders"), row);

count = Boards::getCapability(board, Board::Sliders);
if (count) {
addSection(tr("Sliders"), row);
for (int i = 0; i < count; i++) {
addSlider(i, row);
}
}

addSection(tr("Switches"), row);

count = Boards::getCapability(board, Board::Switches);
if (count) {
addSection(tr("Switches"), row);
for (int i = 0; i < count; i++) {
addSwitch(i, row);
}
Expand Down Expand Up @@ -216,11 +214,20 @@ HardwarePanel::HardwarePanel(QWidget * parent, GeneralSettings & generalSettings
row++;
}

if (Boards::getCapability(board, Board::HasExternalModuleSupport)) {
addLabel(tr("Sample Mode"), row, 0);
AutoComboBox *uartSampleMode = new AutoComboBox(this);
uartSampleMode->setModel(editorItemModels->getItemModel(uartmodelid));
uartSampleMode->setField(generalSettings.uartSampleMode);
addParams(row, uartSampleMode);
}

// All values except 0 are mutually exclusive
ExclusiveComboGroup *exclGroup = new ExclusiveComboGroup(
this, [=](const QVariant &value) { return value == 0; });

addSection(tr("Serial port"), row);
if (firmware->getCapability(HasAuxSerialMode) || firmware->getCapability(HasAux2SerialMode) || firmware->getCapability(HasVCPSerialMode))
addSection(tr("Serial ports"), row);

if (firmware->getCapability(HasAuxSerialMode)) {
QString lbl = "AUX1";
Expand Down
1 change: 1 addition & 0 deletions radio/src/gui/colorlcd/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ set(GUI_SRC
radio_trainer.cpp
radio_version.cpp
hw_intmodule.cpp
hw_extmodule.cpp
hw_inputs.cpp
hw_serial.cpp
radio_hardware.cpp
Expand Down
56 changes: 56 additions & 0 deletions radio/src/gui/colorlcd/hw_extmodule.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
/*
* Copyright (C) EdgeTX
*
* Based on code named
* opentx - https://github.com/opentx/opentx
* th9x - http://code.google.com/p/th9x
* er9x - http://code.google.com/p/er9x
* gruvin9x - http://code.google.com/p/gruvin9x
*
* License GPLv2: http://www.gnu.org/licenses/gpl-2.0.html
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2 as
* published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*/

#include "hw_extmodule.h"

#include "opentx.h"

#define SET_DIRTY() storageDirty(EE_GENERAL)

static const lv_coord_t col_dsc[] = {LV_GRID_FR(1), LV_GRID_FR(3),
LV_GRID_TEMPLATE_LAST};

static const lv_coord_t row_dsc[] = {LV_GRID_CONTENT, LV_GRID_TEMPLATE_LAST};

ExternalModuleWindow::ExternalModuleWindow(Window *parent) :
FormGroup::Line(parent), lastModule(g_eeGeneral.internalModule)
{
FlexGridLayout grid(col_dsc, row_dsc, 2);
setLayout(&grid);

new StaticText(this, rect_t{}, STR_SAMPLE_MODE, 0, COLOR_THEME_PRIMARY1);

auto box = new FormGroup(this, rect_t{});
box->setFlexLayout(LV_FLEX_FLOW_ROW, lv_dpx(8));
lv_obj_set_style_grid_cell_x_align(box->getLvObj(), LV_GRID_ALIGN_STRETCH, 0);

new Choice(box, rect_t{}, STR_SAMPLE_MODES, 0, UART_SAMPLE_MODE_MAX,
getSampleMode, setSampleMode);
}

int ExternalModuleWindow::getSampleMode() { return g_eeGeneral.uartSampleMode; }

void ExternalModuleWindow::setSampleMode(int modeValue)
{
g_eeGeneral.uartSampleMode = modeValue;
SET_DIRTY();
restartModule(EXTERNAL_MODULE);
}
37 changes: 37 additions & 0 deletions radio/src/gui/colorlcd/hw_extmodule.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
/*
* Copyright (C) EdgeTX
*
* Based on code named
* opentx - https://github.com/opentx/opentx
* th9x - http://code.google.com/p/th9x
* er9x - http://code.google.com/p/er9x
* gruvin9x - http://code.google.com/p/gruvin9x
*
* License GPLv2: http://www.gnu.org/licenses/gpl-2.0.html
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2 as
* published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*/

#pragma once

#include "form.h"

class ExternalModuleWindow : public FormGroup::Line
{
public:
ExternalModuleWindow(Window* parent);

protected:
uint8_t lastModule = 0;
lv_obj_t* br_box = nullptr;

static int getSampleMode();
static void setSampleMode(int modeValue);
};
11 changes: 9 additions & 2 deletions radio/src/gui/colorlcd/radio_hardware.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
#include "hal/adc_driver.h"
#include "aux_serial_driver.h"
#include "hw_intmodule.h"
#include "hw_extmodule.h"
#include "hw_serial.h"
#include "hw_inputs.h"

Expand Down Expand Up @@ -121,8 +122,14 @@ void RadioHardwarePage::build(FormWindow * window)

#if defined(HARDWARE_INTERNAL_MODULE)
new Subtitle(window, rect_t{}, TR_INTERNALRF, 0, COLOR_THEME_PRIMARY1);
auto mod = new InternalModuleWindow(window);
mod->padLeft(lv_dpx(8));
auto intMod = new InternalModuleWindow(window);
intMod->padLeft(lv_dpx(8));
#endif

#if defined(HARDWARE_EXTERNAL_MODULE)
new Subtitle(window, rect_t{}, TR_EXTERNALRF, 0, COLOR_THEME_PRIMARY1);
auto extMod = new ExternalModuleWindow(window);
extMod->padLeft(lv_dpx(8));
#endif

#if defined(BLUETOOTH)
Expand Down
3 changes: 3 additions & 0 deletions radio/src/targets/horus/telemetry_driver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,9 @@ void telemetryPortInit(uint32_t baudrate, uint8_t mode)
}
USART_InitStructure.USART_HardwareFlowControl = USART_HardwareFlowControl_None;
USART_InitStructure.USART_Mode = USART_Mode_Tx | USART_Mode_Rx;
if (g_eeGeneral.uartSampleMode == UART_SAMPLE_MODE_ONEBIT) {
USART_OneBitMethodCmd(TELEMETRY_USART, ENABLE);
}
USART_Init(TELEMETRY_USART, &USART_InitStructure);

#if defined(PCBX12S)
Expand Down

0 comments on commit 2ee7503

Please sign in to comment.