feat: More flexible ADC inputs (#3870)

Co-authored-by: 3djc <lesitewebdejc@hotmail.com>
Co-authored-by: Peter Feerick <peter.feerick@gmail.com>
Co-authored-by: philmoz <phil.a.mitchell@gmail.com>
This commit is contained in:
Raphael Coeffic
2023-11-02 11:07:53 +10:00
committed by GitHub
co-authored by 3djc Peter Feerick philmoz
parent f5593c44e8
commit b48e07026d
78 changed files with 1291 additions and 773 deletions
+3 -3
View File
@@ -51,7 +51,7 @@ QVector<QIODevice *> OpenTxSimulator::tracebackDevices;
uint16_t simu_get_analog(uint8_t idx)
{
// 6POS simu mechanism use a different scale, so needs specific offset
if (IS_POT_MULTIPOS(idx - adcGetInputOffset(ADC_INPUT_POT))) {
if (IS_POT_MULTIPOS(idx - adcGetInputOffset(ADC_INPUT_FLEX))) {
// Use radio calibration data to determine conversion factor
StepsCalibData * calib = (StepsCalibData *) &g_eeGeneral.calib[idx];
int range6POS = 2048; // Default if calibration is not valid
@@ -256,11 +256,11 @@ void OpenTxSimulator::setInputValue(int type, uint8_t index, int16_t value)
setAnalogValue(index, value);
break;
case INPUT_SRC_KNOB :
setAnalogValue(index + adcGetInputOffset(ADC_INPUT_POT), value);
setAnalogValue(index + adcGetInputOffset(ADC_INPUT_FLEX), value);
break;
case INPUT_SRC_SLIDER :
// TODO redo this when Companion refactored to use radio json adc files
//setAnalogValue(index + adcGetInputOffset(ADC_INPUT_POT), value);
//setAnalogValue(index + adcGetInputOffset(ADC_INPUT_FLEX), value);
static const int slideroffset = adcGetInputIdx("SL1", 3);
//qDebug() << "SL1:" << slideroffset;
if (slideroffset >= 0)
+44 -76
View File
@@ -33,92 +33,36 @@ struct hw_switch_def {
#include "simu_switches.inc"
int8_t switchesStates[n_total_switches] = { -1 };
int8_t switchesStates[MAX_SWITCHES] = { -1 };
void simuSetSwitch(uint8_t swtch, int8_t state)
{
assert(swtch < n_total_switches);
assert(swtch < switchGetMaxSwitches() + switchGetMaxFctSwitches());
switchesStates[swtch] = state;
}
swconfig_t switchGetDefaultConfig()
void boardInitSwitches() {}
static uint8_t get_switch_index(uint8_t cat, uint8_t idx)
{
return _switch_default_config;
switch(cat) {
case SWITCH_PHYSICAL:
assert(idx < n_switches);
return idx;
case SWITCH_FUNCTION:
assert(idx < n_fct_switches);
return idx + n_switches;
default:
assert(0);
return 0;
}
}
switch_display_pos_t switchGetDisplayPosition(uint8_t idx)
SwitchHwPos boardSwitchGetPosition(uint8_t cat, uint8_t idx)
{
if (idx >= DIM(_switch_display))
return {0, 0};
return _switch_display[idx];
}
uint8_t switchGetMaxSwitches()
{
return n_switches;
}
uint8_t getSwitchCount()
{
int count = 0;
for (int i = 0; i < switchGetMaxSwitches(); ++i) {
if (SWITCH_EXISTS(i)) {
++count;
}
}
return count;
}
uint8_t switchGetMaxRow(uint8_t col)
{
uint8_t lastrow = 0;
for (int i = 0; i < switchGetMaxSwitches(); ++i) {
if (SWITCH_EXISTS(i)) {
auto switch_display = switchGetDisplayPosition(i);
if (switch_display.col == col)
lastrow = switch_display.row > lastrow ? switch_display.row : lastrow;
}
}
return lastrow;
}
uint8_t switchGetMaxFctSwitches()
{
return n_fct_switches;
}
const char* switchGetName(uint8_t idx)
{
assert(idx < n_total_switches);
return _hw_switch_defs[idx].name;
}
SwitchHwType switchGetHwType(uint8_t idx)
{
assert(idx < n_total_switches);
return _hw_switch_defs[idx].type;
}
uint32_t switchState(uint8_t pos)
{
assert(pos < n_total_switches * 3);
div_t qr = div(pos, 3);
int state = switchesStates[qr.quot];
switch (qr.rem) {
case SWITCH_HW_UP:
return state < 0;
case SWITCH_HW_DOWN:
return state > 0;
default:
return state == 0;
}
}
SwitchHwPos switchGetPosition(uint8_t idx)
{
assert(idx < n_total_switches);
idx = get_switch_index(cat, idx);
if (switchesStates[idx] < 0)
return SWITCH_HW_UP;
@@ -127,3 +71,27 @@ SwitchHwPos switchGetPosition(uint8_t idx)
else
return SWITCH_HW_DOWN;
}
const char* boardSwitchGetName(uint8_t cat, uint8_t idx)
{
idx = get_switch_index(cat, idx);
return _switch_defs[idx].name;
}
SwitchHwType boardSwitchGetType(uint8_t cat, uint8_t idx)
{
idx = get_switch_index(cat, idx);
return _switch_defs[idx].type;
}
uint8_t boardGetMaxSwitches() { return n_switches; }
uint8_t boardGetMaxFctSwitches() { return n_fct_switches; }
swconfig_t boardSwitchGetDefaultConfig() { return _switch_default_config; }
switch_display_pos_t switchGetDisplayPosition(uint8_t idx)
{
if (idx >= DIM(_switch_display)) return {0, 0};
return _switch_display[idx];
}