1
0
Fork 0
mirror of https://github.com/opentx/opentx.git synced 2025-07-21 15:25:17 +03:00

#1761 - Radio part done

This commit is contained in:
bsongis 2014-12-08 19:11:49 +01:00
parent 9dd572c191
commit a9e64c3603
14 changed files with 210 additions and 159 deletions

View file

@ -173,6 +173,10 @@ PPM_UNIT = PERCENT_PREC1
# Values = YES, NO
OVERRIDE_CHANNEL_FUNCTION = YES
# Dangerous functions available in Custom Functions (range test, bind, module off)
# Values = YES, NO
DANGEROUS_MODULE_FUNCTIONS = NO
# FrSky Hub
# Values = YES, NO
FRSKY_HUB = YES
@ -1108,6 +1112,10 @@ ifeq ($(OVERRIDE_CHANNEL_FUNCTION), YES)
CPPDEFS += -DOVERRIDE_CHANNEL_FUNCTION
endif
ifeq ($(DANGEROUS_MODULE_FUNCTIONS), YES)
CPPDEFS += -DDANGEROUS_MODULE_FUNCTIONS
endif
ifeq ($(PPM_UNIT), US)
CPPDEFS += -DPPM_UNIT_US
endif

View file

@ -364,6 +364,19 @@ void evalFunctions()
}
#endif
#if defined(DANGEROUS_MODULE_FUNCTIONS)
case FUNC_RANGECHECK:
case FUNC_BIND:
case FUNC_MODULE_OFF:
{
unsigned int moduleIndex = CFN_PARAM(cfn);
if (moduleIndex < NUM_MODULES) {
moduleFlag[moduleIndex] = 1 + CFN_FUNC(cfn) - FUNC_RANGECHECK;
}
break;
}
#endif
#if defined(GVARS)
case FUNC_ADJUST_GVAR:
if (CFN_GVAR_MODE(cfn) == 0) {

View file

@ -601,9 +601,4 @@ void menuMainView(uint8_t event)
lcd_outdezAtt(BITMAP_X+5*FW+FW/2, BITMAP_Y+2*FH+3, GVAR_VALUE(s_gvar_last, getGVarFlightPhase(mixerCurrentFlightMode, s_gvar_last)), BOLD);
}
#endif
#if defined(DSM2)
if (dsm2Flag == DSM2_BIND_FLAG) // Issue 98
lcd_putsAtt(15*FW, 0, PSTR("BIND"), 0);
#endif
}

View file

@ -1048,17 +1048,14 @@ void menuModelSetup(uint8_t event)
MENU_CHECK(menuTabModel, e_ModelSetup, MODEL_SETUP_MAX_LINES);
#if defined(DSM2) || defined(PXX)
if (menuEvent) {
#if defined(DSM2)
dsm2Flag = 0;
#endif
#if defined(PCBTARANIS)
pxxFlag[INTERNAL_MODULE] = 0;
#endif
#if defined(CPUARM) && defined(PXX)
pxxFlag[EXTERNAL_MODULE] = 0;
moduleFlag[0] = 0;
#if NUM_MODULES > 1
moduleFlag[1] = 0;
#endif
}
#endif
TITLE(STR_MENUSETUP);
@ -1671,32 +1668,15 @@ void menuModelSetup(uint8_t event)
}
lcd_putsAtt(MODEL_SETUP_2ND_COLUMN+xOffsetBind, y, STR_MODULE_BIND, l_posHorz==1 ? attr : 0);
lcd_putsAtt(MODEL_SETUP_2ND_COLUMN+MODEL_SETUP_RANGE_OFS+xOffsetBind, y, STR_MODULE_RANGE, l_posHorz==2 ? attr : 0);
if (IS_MODULE_XJT(moduleIdx)) {
#if defined(PXX)
uint8_t newFlag = 0;
if (attr && l_posHorz>0 && s_editMode>0) {
if (l_posHorz == 1)
newFlag = PXX_SEND_RXNUM;
newFlag = MODULE_BIND;
else if (l_posHorz == 2) {
newFlag = PXX_SEND_RANGECHECK;
newFlag = MODULE_RANGECHECK;
}
}
pxxFlag[moduleIdx] = newFlag;
#endif
}
#if defined(DSM2)
else {
uint8_t newFlag = 0;
if (attr && l_posHorz>0 && s_editMode>0) {
if (l_posHorz == 1)
newFlag = DSM2_BIND_FLAG;
else if (l_posHorz == 2) {
newFlag = DSM2_RANGECHECK_FLAG;
}
}
dsm2Flag = newFlag;
}
#endif
moduleFlag[moduleIdx] = newFlag;
}
}
break;
@ -1851,7 +1831,7 @@ void menuModelSetup(uint8_t event)
// send reset code
newFlag = PXX_SEND_RXNUM;
}
pxxFlag[0] = newFlag;
moduleFlag[0] = newFlag;
}
#endif
#if defined(DSM2)
@ -1868,7 +1848,7 @@ void menuModelSetup(uint8_t event)
}
#if defined(CPUARM) && defined(PXX)
if (IS_PXX_RANGE_CHECK_ENABLE()) {
if (IS_RANGECHECK_ENABLE()) {
displayPopup("RSSI: ");
lcd_outdezAtt(16+4*FW, 5*FH, TELEMETRY_RSSI(), BOLD);
}
@ -5323,6 +5303,12 @@ void menuCustomFunctions(uint8_t event, CustomFunctionData * functions, CustomFu
lcd_outdezAtt(MODEL_CUSTOM_FUNC_3RD_COLUMN, y, val_displayed, attr|LEFT);
}
#endif
#if defined(DANGEROUS_MODULE_FUNCTIONS)
else if (func >= FUNC_RANGECHECK && func <= FUNC_MODULE_OFF) {
val_max = NUM_MODULES-1;
lcd_putsiAtt(MODEL_CUSTOM_FUNC_3RD_COLUMN, y, "\004Int.Ext.", CFN_PARAM(cfn), attr);
}
#endif
#if defined(CPUARM)
else if (func == FUNC_SET_TIMER) {
val_max = 59*60+59;

View file

@ -1624,9 +1624,11 @@ bool isAssignableFunctionAvailable(int function)
case FUNC_HAPTIC:
#endif
case FUNC_PLAY_DIFF:
case FUNC_RESERVE1:
case FUNC_RESERVE2:
case FUNC_RESERVE3:
#if !defined(DANGEROUS_MODULE_FUNCTIONS)
case FUNC_RANGECHECK:
case FUNC_BIND:
case FUNC_MODULE_OFF:
#endif
#if !defined(LUA)
case FUNC_PLAY_SCRIPT:
#endif

View file

@ -577,7 +577,9 @@ void menuMainView(uint8_t event)
#endif
#if defined(DSM2)
if (dsm2Flag == DSM2_BIND_FLAG) // Issue 98
if (dsm2BindEnable) {
// Issue 98
lcd_putsAtt(15*FW, 0, PSTR("BIND"), 0);
}
#endif
}

View file

@ -454,11 +454,10 @@ enum Functions {
FUNC_ADJUST_GVAR,
#if defined(CPUARM)
FUNC_VOLUME,
FUNC_RESERVE1,
FUNC_RESERVE2,
FUNC_RESERVE3,
FUNC_RANGECHECK,
FUNC_BIND,
FUNC_MODULE_OFF,
#endif
// then the other functions
FUNC_FIRST_WITHOUT_ENABLE,
FUNC_PLAY_SOUND = FUNC_FIRST_WITHOUT_ENABLE,

View file

@ -97,14 +97,6 @@ uint16_t maxMixerDuration;
audioQueue audio;
#endif
#if defined(DSM2)
// TODO move elsewhere
uint8_t dsm2Flag = 0;
#if !defined(PCBTARANIS)
uint8_t s_bind_allowed = 255;
#endif
#endif
uint8_t heartbeat;
uint8_t stickMode;
@ -1903,23 +1895,13 @@ void doMixerCalculations()
}
}
#if defined(DSM2)
static uint8_t count_dsm_range = 0;
if (dsm2Flag & (DSM2_BIND_FLAG | DSM2_RANGECHECK_FLAG)) {
if (++count_dsm_range >= 200) {
#if defined(PXX) || defined(DSM2)
static uint8_t countRangecheck = 0;
for (uint8_t i=0; i<NUM_MODULES; ++i) {
if (moduleFlag[i] != MODULE_NORMAL_MODE) {
if (++countRangecheck >= 250) {
countRangecheck = 0;
AUDIO_PLAY(AU_FRSKY_CHEEP);
count_dsm_range = 0;
}
}
#endif
#if defined(PXX)
static uint8_t count_pxx = 0;
for (uint8_t i = 0; i < NUM_MODULES; i++) {
if (pxxFlag[i] & (PXX_SEND_RANGECHECK | PXX_SEND_RXNUM)) {
if (++count_pxx >= 250) {
AUDIO_PLAY(AU_FRSKY_CHEEP);
count_pxx = 0;
}
}
}

View file

@ -440,11 +440,7 @@ enum PotType {
#include "eeprom_rlc.h"
#endif
#if defined(CPUARM)
#include "pulses/pulses_arm.h"
#else
#include "pulses/pulses_avr.h"
#endif
#include "pulses/pulses.h"
#if defined(PCBTARANIS)
#define BITMAP_BUFFER_SIZE(width, height) (2 + width * ((height+7)/8)*4)
@ -465,40 +461,6 @@ enum PotType {
#define LOAD_MODEL_CURVES()
#endif
// TODO elsewhere ...
#if defined(DSM2)
#define DSM2_BIND_FLAG 0x80
#define DSM2_RANGECHECK_FLAG 0x20
extern uint8_t dsm2Flag;
#if !defined(PCBTARANIS)
extern uint8_t s_bind_allowed;
#endif
#endif
#if defined(CPUARM)
#define IS_PPM_PROTOCOL(protocol) (protocol==PROTO_PPM)
#else
#define IS_PPM_PROTOCOL(protocol) (protocol<=PROTO_PPMSIM)
#endif
#if defined(PXX)
#define IS_PXX_PROTOCOL(protocol) (protocol==PROTO_PXX)
#else
#define IS_PXX_PROTOCOL(protocol) (0)
#endif
#if defined(DSM2)
#define IS_DSM2_PROTOCOL(protocol) (protocol>=PROTO_DSM2_LP45 && protocol<=PROTO_DSM2_DSMX)
#else
#define IS_DSM2_PROTOCOL(protocol) (0)
#endif
#if defined(DSM2_SERIAL)
#define IS_DSM2_SERIAL_PROTOCOL(protocol) (IS_DSM2_PROTOCOL(protocol))
#else
#define IS_DSM2_SERIAL_PROTOCOL(protocol) (0)
#endif
#if defined(CPUARM)
static const int8_t maxChannelsModules[] = { 0, 8, 8, -2 }; // relative to 8!
static const int8_t maxChannelsXJT[] = { 0, 8, 0, 4 }; // relative to 8!
@ -517,7 +479,6 @@ enum PotType {
#define MAX_INTERNAL_MODULE_CHANNELS() (maxChannelsXJT[1+g_model.moduleData[INTERNAL_MODULE].rfProtocol])
#define MAX_EXTERNAL_MODULE_CHANNELS() ((g_model.externalModule == MODULE_TYPE_XJT) ? maxChannelsXJT[1+g_model.moduleData[1].rfProtocol] : maxChannelsModules[g_model.externalModule])
#define MAX_CHANNELS(idx) (idx==INTERNAL_MODULE ? MAX_INTERNAL_MODULE_CHANNELS() : (idx==EXTERNAL_MODULE ? MAX_EXTERNAL_MODULE_CHANNELS() : MAX_TRAINER_CHANNELS()))
#define IS_PXX_RANGE_CHECK_ENABLE() (pxxFlag[INTERNAL_MODULE] == PXX_SEND_RANGECHECK || pxxFlag[EXTERNAL_MODULE] == PXX_SEND_RANGECHECK)
#elif defined(PCBSKY9X) && !defined(REVA) && !defined(REVX)
#define IS_MODULE_PPM(idx) (idx==TRAINER_MODULE || idx==EXTRA_MODULE || (idx==EXTERNAL_MODULE && g_model.externalModule==MODULE_TYPE_PPM))
#define IS_MODULE_XJT(idx) (idx==EXTERNAL_MODULE && g_model.externalModule==MODULE_TYPE_XJT)
@ -525,14 +486,12 @@ enum PotType {
#define MAX_EXTERNAL_MODULE_CHANNELS() ((g_model.externalModule == MODULE_TYPE_XJT) ? maxChannelsXJT[1+g_model.moduleData[0].rfProtocol] : maxChannelsModules[g_model.externalModule])
#define MAX_EXTRA_MODULE_CHANNELS() (0) // Only PPM
#define MAX_CHANNELS(idx) (idx==EXTERNAL_MODULE ? MAX_EXTERNAL_MODULE_CHANNELS() : (idx==EXTRA_MODULE ? MAX_EXTRA_MODULE_CHANNELS() : MAX_TRAINER_CHANNELS()))
#define IS_PXX_RANGE_CHECK_ENABLE() (pxxFlag[EXTERNAL_MODULE] == PXX_SEND_RANGECHECK)
#else
#define IS_MODULE_PPM(idx) (idx==TRAINER_MODULE || (idx==EXTERNAL_MODULE && g_model.externalModule==MODULE_TYPE_PPM))
#define IS_MODULE_XJT(idx) (idx==EXTERNAL_MODULE && g_model.externalModule==MODULE_TYPE_XJT)
#define IS_MODULE_DSM2(idx) (idx==EXTERNAL_MODULE && g_model.externalModule==MODULE_TYPE_DSM2)
#define MAX_EXTERNAL_MODULE_CHANNELS() ((g_model.externalModule == MODULE_TYPE_XJT) ? maxChannelsXJT[1+g_model.moduleData[EXTERNAL_MODULE].rfProtocol] : maxChannelsModules[g_model.externalModule])
#define MAX_CHANNELS(idx) (idx==EXTERNAL_MODULE ? MAX_EXTERNAL_MODULE_CHANNELS() : MAX_TRAINER_CHANNELS())
#define IS_PXX_RANGE_CHECK_ENABLE() (pxxFlag[EXTERNAL_MODULE] == PXX_SEND_RANGECHECK)
#endif
#include "lcd.h"
@ -626,14 +585,6 @@ struct t_inactivity
extern struct t_inactivity inactivity;
#if defined(PXX)
extern uint8_t pxxFlag[NUM_MODULES];
#endif
#define PXX_SEND_RXNUM 0x01
#define PXX_SEND_FAILSAFE (1 << 4)
#define PXX_SEND_RANGECHECK (1 << 5)
#define LEN_STD_CHARS 40
#if defined(TRANSLATIONS_CZ)

View file

@ -36,6 +36,9 @@
#include "../opentx.h"
#define DSM2_SEND_BIND (1 << 7)
#define DSM2_SEND_RANGECHECK (1 << 5)
#if defined(PCBTARANIS)
uint16_t dsm2Stream[400]; // Likely more than we need
uint16_t *dsm2StreamPtr;
@ -45,6 +48,8 @@ uint8_t dsm2Stream[64]; // Likely more than we need
uint8_t *dsm2StreamPtr;
uint8_t dsm2SerialByte ;
uint8_t dsm2SerialBitCount;
uint8_t dsm2BindEnable = 0;
uint8_t dsm2BindTimer = DSM2_BIND_TIMEOUT;
#endif
// DSM2 control bits
@ -159,15 +164,22 @@ void setupPulsesDSM2(unsigned int port)
break;
}
#if !defined(PCBTARANIS)
if (s_bind_allowed) s_bind_allowed--;
if (s_bind_allowed && switchState(SW_DSM2_BIND))
dsm2Flag = DSM2_BIND_FLAG;
else
dsm2Flag &= ~DSM2_BIND_FLAG;
#if defined(PCBTARANIS)
if (moduleFlag[port] == MODULE_BIND)
dsmDat[0] |= DSM2_SEND_BIND;
else if (moduleFlag[port] == MODULE_RANGECHECK)
dsmDat[0] |= DSM2_SEND_RANGECHECK;
#else
dsm2BindEnable = 0;
if (dsm2BindTimer > 0) {
dsm2BindTimer--;
if (switchState(SW_DSM2_BIND)) {
dsm2BindEnable = DSM2_SEND_BIND;
dsmDat[0] |= DSM2_SEND_BIND;
}
}
#endif
dsmDat[0] |= dsm2Flag;
dsmDat[1] = g_model.header.modelId; // DSM2 Header second byte for model match
for (int i=0; i<DSM2_CHANS; i++) {

94
radio/src/pulses/pulses.h Executable file
View file

@ -0,0 +1,94 @@
/*
* Authors (alphabetical order)
* - Andre Bernet <bernet.andre@gmail.com>
* - Andreas Weitl
* - Bertrand Songis <bsongis@gmail.com>
* - Bryan J. Rentoul (Gruvin) <gruvin@gmail.com>
* - Cameron Weeks <th9xer@gmail.com>
* - Erez Raviv
* - Gabriel Birkus
* - Jean-Pierre Parisy
* - Karl Szmutny
* - Michael Blandford
* - Michal Hlavinka
* - Pat Mackenzie
* - Philip Moss
* - Rob Thomson
* - Romolo Manfredini <romolo.manfredini@gmail.com>
* - Thomas Husterer
*
* opentx is based on code named
* gruvin9x by Bryan J. Rentoul: http://code.google.com/p/gruvin9x/,
* er9x by Erez Raviv: http://code.google.com/p/er9x/,
* and the original (and ongoing) project by
* Thomas Husterer, th9x: http://code.google.com/p/th9x/
*
* 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.
*
*/
#ifndef PULSES_COMMON_H
#define PULSES_COMMON_H
enum ModuleFlag
{
MODULE_NORMAL_MODE,
MODULE_RANGECHECK,
MODULE_BIND,
MODULE_OFF,
};
#if defined(CPUARM) // (PXX) || defined(DSM2)
extern uint8_t moduleFlag[NUM_MODULES];
#endif
#if NUM_MODULES > 1
#define IS_RANGECHECK_ENABLE() (moduleFlag[0] == MODULE_RANGECHECK || moduleFlag[1] == MODULE_RANGECHECK)
#else
#define IS_RANGECHECK_ENABLE() (moduleFlag[0] == MODULE_RANGECHECK)
#endif
#if defined(DSM2) && !defined(PCBTARANIS)
#define DSM2_BIND_TIMEOUT 255 // 255*11ms
extern uint8_t dsm2BindTimer;
extern uint8_t dsm2BindEnable; // needed to display BIND on screen
#endif
#if defined(CPUARM)
#define IS_PPM_PROTOCOL(protocol) (protocol==PROTO_PPM)
#else
#define IS_PPM_PROTOCOL(protocol) (protocol<=PROTO_PPMSIM)
#endif
#if defined(PXX)
#define IS_PXX_PROTOCOL(protocol) (protocol==PROTO_PXX)
#else
#define IS_PXX_PROTOCOL(protocol) (0)
#endif
#if defined(DSM2)
#define IS_DSM2_PROTOCOL(protocol) (protocol>=PROTO_DSM2_LP45 && protocol<=PROTO_DSM2_DSMX)
#else
#define IS_DSM2_PROTOCOL(protocol) (0)
#endif
#if defined(DSM2_SERIAL)
#define IS_DSM2_SERIAL_PROTOCOL(protocol) (IS_DSM2_PROTOCOL(protocol))
#else
#define IS_DSM2_SERIAL_PROTOCOL(protocol) (0)
#endif
#if defined(CPUARM)
#include "pulses_arm.h"
#else
#include "pulses_avr.h"
#endif
#endif

View file

@ -39,6 +39,7 @@
uint8_t s_pulses_paused = 0;
uint8_t s_current_protocol[NUM_MODULES] = { MODULES_INIT(255) };
uint32_t failsafeCounter[NUM_MODULES] = { MODULES_INIT(100) };
uint8_t moduleFlag[NUM_MODULES] = { 0 };
void setupPulses(unsigned int port)
{
@ -62,13 +63,13 @@ void setupPulses(unsigned int port)
case MODULE_TYPE_XJT:
required_protocol = PROTO_PXX;
break;
#if defined(DSM2)
#if defined(PCBTARANIS) && defined(DSM2)
case MODULE_TYPE_DSM2:
required_protocol = limit<uint8_t>(PROTO_DSM2_LP45, PROTO_DSM2_LP45+g_model.moduleData[EXTERNAL_MODULE].rfProtocol, PROTO_DSM2_DSMX);
// The module is set to OFF during one second before BIND start
{
static tmr10ms_t bindStartTime = 0;
if (dsm2Flag == DSM2_BIND_FLAG) {
if (moduleFlag[EXTERNAL_MODULE] == MODULE_BIND) {
if (bindStartTime == 0) bindStartTime = get_tmr10ms();
if ((tmr10ms_t)(get_tmr10ms() - bindStartTime) < 100) {
required_protocol = PROTO_NONE;
@ -92,6 +93,10 @@ void setupPulses(unsigned int port)
required_protocol = PROTO_NONE;
}
if (moduleFlag[port] == MODULE_OFF) {
required_protocol = PROTO_NONE;
}
if (s_current_protocol[port] != required_protocol) {
switch (s_current_protocol[port]) { // stop existing protocol hardware

View file

@ -233,7 +233,7 @@ uint8_t PcmByte ;
uint8_t PcmBitCount ;
uint16_t PcmCrc ;
uint8_t PcmOnesCount ;
uint8_t pxxFlag[NUM_MODULES] = { 0 };
uint8_t moduleFlag[NUM_MODULES] = { 0 };
void crc( uint8_t data )
{

View file

@ -36,7 +36,9 @@
#include "../opentx.h"
uint8_t pxxFlag[NUM_MODULES] = { MODULES_INIT(0) };
#define PXX_SEND_BIND 0x01
#define PXX_SEND_FAILSAFE (1 << 4)
#define PXX_SEND_RANGECHECK (1 << 5)
#if defined(PCBTARANIS)
uint16_t pxxStream[NUM_MODULES][400];
@ -205,13 +207,14 @@ void setupPulsesPXX(unsigned int port)
putPcmByte(g_model.header.modelId, port);
/* FLAG1 */
uint8_t flag1;
if (pxxFlag[port] & PXX_SEND_RXNUM) {
flag1 = (g_model.moduleData[port].rfProtocol << 6) | (g_eeGeneral.countryCode << 1) | pxxFlag[port];
uint8_t flag1 = (g_model.moduleData[port].rfProtocol << 6);
if (moduleFlag[port] == MODULE_BIND) {
flag1 |= (g_eeGeneral.countryCode << 1) | PXX_SEND_BIND;
}
else {
flag1 = (g_model.moduleData[port].rfProtocol << 6) | pxxFlag[port];
if (g_model.moduleData[port].failsafeMode != FAILSAFE_RECEIVER) {
else if (moduleFlag[port] == MODULE_RANGECHECK) {
flag1 |= PXX_SEND_RANGECHECK;
}
else if (g_model.moduleData[port].failsafeMode != FAILSAFE_RECEIVER) {
if (failsafeCounter[port]-- == 0) {
failsafeCounter[port] = 1000;
flag1 |= PXX_SEND_FAILSAFE;
@ -220,7 +223,6 @@ void setupPulsesPXX(unsigned int port)
flag1 |= PXX_SEND_FAILSAFE;
}
}
}
putPcmByte(flag1, port);