Skip to content

Commit

Permalink
Merge pull request opentx#2832 from opentx/bsongis/#2810_reject_new_s…
Browse files Browse the repository at this point in the history
…ensors

Fixes opentx#2810 - Reject new sensor option
Fixes opentx#2730 - Delete all sensors
  • Loading branch information
kilrah committed Sep 6, 2015
2 parents bd48c47 + 91bd3f0 commit 4b9fcda
Show file tree
Hide file tree
Showing 20 changed files with 262 additions and 86 deletions.
77 changes: 70 additions & 7 deletions companion/src/modeledit/telemetry.ui
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,16 @@
<bool>false</bool>
</property>
<layout class="QGridLayout" name="rssiLayout" columnstretch="0,0,1">
<property name="margin">
<property name="leftMargin">
<number>4</number>
</property>
<property name="topMargin">
<number>4</number>
</property>
<property name="rightMargin">
<number>4</number>
</property>
<property name="bottomMargin">
<number>4</number>
</property>
<item row="2" column="0">
Expand Down Expand Up @@ -269,7 +278,16 @@
<bool>false</bool>
</property>
<layout class="QVBoxLayout" name="A1Layout">
<property name="margin">
<property name="leftMargin">
<number>4</number>
</property>
<property name="topMargin">
<number>4</number>
</property>
<property name="rightMargin">
<number>4</number>
</property>
<property name="bottomMargin">
<number>4</number>
</property>
<item>
Expand All @@ -294,7 +312,16 @@
<bool>false</bool>
</property>
<layout class="QVBoxLayout" name="A2Layout">
<property name="margin">
<property name="leftMargin">
<number>4</number>
</property>
<property name="topMargin">
<number>4</number>
</property>
<property name="rightMargin">
<number>4</number>
</property>
<property name="bottomMargin">
<number>4</number>
</property>
<item>
Expand Down Expand Up @@ -322,7 +349,16 @@
</sizepolicy>
</property>
<layout class="QGridLayout" name="gridLayout_39">
<property name="margin">
<property name="leftMargin">
<number>4</number>
</property>
<property name="topMargin">
<number>4</number>
</property>
<property name="rightMargin">
<number>4</number>
</property>
<property name="bottomMargin">
<number>4</number>
</property>
<property name="spacing">
Expand Down Expand Up @@ -571,7 +607,16 @@
</sizepolicy>
</property>
<layout class="QGridLayout" name="gridLayout_40">
<property name="margin">
<property name="leftMargin">
<number>4</number>
</property>
<property name="topMargin">
<number>4</number>
</property>
<property name="rightMargin">
<number>4</number>
</property>
<property name="bottomMargin">
<number>4</number>
</property>
<property name="spacing">
Expand Down Expand Up @@ -642,7 +687,16 @@
</sizepolicy>
</property>
<layout class="QGridLayout" name="gridLayout_6">
<property name="margin">
<property name="leftMargin">
<number>4</number>
</property>
<property name="topMargin">
<number>4</number>
</property>
<property name="rightMargin">
<number>4</number>
</property>
<property name="bottomMargin">
<number>4</number>
</property>
<property name="spacing">
Expand Down Expand Up @@ -893,7 +947,16 @@
<bool>false</bool>
</property>
<layout class="QGridLayout" name="sensorsLayout" columnstretch="0">
<property name="margin">
<property name="leftMargin">
<number>4</number>
</property>
<property name="topMargin">
<number>4</number>
</property>
<property name="rightMargin">
<number>4</number>
</property>
<property name="bottomMargin">
<number>4</number>
</property>
<item row="1" column="0">
Expand Down
96 changes: 62 additions & 34 deletions radio/src/gui/9X/menu_model_telemetry.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -86,8 +86,10 @@ enum menuModelTelemetryItems {
ITEM_TELEMETRY_SENSOR30,
ITEM_TELEMETRY_SENSOR31,
ITEM_TELEMETRY_SENSOR32,
ITEM_TELEMETRY_NEWSENSOR,
ITEM_TELEMETRY_IGNORE_SENSORID,
ITEM_TELEMETRY_DISCOVER_SENSORS,
ITEM_TELEMETRY_NEW_SENSOR,
ITEM_TELEMETRY_DELETE_ALL_SENSORS,
ITEM_TELEMETRY_IGNORE_SENSOR_INSTANCE,
#endif
#if !defined(CPUARM)
#if defined(FRSKY_HUB) || defined(WS_HOW_HIGH)
Expand Down Expand Up @@ -132,69 +134,69 @@ enum menuModelTelemetryItems {
};

#if defined(FRSKY)
#define TELEM_COL1 INDENT_WIDTH
#define TELEM_COL1 INDENT_WIDTH
#if defined(TRANSLATIONS_FR) || defined(TRANSLATIONS_CZ)
#define TELEM_COL2 (9*FW)
#define TELEM_COL2 (9*FW)
#else
#define TELEM_COL2 (8*FW)
#define TELEM_COL2 (8*FW)
#endif
#define TELEM_BARS_COLMIN (56-3*FW)
#define TELEM_BARS_COLMAX (14*FW-3)
#define TELEM_SCRTYPE_COL TELEM_COL2
#define TELEM_BARS_COLMIN (56-3*FW)
#define TELEM_BARS_COLMAX (14*FW-3)
#define TELEM_SCRTYPE_COL TELEM_COL2

#define IS_RANGE_DEFINED(k) (g_model.frsky.channels[k].ratio > 0)
#define IS_RANGE_DEFINED(k) (g_model.frsky.channels[k].ratio > 0)

#if defined(CPUARM)
#define CHANNELS_ROWS
#define SENSOR_ROWS(x) (isTelemetryFieldAvailable(x) ? (uint8_t)0 : HIDDEN_ROW)
#define SENSORS_ROWS LABEL(Sensors), SENSOR_ROWS(0), SENSOR_ROWS(1), SENSOR_ROWS(2), SENSOR_ROWS(3), SENSOR_ROWS(4), SENSOR_ROWS(5), SENSOR_ROWS(6), SENSOR_ROWS(7), SENSOR_ROWS(8), SENSOR_ROWS(9), SENSOR_ROWS(10), SENSOR_ROWS(11), SENSOR_ROWS(12), SENSOR_ROWS(13), SENSOR_ROWS(14), SENSOR_ROWS(15), SENSOR_ROWS(16), SENSOR_ROWS(17), SENSOR_ROWS(18), SENSOR_ROWS(19), SENSOR_ROWS(20), SENSOR_ROWS(21), SENSOR_ROWS(22), SENSOR_ROWS(23), SENSOR_ROWS(24), SENSOR_ROWS(25), SENSOR_ROWS(26), SENSOR_ROWS(27), SENSOR_ROWS(28), SENSOR_ROWS(29), SENSOR_ROWS(30), SENSOR_ROWS(31), 0, 0,
#define SENSOR_ROWS(x) (isTelemetryFieldAvailable(x) ? (uint8_t)0 : HIDDEN_ROW)
#define SENSORS_ROWS LABEL(Sensors), SENSOR_ROWS(0), SENSOR_ROWS(1), SENSOR_ROWS(2), SENSOR_ROWS(3), SENSOR_ROWS(4), SENSOR_ROWS(5), SENSOR_ROWS(6), SENSOR_ROWS(7), SENSOR_ROWS(8), SENSOR_ROWS(9), SENSOR_ROWS(10), SENSOR_ROWS(11), SENSOR_ROWS(12), SENSOR_ROWS(13), SENSOR_ROWS(14), SENSOR_ROWS(15), SENSOR_ROWS(16), SENSOR_ROWS(17), SENSOR_ROWS(18), SENSOR_ROWS(19), SENSOR_ROWS(20), SENSOR_ROWS(21), SENSOR_ROWS(22), SENSOR_ROWS(23), SENSOR_ROWS(24), SENSOR_ROWS(25), SENSOR_ROWS(26), SENSOR_ROWS(27), SENSOR_ROWS(28), SENSOR_ROWS(29), SENSOR_ROWS(30), SENSOR_ROWS(31), 0, 0, 0, 0,
#else
#define CHANNEL_ROWS(x) LABEL(CHANNEL), 1, 0, 2, 2
#define CHANNELS_ROWS CHANNEL_ROWS(0), CHANNEL_ROWS(1),
#define CHANNEL_ROWS(x) LABEL(CHANNEL), 1, 0, 2, 2
#define CHANNELS_ROWS CHANNEL_ROWS(0), CHANNEL_ROWS(1),
#define SENSORS_ROWS
#endif

#if defined(FAS_OFFSET) || !defined(CPUM64)
#define IF_FAS_OFFSET(x) x,
#define IF_FAS_OFFSET(x) x,
#else
#define IF_FAS_OFFSET(x)
#endif

#if defined(CPUARM)
#define USRDATA_ROWS
#elif defined(FRSKY_HUB) || defined(WS_HOW_HIGH)
#define USRDATA_ROWS LABEL(UsrData), 0, 0, 0, 0, IF_FAS_OFFSET(0)
#define USRDATA_ROWS LABEL(UsrData), 0, 0, 0, 0, IF_FAS_OFFSET(0)
#else
#define USRDATA_ROWS 0, 0, IF_FAS_OFFSET(0)
#define USRDATA_ROWS 0, 0, IF_FAS_OFFSET(0)
#endif

#define RSSI_ROWS LABEL(RSSI), 1, 1,
#define RSSI_ROWS LABEL(RSSI), 1, 1,

#if defined(CPUARM) || defined(GAUGES)
#define SCREEN_TYPE_ROWS 0
#define SCREEN_TYPE_ROWS 0
#else
#define SCREEN_TYPE_ROWS LABEL(SCREEN)
#define SCREEN_TYPE_ROWS LABEL(SCREEN)
#endif

#if defined(PCBSTD)
#define VARIO_RANGE_ROWS 1
#define VARIO_RANGE_ROWS 1
#else
#define VARIO_RANGE_ROWS 3
#define VARIO_RANGE_ROWS 3
#endif

#if defined(CPUARM)
#define TELEMETRY_TYPE_ROWS 0,
#define TELEMETRY_TYPE_ROWS 0,
#else
#define TELEMETRY_TYPE_ROWS
#endif

#if defined(CPUARM)
#define TELEMETRY_SCREEN_LINE(x) (TELEMETRY_SCREEN_TYPE(x) == TELEMETRY_SCREEN_TYPE_NONE ? HIDDEN_ROW : (uint8_t)2)
#define TELEMETRY_SCREEN_ROWS(x) SCREEN_TYPE_ROWS, TELEMETRY_SCREEN_LINE(x), TELEMETRY_SCREEN_LINE(x), TELEMETRY_SCREEN_LINE(x), TELEMETRY_SCREEN_LINE(x)
#define TELEMETRY_CURRENT_EDIT_SCREEN(k) (k < ITEM_TELEMETRY_SCREEN_LABEL2 ? 0 : (k < ITEM_TELEMETRY_SCREEN_LABEL3 ? 1 : (k < ITEM_TELEMETRY_SCREEN_LABEL4 ? 2 : 3)))
#define TELEMETRY_SCREEN_LINE(x) (TELEMETRY_SCREEN_TYPE(x) == TELEMETRY_SCREEN_TYPE_NONE ? HIDDEN_ROW : (uint8_t)2)
#define TELEMETRY_SCREEN_ROWS(x) SCREEN_TYPE_ROWS, TELEMETRY_SCREEN_LINE(x), TELEMETRY_SCREEN_LINE(x), TELEMETRY_SCREEN_LINE(x), TELEMETRY_SCREEN_LINE(x)
#define TELEMETRY_CURRENT_SCREEN(k) (k < ITEM_TELEMETRY_SCREEN_LABEL2 ? 0 : (k < ITEM_TELEMETRY_SCREEN_LABEL3 ? 1 : (k < ITEM_TELEMETRY_SCREEN_LABEL4 ? 2 : 3)))
#else
#define TELEMETRY_SCREEN_ROWS(x) SCREEN_TYPE_ROWS, 2, 2, 2, 2
#define TELEMETRY_CURRENT_EDIT_CHANNEL(k) (k >= ITEM_TELEMETRY_A2_LABEL ? TELEM_ANA_A2 : TELEM_ANA_A1)
#define TELEMETRY_SCREEN_ROWS(x) SCREEN_TYPE_ROWS, 2, 2, 2, 2
#define TELEMETRY_CURRENT_CHANNEL(k) (k >= ITEM_TELEMETRY_A2_LABEL ? TELEM_ANA_A2 : TELEM_ANA_A1)
#endif

#if defined(CPUARM)
Expand Down Expand Up @@ -497,7 +499,7 @@ void onSensorMenu(const char *result)
if (index<MAX_SENSORS && isTelemetryFieldAvailable(index))
m_posVert += 1;
else
m_posVert = 1+ITEM_TELEMETRY_NEWSENSOR;
m_posVert = 1+ITEM_TELEMETRY_NEW_SENSOR;
}
else if (result == STR_COPY) {
int newIndex = availableTelemetryIndex();
Expand All @@ -521,6 +523,15 @@ void onSensorMenu(const char *result)

void menuModelTelemetry(uint8_t event)
{
#if defined(CPUARM)
if (s_warning_result) {
s_warning_result = 0;
for (int i=0; i<MAX_SENSORS; i++) {
delTelemetryIndex(i);
}
}
#endif

MENU(STR_MENUTELEMETRY, menuTabModel, e_Telemetry, ITEM_TELEMETRY_MAX+1, {0, TELEMETRY_TYPE_ROWS CHANNELS_ROWS RSSI_ROWS SENSORS_ROWS USRDATA_ROWS CASE_VARIO(LABEL(Vario)) CASE_VARIO(0) CASE_VARIO(VARIO_RANGE_ROWS) TELEMETRY_SCREEN_ROWS(0), TELEMETRY_SCREEN_ROWS(1), CASE_CPUARM(TELEMETRY_SCREEN_ROWS(2)) CASE_CPUARM(TELEMETRY_SCREEN_ROWS(3))});

uint8_t sub = m_posVert - 1;
Expand Down Expand Up @@ -549,7 +560,7 @@ void menuModelTelemetry(uint8_t event)
uint8_t attr = (sub == k ? blink : 0);

#if !defined(CPUARM)
uint8_t ch = TELEMETRY_CURRENT_EDIT_CHANNEL(k);
uint8_t ch = TELEMETRY_CURRENT_CHANNEL(k);
FrSkyChannelData & channel = g_model.frsky.channels[ch];
uint8_t dest = TELEM_A1-1+ch;
#endif
Expand Down Expand Up @@ -604,7 +615,15 @@ void menuModelTelemetry(uint8_t event)
lcd_putsLeft(y, STR_TELEMETRY_SENSORS);
break;

case ITEM_TELEMETRY_NEWSENSOR:
case ITEM_TELEMETRY_DISCOVER_SENSORS:
lcd_putsAtt(0, y, allowNewSensors ? STR_STOP_DISCOVER_SENSORS : STR_DISCOVER_SENSORS, attr);
if (attr && event==EVT_KEY_BREAK(KEY_ENTER)) {
s_editMode = 0;
allowNewSensors = !allowNewSensors;
}
break;

case ITEM_TELEMETRY_NEW_SENSOR:
lcd_putsAtt(0, y, STR_TELEMETRY_NEWSENSOR, attr);
if (attr && event==EVT_KEY_BREAK(KEY_ENTER)) {
s_editMode = 0;
Expand All @@ -618,9 +637,18 @@ void menuModelTelemetry(uint8_t event)
}
}
break;

case ITEM_TELEMETRY_IGNORE_SENSORID:
ON_OFF_MENU_ITEM(g_model.ignoreSensorIds, TELEM_COL2, y, STR_IGNOREIDS, attr, event);

case ITEM_TELEMETRY_DELETE_ALL_SENSORS:
lcd_putsAtt(0, y, STR_DELETE_ALL_SENSORS, attr);
s_editMode = 0;
if (attr && event==EVT_KEY_LONG(KEY_ENTER)) {
killEvents(KEY_ENTER);
POPUP_CONFIRMATION(STR_CONFIRMDELETE);
}
break;

case ITEM_TELEMETRY_IGNORE_SENSOR_INSTANCE:
ON_OFF_MENU_ITEM(g_model.ignoreSensorIds, TELEM_COL2, y, STR_IGNORE_INSTANCE, attr, event);
break;
#endif

Expand Down Expand Up @@ -830,7 +858,7 @@ void menuModelTelemetry(uint8_t event)
case ITEM_TELEMETRY_SCREEN_LABEL3:
case ITEM_TELEMETRY_SCREEN_LABEL4:
{
uint8_t screenIndex = TELEMETRY_CURRENT_EDIT_SCREEN(k);
uint8_t screenIndex = TELEMETRY_CURRENT_SCREEN(k);
putsStrIdx(0*FW, y, STR_SCREEN, screenIndex+1);
TelemetryScreenType oldScreenType = TELEMETRY_SCREEN_TYPE(screenIndex);
TelemetryScreenType newScreenType = (TelemetryScreenType)selectMenuItem(TELEM_SCRTYPE_COL, y, PSTR(""), STR_VTELEMSCREENTYPE, oldScreenType, 0, TELEMETRY_SCREEN_TYPE_MAX, (m_posHorz==0 ? attr : 0), event);
Expand Down
Loading

0 comments on commit 4b9fcda

Please sign in to comment.