fix(ui): Auto adjust PPM frame length if greater than 8 ch (#3622)

* Auto-adjusts PPM frame length if channel count is greater than 8 channels

* added auto adjust for PPM trainer mode on b&w targets

* code cleanup
This commit is contained in:
Michael
2023-05-31 13:29:17 +10:00
committed by GitHub
parent 892d2b183b
commit e25c6d8a99
9 changed files with 81 additions and 30 deletions
+2
View File
@@ -1489,6 +1489,8 @@ void menuModelSetup(event_t event)
break; break;
case 1: case 1:
CHECK_INCDEC_MODELVAR(event, g_model.trainerData.channelsCount, -4, min<int8_t>(MAX_TRAINER_CHANNELS_M8, 32-8-g_model.trainerData.channelsStart)); CHECK_INCDEC_MODELVAR(event, g_model.trainerData.channelsCount, -4, min<int8_t>(MAX_TRAINER_CHANNELS_M8, 32-8-g_model.trainerData.channelsStart));
if (checkIncDec_Ret)
setDefaultPpmFrameLengthTrainer();
break; break;
} }
} }
+2
View File
@@ -1376,6 +1376,8 @@ void menuModelSetup(event_t event)
break; break;
case 1: case 1:
CHECK_INCDEC_MODELVAR(event, g_model.trainerData.channelsCount, -4, min<int8_t>(MAX_TRAINER_CHANNELS_M8, 32-8-g_model.trainerData.channelsStart)); CHECK_INCDEC_MODELVAR(event, g_model.trainerData.channelsCount, -4, min<int8_t>(MAX_TRAINER_CHANNELS_M8, 32-8-g_model.trainerData.channelsStart));
if (checkIncDec_Ret)
setDefaultPpmFrameLengthTrainer();
break; break;
} }
} }
+35
View File
@@ -24,6 +24,27 @@
#define SET_DIRTY() storageDirty(EE_MODEL) #define SET_DIRTY() storageDirty(EE_MODEL)
inline int16_t ppmFrameLen(int8_t chCount) {
#define PPM_PULSE_LEN_MAX (4 * PPM_STEP_SIZE) // let's assume roughly 2ms max pulse length
if(chCount > 0)
return((PPM_PULSE_LEN_MAX * chCount) + PPM_DEF_PERIOD); // for more than 8 channels update frame length
else
return(PPM_DEF_PERIOD); // else leave frame Length at default (22.5ms)
}
void cb_value_changed(lv_event_t* e) {
ChannelRange* chRangeEditObject = (ChannelRange*)lv_event_get_user_data(e);
if(!chRangeEditObject)
return;
NumberEdit* ppmFrameLenEditObject = chRangeEditObject->getPpmFrameLenEditObject();
if(!ppmFrameLenEditObject)
return;
ppmFrameLenEditObject->setValue(ppmFrameLen(chRangeEditObject->getChannelsCount()));
}
ChannelRange::ChannelRange(Window* parent) : ChannelRange::ChannelRange(Window* parent) :
FormGroup(parent, rect_t{}) FormGroup(parent, rect_t{})
{ {
@@ -83,11 +104,22 @@ void ChannelRange::update()
updateEnd(); updateEnd();
} }
NumberEdit* ChannelRange::getPpmFrameLenEditObject() {
return this->ppmFrameLenEditObject;
}
void ChannelRange::setPpmFrameLenEditObject(NumberEdit* ppmFrameLenEditObject) {
this->ppmFrameLenEditObject = ppmFrameLenEditObject;
}
ModuleChannelRange::ModuleChannelRange(Window* parent, uint8_t moduleIdx) : ModuleChannelRange::ModuleChannelRange(Window* parent, uint8_t moduleIdx) :
ChannelRange(parent), moduleIdx(moduleIdx) ChannelRange(parent), moduleIdx(moduleIdx)
{ {
build(); build();
update(); update();
// add callback to be notified when channel count changes
lv_obj_add_event_cb(chEnd->getLvObj(), cb_value_changed, LV_EVENT_VALUE_CHANGED, (void *)this);
} }
void ModuleChannelRange::update() void ModuleChannelRange::update()
@@ -156,6 +188,9 @@ TrainerChannelRange::TrainerChannelRange(Window* parent) :
{ {
build(); build();
update(); update();
// add callback to be notified when channel count changes
lv_obj_add_event_cb(chEnd->getLvObj(), cb_value_changed, LV_EVENT_VALUE_CHANGED, (void *)this);
} }
uint8_t TrainerChannelRange::getChannelsStart() uint8_t TrainerChannelRange::getChannelsStart()
+9 -3
View File
@@ -36,16 +36,20 @@ class ChannelRange : public FormGroup
void updateStart(); void updateStart();
void updateEnd(); void updateEnd();
virtual int8_t getChannelsCount() = 0;
void setPpmFrameLenEditObject(NumberEdit* ppmFrameLenEditObject);
NumberEdit* getPpmFrameLenEditObject();
protected: protected:
NumberEdit* chStart; NumberEdit* chStart;
NumberEdit* chEnd; NumberEdit* chEnd;
NumberEdit* ppmFrameLenEditObject = nullptr;
void build(); void build();
virtual uint8_t getChannelsStart() = 0; virtual uint8_t getChannelsStart() = 0;
virtual void setChannelsStart(uint8_t val) = 0; virtual void setChannelsStart(uint8_t val) = 0;
virtual int8_t getChannelsCount() = 0;
virtual void setChannelsCount(int8_t val) = 0; virtual void setChannelsCount(int8_t val) = 0;
virtual uint8_t getChannelsUsed() = 0; virtual uint8_t getChannelsUsed() = 0;
@@ -62,7 +66,6 @@ class ModuleChannelRange : public ChannelRange
uint8_t getChannelsStart() override; uint8_t getChannelsStart() override;
void setChannelsStart(uint8_t val) override; void setChannelsStart(uint8_t val) override;
int8_t getChannelsCount() override;
void setChannelsCount(int8_t val) override; void setChannelsCount(int8_t val) override;
uint8_t getChannelsUsed() override; uint8_t getChannelsUsed() override;
@@ -71,6 +74,8 @@ class ModuleChannelRange : public ChannelRange
public: public:
ModuleChannelRange(Window* parent, uint8_t moduleIdx); ModuleChannelRange(Window* parent, uint8_t moduleIdx);
int8_t getChannelsCount() override;
}; };
class TrainerChannelRange : public ChannelRange class TrainerChannelRange : public ChannelRange
@@ -78,7 +83,6 @@ class TrainerChannelRange : public ChannelRange
uint8_t getChannelsStart() override; uint8_t getChannelsStart() override;
void setChannelsStart(uint8_t val) override; void setChannelsStart(uint8_t val) override;
int8_t getChannelsCount() override;
void setChannelsCount(int8_t val) override; void setChannelsCount(int8_t val) override;
uint8_t getChannelsUsed() override; uint8_t getChannelsUsed() override;
@@ -87,4 +91,6 @@ class TrainerChannelRange : public ChannelRange
public: public:
TrainerChannelRange(Window* parent); TrainerChannelRange(Window* parent);
int8_t getChannelsCount() override;
}; };
+7 -1
View File
@@ -242,7 +242,13 @@ void ModuleWindow::updateModule()
// PPM modules // PPM modules
if (isModulePPM(moduleIdx)) { if (isModulePPM(moduleIdx)) {
new PpmSettings(this, grid, moduleIdx); // PPM frame
auto line = newLine(&grid);
new StaticText(line, rect_t{}, STR_PPMFRAME, 0, COLOR_THEME_PRIMARY1);
auto obj = new PpmFrameSettings<PpmModule>(line, &md->ppm);
// copy pointer to frame len edit object to channel range
chRange->setPpmFrameLenEditObject(obj->getPpmFrameLenEditObject());
} }
// Generic module parameters // Generic module parameters
+6 -14
View File
@@ -25,7 +25,7 @@
#define SET_DIRTY() storageDirty(EE_MODEL) #define SET_DIRTY() storageDirty(EE_MODEL)
template <typename T> template <typename T>
PpmFrameSettings<T>::PpmFrameSettings(Window* parent, const FlexGridLayout& g, T* ppm) : PpmFrameSettings<T>::PpmFrameSettings(Window* parent, T* ppm) :
FormGroup(parent, rect_t{}) FormGroup(parent, rect_t{})
{ {
setFlexLayout(LV_FLEX_FLOW_ROW); setFlexLayout(LV_FLEX_FLOW_ROW);
@@ -39,6 +39,9 @@ PpmFrameSettings<T>::PpmFrameSettings(Window* parent, const FlexGridLayout& g, T
edit->setStep(PPM_STEP_SIZE); edit->setStep(PPM_STEP_SIZE);
edit->setSuffix(STR_MS); edit->setSuffix(STR_MS);
// memorize PPM frame length NumberEdit object
this->ppmFrameLenEditObject = edit;
// PPM frame delay // PPM frame delay
edit = new NumberEdit(this, rect_t{}, 100, 800, edit = new NumberEdit(this, rect_t{}, 100, 800,
GET_DEFAULT(ppm->delay * 50 + 300), GET_DEFAULT(ppm->delay * 50 + 300),
@@ -50,17 +53,6 @@ PpmFrameSettings<T>::PpmFrameSettings(Window* parent, const FlexGridLayout& g, T
new Choice(this, rect_t{}, STR_PPM_POL, 0, 1, GET_SET_DEFAULT(ppm->pulsePol)); new Choice(this, rect_t{}, STR_PPM_POL, 0, 1, GET_SET_DEFAULT(ppm->pulsePol));
} }
// explicit instantiation // explicit instantiation to make linker happy
template struct PpmFrameSettings<TrainerModuleData>; template struct PpmFrameSettings<TrainerModuleData>;
template struct PpmFrameSettings<PpmModule>;
PpmSettings::PpmSettings(Window* parent, const FlexGridLayout& g, uint8_t moduleIdx) :
FormGroup(parent, rect_t{}), md(&g_model.moduleData[moduleIdx])
{
FlexGridLayout grid(g);
setFlexLayout();
// PPM frame
auto line = newLine(&grid);
new StaticText(line, rect_t{}, STR_PPMFRAME, 0, COLOR_THEME_PRIMARY1);
new PpmFrameSettings<PpmModule>(line, grid, &md->ppm);
}
+10 -11
View File
@@ -22,18 +22,17 @@
#pragma once #pragma once
#include "form.h" #include "form.h"
#include "numberedit.h"
struct ModuleData;
class PpmSettings : public FormGroup
{
ModuleData* md;
public:
PpmSettings(Window* parent, const FlexGridLayout& g, uint8_t moduleIdx);
};
template <typename T> template <typename T>
struct PpmFrameSettings : public FormGroup { struct PpmFrameSettings : public FormGroup {
PpmFrameSettings(Window* parent, const FlexGridLayout& g, T* ppm); private:
NumberEdit* ppmFrameLenEditObject = nullptr;
public:
PpmFrameSettings(Window* parent, T* ppm);
NumberEdit* getPpmFrameLenEditObject() {
return ppmFrameLenEditObject;
};
}; };
+4 -1
View File
@@ -134,7 +134,10 @@ void TrainerModuleWindow::update()
// PPM frame // PPM frame
line = newLine(&grid); line = newLine(&grid);
new StaticText(line, rect_t{}, STR_PPMFRAME, 0, COLOR_THEME_PRIMARY1); new StaticText(line, rect_t{}, STR_PPMFRAME, 0, COLOR_THEME_PRIMARY1);
new PpmFrameSettings<TrainerModuleData>(line, grid, td); auto obj = new PpmFrameSettings<TrainerModuleData>(line, td);
// copy pointer to frame len edit object to channel range
chRange->setPpmFrameLenEditObject(obj->getPpmFrameLenEditObject());
} }
} }
+6
View File
@@ -788,6 +788,12 @@ inline void setDefaultPpmFrameLength(uint8_t moduleIdx)
4 * max<int>(0, g_model.moduleData[moduleIdx].channelsCount); 4 * max<int>(0, g_model.moduleData[moduleIdx].channelsCount);
} }
inline void setDefaultPpmFrameLengthTrainer()
{
g_model.trainerData.frameLength =
4 * max<int>(0, g_model.trainerData.channelsCount);
}
inline void resetAccessAuthenticationCount() inline void resetAccessAuthenticationCount()
{ {
// the module will reset on mode switch, we need to reset the authentication counter // the module will reset on mode switch, we need to reset the authentication counter