Browse Source

add sw on p/r

add battery percentage
master
Schoenberger, Philipp 6 years ago
parent
commit
bf5cea1fd3
  1. 141
      remote/include/config.h
  2. 2
      remote/include/debug.h
  3. 5
      remote/include/input.h
  4. 3
      remote/include/pins.h
  5. 16
      remote/include/state.h
  6. 4
      remote/src/FrSkyD_cc2500.cpp
  7. 203
      remote/src/config.cpp
  8. 31
      remote/src/input.cpp
  9. 13
      remote/src/state.cpp
  10. 7
      remote/src/state_bind.cpp
  11. 29
      remote/src/state_fly.cpp
  12. 19
      remote/src/state_init.cpp
  13. 55
      remote/src/state_joy_calib.cpp
  14. 8
      remote/src/state_joy_usb.cpp
  15. 5
      remote/src/state_menu.cpp
  16. 8
      remote/src/telemetry.cpp

141
remote/include/config.h

@ -16,51 +16,15 @@
#define _CONFIG_H_
#include <stdint.h>
//#define REMOE_OWNER "phschoen"
#define REMOE_OWNER "Marleen"
//#define REMOE_OWNER "Sina"
//#define REMOE_OWNER "Malaika"
//#define REMOE_OWNER "Pauline"
//#define REMOE_OWNER "Mara"
#define DEFAULT_BIND_TIME 13 /*seconds*/
/*****************/
/*** AUTO BIND ***/ // Also referred as "Bind on powerup"
/*****************/
//Bind from channel enables you to bind when a specified channel is going from low to high. This feature is only active
// if you specify AUTOBIND in PPM mode or set AutoBind to YES for serial mode. It also requires that the throttle channel is low.
//Comment to globaly disable the bind feature from a channel.
#define ENABLE_BIND_CH
//Set the channel number used for bind. Default is 16.
#define BIND_CH 16
//Comment to disable the wait for bind feature. If Autobind is enabled in the model config, this feature will not activate
// the selected protocol unless a bind is requested using bind from channel or the GUI "Bind" button.
//The goal is to prevent binding other people's model when powering up the TX, changing model or scanning through protocols.
#define WAIT_FOR_BIND
/****************/
/*** RF CHIPS ***/
/****************/
//There are 4 RF components supported. If one of them is not installed you must comment it using "//".
//If a chip is not installed all associated protocols are automatically disabled.
//4-in-1 modules have all RF chips installed
//!!!If a RF chip is present it MUST be marked as installed!!! or weird things will happen you have been warned.
//#define A7105_INSTALLED
//#define CYRF6936_INSTALLED
#define CC2500_INSTALLED
//#define NRF24L01_INSTALLED
/** CC2500 Fine Frequency Tuning **/
//For optimal performance the CC2500 RF module used by the FrSkyD, FrSkyV, FrSkyX, SFHSS, CORONA and Hitec protocols needs to be tuned for each protocol.
//Initial tuning should be done via the radio menu with a genuine FrSky/Futaba/CORONA/Hitec receiver.
//Once a good tuning value is found it can be set here and will override the radio's 'option' setting for all existing and new models which use that protocol.
//For more information: https://github.com/pascallanger/DIY-Multiprotocol-TX-Module/tree/master/docs/Frequency_Tuning.md
//Uncomment the lines below (remove the "//") and set an appropriate value (replace the "0") to enable. Valid range is -127 to +127.
//#define FORCE_FRSKYD_TUNING 0
//#define FORCE_FRSKYV_TUNING 0
//#define FORCE_FRSKYX_TUNING 0
/** Low Power **/
//Low power is reducing the transmit power of the multi module. This setting is configurable per model in PPM (table below) or Serial mode (radio GUI).
//It can be activated when flying indoor or small models since the distance is short or if a model is causing issues when flying closed to the TX.
@ -71,19 +35,7 @@
/*****************/
/*** GLOBAL ID ***/
/*****************/
//A global ID is used by most protocols to bind and retain the bind to models. To prevent duplicate IDs, it is automatically
// generated using a random 32 bits number the first time the eeprom is initialized.
//If you have 2 Multi modules which you want to share the same ID so you can use either to control the same RC model
// then you can force the ID to a certain known value using the lines below.
//Default is commented, you should uncoment only for test purpose or if you know exactly what you are doing!!!
#define FORCE_GLOBAL_ID 0x12345678
//Protocols using the CYRF6936 (DSM, Devo, Walkera...) are using the CYRF ID instead which should prevent duplicated IDs.
//If you have 2 Multi modules which you want to share the same ID so you can use either to control the same RC model
// then you can force the ID to a certain known value using the lines below.
//Default is commented, you should uncoment only for test purpose or if you know exactly what you are doing!!!
//#define FORCE_CYRF_ID "\x12\x34\x56\x78\x9A\xBC"
//#define FORCE_GLOBAL_ID 0x12345678
/****************************/
/*** PROTOCOLS TO INCLUDE ***/
@ -97,29 +49,6 @@
#define FRSKYV_CC2500_INO
#define FRSKYX_CC2500_INO
/**************************/
/*** FAILSAFE SETTINGS ***/
/**************************/
//The module is using the same default failsafe values for all protocols which currently supports it:
// Devo, WK2x01, SFHSS, HISKY/HK310 and AFHDS2A
//All channels are centered except throttle which is forced low.
//If you want to diasble failsafe globally comment the line below using "//".
#define FAILSAFE_ENABLE
//Failsafe throttle low value in percentage.
//Value between -125% and +125%. Default -100.
#define FAILSAFE_THROTTLE_LOW -100
//The radio using serial protocol can set failsafe data.
// Two options are available:
// a. replace the default failsafe data with serial failsafe data when they are received.
// b. wait for the radio to provide failsafe before sending it. Enable advanced settings like "FAILSAFE NOT SET" or "FAILSAFE RX".
// Option a. is the default since you have a protection even if no failsafe has been set on the radio.
// You can force option b. by uncommenting the line below (remove the "//").
//#define FAILSAFE_SERIAL_ONLY
/**************************/
/*** TELEMETRY SETTINGS ***/
/**************************/
@ -128,14 +57,6 @@
//If you do not plan using the telemetry comment this global setting using "//" and skip to the next section.
#define TELEMETRY
//Comment to invert the polarity of the output telemetry serial signal.
//This function takes quite some flash space and processor power on an atmega.
//For OpenTX it must be uncommented.
//On a 9XR_PRO running ersky9x both commented and uncommented will work depending on the radio setting Invert COM1 under the Telemetry menu.
//On other addon/replacement boards like the 9xtreme board or the Ar9x board running ersky9x, you need to uncomment the line below.
//For er9x it depends if you have an inveter mod or not on the telemetry pin. If you don't have an inverter comment this line.
//#define INVERT_TELEMETRY
//Comment if you don't want to send Multi status telemetry frames (Protocol available, Bind in progress, version...)
//Use with er9x/erksy9x, for OpenTX MULTI_TELEMETRY below is preferred instead
//#define MULTI_STATUS
@ -145,17 +66,8 @@
//#define MULTI_TELEMETRY
//Comment a line to disable a specific protocol telemetry
//#define DSM_TELEMETRY // Forward received telemetry packet directly to TX to be decoded by er9x, ersky9x and OpenTX
//#define SPORT_TELEMETRY // Use FrSkyX SPORT format to send telemetry to TX
//#define AFHDS2A_FW_TELEMETRY // Forward received telemetry packet directly to TX to be decoded by ersky9x and OpenTX
//#define AFHDS2A_HUB_TELEMETRY // Use FrSkyD Hub format to send basic telemetry to TX like er9x
//#define HUB_TELEMETRY // Use FrSkyD Hub format to send telemetry to TX
//#define BAYANG_HUB_TELEMETRY // Use FrSkyD Hub format to send telemetry to TX
//#define BUGS_HUB_TELEMETRY // Use FrSkyD Hub format to send telemetry to TX
//#define HUBSAN_HUB_TELEMETRY // Use FrSkyD Hub format to send telemetry to TX
//#define CABELL_HUB_TELEMETRY // Use FrSkyD Hub format to send telemetry to TX
//#define HITEC_HUB_TELEMETRY // Use FrSkyD Hub format to send basic telemetry to the radios which can decode it like er9x, ersky9x and OpenTX
//#define HITEC_FW_TELEMETRY // Under development: Forward received telemetry packets to be decoded by ersky9x and OpenTX
//SPORT_POLLING is an implementation of the same polling routine as XJT module for sport telemetry bidirectional communication.
//This is useful for passing sport control frames from TX to RX(ex: changing Betaflight PID or VTX channels on the fly using LUA scripts with OpentX).
@ -163,49 +75,4 @@
//!!!! This is a work in progress!!! Do not enable unless you want to test and report
//#define SPORT_POLLING
/*************************/
/*** PPM MODE SETTINGS ***/
/*************************/
#define NBR_BANKS 1
struct PPM_Parameters
{
uint8_t protocol : 6;
uint8_t sub_proto : 3;
uint8_t rx_num : 4;
#define P_HIGH 1
#define P_LOW 0
uint8_t power : 1;
#define AUTOBIND 1
#define NO_AUTOBIND 0
uint8_t autobind : 1;
uint8_t option;
};
//******************
// Protocols
//******************
enum PROTOCOLS
{
MODE_SERIAL = 0, // Serial commands
PROTO_FRSKYD = 3, // =>CC2500
PROTO_FRSKYX = 15, // =>CC2500
PROTO_SFHSS = 21, // =>CC2500
PROTO_FRSKYV = 25, // =>CC2500
PROTO_CORONA = 37, // =>CC2500
PROTO_HITEC = 39, // =>CC2500
};
enum FRSKYX_SUP_PROTOCOL
{
CH_16 = 0,
CH_8 = 1,
EU_16 = 2,
EU_8 = 3,
};
extern const PPM_Parameters PPM_prot[14*NBR_BANKS];
#endif

2
remote/include/debug.h

@ -6,7 +6,7 @@
//********************
//** Debug messages **
//********************
//#define ENABLE_DBEUG // ~1k
#define ENABLE_DBEUG // ~1k
#ifdef ENABLE_DBEUG
#define debug(msg, ...) { char buf[256]; sprintf(buf, msg, ##__VA_ARGS__); Serial.print(buf);}
#define debugln(msg, ...) { char buf[256]; sprintf(buf, msg "\r\n", ##__VA_ARGS__); Serial.println(buf);}

5
remote/include/input.h

@ -18,9 +18,10 @@ class Input {
CH_AUX3 = 6,
CH_AUX4 = 7,
CH_AUX5 = 8,
CH_AUX6 = 9,
CH_MAX = 8,
CH_COUNT = 9,
CH_MAX = 9,
CH_COUNT = 10,
MENU_UP_DOWN = CH_PITCH,
MENU_LEFT_RIGHT = CH_ROLL,

3
remote/include/pins.h

@ -36,9 +36,10 @@
#define Aux3_pin PB11
#define Aux4_pin PB13
#define Aux5_pin PB15
#define Aux6_pin PA15
#define Menu_pin PB12
#define Battery_pin PA9
#define Battery_pin PB0
#define Led_pin PC13
#define Buzzer_pin PA8

16
remote/include/state.h

@ -46,6 +46,7 @@ public:
void update(void);
void leave(void);
};
extern State *s_init;
class LCD_state_bind: public State {
private:
@ -58,6 +59,7 @@ public:
void update(void);
void leave(void);
};
extern State *s_bind;
class LCD_state_fly: public State {
private:
@ -75,6 +77,7 @@ public:
void update(void);
void leave(void);
};
extern State *s_fly;
class LCD_state_menu: public State {
private:
@ -85,6 +88,7 @@ public:
void update(void);
void leave(void);
};
extern State *s_menu;
class LCD_state_joy_calibration: public State {
public:
@ -93,7 +97,9 @@ public:
void update(void);
void leave(void);
};
extern State *s_joy;
#ifndef ENABLE_DBEUG
class LCD_state_joy_usb: public State {
private:
unsigned long time_enter;
@ -103,13 +109,11 @@ public:
void update(void);
void leave(void);
};
extern State *s_usb;
#endif
extern State *curr_state;
extern State *new_state;
extern State *s_init;
extern State *s_bind;
extern State *s_fly;
extern State *s_joy;
extern State *s_usb;
extern State *s_menu;
void lcd_centerText(const char *text);
#endif /*_STATE_H_*/

4
remote/src/FrSkyD_cc2500.cpp

@ -245,7 +245,7 @@ uint16_t ReadFrSky_2way()
//debugln("%d len",len);
if (len && len<=(0x11+3)) { // 20bytes
debug("rx tel\n");
debug("rx tel %d\n", len);
CC2500_ReadData(pkt, len); //received telemetry packets
#if defined(TELEMETRY)
if(pkt[len-1] & 0x80)
@ -257,6 +257,8 @@ uint16_t ReadFrSky_2way()
debug("rx end crc\n");
#endif
} else {
if (len != 0)
debug("rx len %d\n", len);
packet_count++;
// restart sequence on missed packet - might need count or timeout instead of one missed
if(packet_count > 100) {//~1sec

203
remote/src/config.cpp

@ -1,203 +0,0 @@
/*
This project is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
Multiprotocol 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.
You should have received a copy of the GNU General Public License
along with Multiprotocol. If not, see <http://www.gnu.org/licenses/>.
*/
#include "config.h"
const PPM_Parameters PPM_prot[14]= {
//****************************** BANK 1 ******************************
// Switch Protocol Sub protocol RX_Num Power Auto Bind Option
/* 1 */ {PROTO_FRSKYD, 0 , 0 , P_LOW , AUTOBIND , 0 },
/* 2 */ {PROTO_FRSKYD, 0 , 0 , P_LOW , AUTOBIND , 20 },
/* 3 */ {PROTO_FRSKYD, 0 , 0 , P_LOW , AUTOBIND , 40 },
/* 4 */ {PROTO_FRSKYD, 0 , 0 , P_LOW , AUTOBIND , 60 },
/* 5 */ {PROTO_FRSKYD, 0 , 0 , P_LOW , AUTOBIND , 80 },
/* 6 */ {PROTO_FRSKYD, 0 , 0 , P_LOW , AUTOBIND , 100 },
/* 7 */ {PROTO_FRSKYD, 0 , 0 , P_LOW , AUTOBIND , 120 },
/* 8 */ {PROTO_FRSKYD, 0 , 0 , P_LOW , AUTOBIND , 140 },
/* 9 */ {PROTO_FRSKYD, 0 , 0 , P_LOW , AUTOBIND , 160 },
/* 10 */ {PROTO_FRSKYD, 0 , 0 , P_LOW , AUTOBIND , 180 },
/* 11 */ {PROTO_FRSKYD, 0 , 0 , P_LOW , AUTOBIND , 200 },
/* 12 */ {PROTO_FRSKYD, 0 , 0 , P_LOW , AUTOBIND , 220 }, // option=fine freq tuning
/* 13 */ {PROTO_FRSKYD, 0 , 0 , P_LOW , AUTOBIND , 240 },
/* 14 */ {PROTO_FRSKYD, 0 , 0 , P_LOW , AUTOBIND , 255 },
};
/* Available protocols and associated sub protocols to pick and choose from
PROTO_FLYSKY
Flysky
V9X9
V6X6
V912
CX20
PROTO_HUBSAN
H107
H301
H501
PROTO_FRSKYV
NONE
PROTO_FRSKYD
NONE
PROTO_FRSKYX
CH_16
CH_8
EU_16
EU_8
PROTO_HISKY
Hisky
HK310
PROTO_V2X2
V2X2
JXD506
PROTO_DSM
DSM2_22
DSM2_11
DSMX_22
DSMX_11
PROTO_DEVO
NONE
PROTO_YD717
YD717
SKYWLKRP_LOW
SYMAX4
XINXUN
NIHUI
PROTO_KN
WLTOYS
FEILUN
PROTO_SYMAX
SYMAX
SYMAX5C
PROTO_SLT
NONE
PROTO_CX10
CX10_GREEN
CX10_BLUE
DM007
JC3015_1
JC3015_2
MK33041
PROTO_Q2X2
Q222
Q242
Q282
PROTO_SLT
SLT
VISTA
PROTO_CG023
CG023
YD829
PROTO_BAYANG
BAYANG
H8S3D
X16_AH
IRDRONE
PROTO_ESKY
NONE
PROTO_MT99XX
MT99
H7
YZ
LS
FY805
PROTO_MJXQ
WLH08
X600
X800
H26D
E010
H26WH
PROTO_SHENQI
NONE
PROTO_FY326
FY326
FY319
PROTO_SFHSS
NONE
PROTO_J6PRO
NONE
PROTO_FQ777
NONE
PROTO_ASSAN
NONE
PROTO_HONTAI
HONTAI
JJRCX1
X5C1
FQ777_951
PROTO_AFHDS2A
PWM_IBUS
PPM_IBUS
PWM_SBUS
PPM_SBUS
PROTO_WK2x01
WK2801
WK2401
W6_5_1
W6_6_1
W6_HEL
W6_HEL_I
PROTO_Q303
Q303
CX35
CX10D
CX10WD
PROTO_GW008
NONE
PROTO_DM002
NONE
PROTO_CABELL
CABELL_V3
CABELL_V3_TELEMETRY
CABELL_SET_FAIL_SAFE
CABELL_UNBIND
PROTO_ESKY150
PROTO_H8_3D
H8_3D
H20H
H20MINI
H30MINI
PROTO_CORONA
COR_V1
COR_V2
FD_V3
PROTO_CFLIE
NONE
PROTO_HITEC
OPT_FW
OPT_HUB
MINIMA
PROTO_WFLY
NONE
PROTO_BUGS
NONE
PROTO_SLT
SLT_V1
SLT_V2
Q100
Q200
MR100
*/
// RX_Num is used for TX & RX match. Using different RX_Num values for each receiver will prevent starting a model with the false config loaded...
// RX_Num value is between 0 and 15.
// Power P_HIGH or P_LOW: High or low power setting for the transmission.
// For indoor P_LOW is more than enough.
// Auto Bind AUTOBIND or NO_AUTOBIND
// For protocols which does not require binding at each power up (like Flysky, FrSky...), you might still want a bind to be initiated each time you power up the TX.
// As an example, it's usefull for the WLTOYS F929/F939/F949/F959 (all using the Flysky protocol) which requires a bind at each power up.
// It also enables the Bind from channel feature, allowing to execute a bind by toggling a designated channel.
// Option: the value is between -128 and +127.
// The option value is only valid for some protocols, read this page for more information: https://github.com/pascallanger/DIY-Multiprotocol-TX-Module/blob/master/Protocols_Details.md

31
remote/src/input.cpp

@ -10,16 +10,16 @@ Input input;
const char* ch_name[Input::CH_COUNT] = {
"CH_ROLL",
"CH_PITCH",
"CH_THROTTLE",
"CH_YAW",
"CH_AUX1",
"CH_AUX2",
"CH_AUX3",
"CH_AUX4",
"CH_AUX5",
"ROLL",
"PITCH",
"THROTTLE",
"YAW",
"AUX1",
"AUX2",
"AUX3",
"AUX4",
"AUX5",
};
Input::Input(void) {
@ -76,6 +76,9 @@ void Input::init() {
this->pins[CH_AUX5] = Aux5_pin;
this->ch_config[CH_AUX5].is_analog = false;
this->pins[CH_AUX6] = Aux6_pin;
this->ch_config[CH_AUX6].is_analog = false;
for (uint8_t i = 0; i < CH_COUNT; ++i) {
pinMode(this->pins[i], INPUT);
}
@ -93,6 +96,7 @@ void Input::init() {
this->ch_config[CH_AUX3].inverted = true;
this->ch_config[CH_AUX4].inverted = true;
this->ch_config[CH_AUX5].inverted = true;
this->ch_config[CH_AUX6].inverted = true;
}
bool Input::is_centered(void) {
@ -240,7 +244,7 @@ void Input::update(void) {
for (uint8_t ch = 0; ch < CH_COUNT; ++ch) {
this->channel_data[ch] = map(this->curr->ch_data[ch], this->ch_config[ch].min, this->ch_config[ch].max, CHANNEL_MIN_100, CHANNEL_MAX_100);
this->channel_data[ch] = map(this->curr->ch_data[ch], this->ch_config[ch].min, this->ch_config[ch].max, CHANNEL_MIN_100+3, CHANNEL_MAX_100);
}
#define CHANNEL_DEAD 70
@ -248,6 +252,11 @@ void Input::update(void) {
uint8_t min_dead = mid - CHANNEL_DEAD;
uint8_t max_dead = mid + CHANNEL_DEAD;
for (uint8_t ch = 0; ch < CH_COUNT; ++ch) {
if (this->channel_data[ch] > mid) {
this->channel_data[ch] -= CHANNEL_DEAD;
} else {
this->channel_data[ch] -= CHANNEL_DEAD;
}
if (min_dead <= this->channel_data[ch] &&
this->channel_data[ch] <= max_dead) {
this->channel_data[ch] = mid;

13
remote/src/state.cpp

@ -17,7 +17,9 @@ State *s_init = NULL;
State *s_bind = NULL;
State *s_fly = NULL;
State *s_joy = NULL;
#ifndef ENABLE_DBEUG
State *s_usb = NULL;
#endif
State *s_menu = NULL;
@ -33,7 +35,9 @@ void init_state(void) {
s_bind = new LCD_state_bind();
s_fly = new LCD_state_fly();
s_joy = new LCD_state_joy_calibration();
#ifndef ENABLE_DBEUG
s_usb = new LCD_state_joy_usb();
#endif
s_menu = new LCD_state_menu();
lcd.backlight();
curr_state = NULL;
@ -56,3 +60,12 @@ void update_state(void) {
curr_state->enter();
}
}
void lcd_centerText(const char *text)
{
int fieldWidth = 16;
int padlen = 0;
padlen = (fieldWidth - strlen(text)) / 2 ;
char line[17] = {0};
sprintf(line, "%*s%s%*s\n", padlen, "", text, padlen, "");
lcd.print(line);
}

7
remote/src/state_bind.cpp

@ -54,6 +54,13 @@ void LCD_state_bind::update(void)
lcd.setCursor(14,1);
lcd.print(line);
input.update();
if (input.is_menu_triggered()) {
debug("%lu menu button trigger\n", millis);
new_state = s_menu;
break;
}
end__ = micros();
if (end__ - start < next_callback_time) {

29
remote/src/state_fly.cpp

@ -76,7 +76,7 @@ void LCD_state_fly::enter(void) {
lcd.setCursor(12,0);
lcd.write(battery_char);
#if 0
#if 1
lcd.setCursor(12,1);
lcd.write(battery_char);
lcd.setCursor(6,1);
@ -149,7 +149,8 @@ void LCD_state_fly::update(void)
uint8_t call=0;
uint8_t rssi_percent = 100;
uint8_t akku_quad = 1;
uint8_t akku_remote = 2;
uint32_t akku_remote = 2;
uint32_t old_akku_remote = 2;
unsigned long time_in_ms = millis() - this->time_enter;
unsigned long time_in_s = time_in_ms/1000; // to sec
@ -196,9 +197,9 @@ void LCD_state_fly::update(void)
this->print_time(time_in_s);
break;
#if 0
#if 1
case 20:
rssi_percent += 1;
rssi_percent = TX_RSSI;
if(rssi_percent > 100)
rssi_percent = 0;
this->print_rssi(rssi_percent);
@ -215,12 +216,20 @@ void LCD_state_fly::update(void)
#endif
case 40:
// update akku
akku_remote = analogRead(Battery_pin);
if (akku_remote > 3830)
akku_remote = 3830;
if (akku_remote < 3450)
akku_remote = 3450;
akku_remote = map16b(akku_remote, 3450, 3830, 0, 100);
// 3.7 -> 1560
// 4.22 -> 1440
pinMode(Battery_pin, INPUT);
for(int i = 0; i < 10; ++i)
akku_remote += analogRead(Battery_pin);
akku_remote /=10;
akku_remote = (old_akku_remote +akku_remote )/2;
old_akku_remote = akku_remote;
debug("akku %u \n", akku_remote);
if (akku_remote > 1560)
akku_remote = 1560;
if (akku_remote < 1440)
akku_remote = 1440;
akku_remote = map16b(akku_remote, 1440, 1560, 100, 0);
if (akku_remote > 100)
akku_remote = 100;
this->print_akku_remote(akku_remote);

19
remote/src/state_init.cpp

@ -9,14 +9,6 @@
#include "config.h"
#include "pins.h"
#include "tx_def.h"
void centerText(const char *text, int fieldWidth)
{
int padlen = 0;
padlen = (fieldWidth - strlen(text)) / 2 ;
char line[17];
sprintf(line, "%*s%s%*s\n", padlen, "", text, padlen, "");
lcd.print(line);
}
LCD_state_init::LCD_state_init(void) {
}
@ -24,9 +16,18 @@ void LCD_state_init::enter(void) {
lcd.setCursor(0,0);
lcd.print(" wellcome ");
lcd.setCursor(0,1);
centerText(REMOE_OWNER,16);
lcd_centerText(REMOE_OWNER);
this->time_enter = millis();
BUZZER_output;
/* for(int i = 0 ; i < 10;++i) { */
/* delay(100); */
/* BUZZER_on; */
/* delay(100); */
/* BUZZER_off; */
/* delay(100); */
/* } */
}
void LCD_state_init::update(void)

55
remote/src/state_joy_calib.cpp

@ -18,15 +18,19 @@ void LCD_state_joy_calibration::enter(void) {
lcd.print("move all sticks ");
delay(500);
}
void show_dots(int row, int number) {
void lcd_show_dots(int row, int number) {
char line[17] = "";
int c = 0;
lcd.setCursor(0,row);
for(int c = 0; c < 16;++c) {
for(c = 0; c < 16;++c) {
if (c < number)
lcd.print(".");
else
lcd.print(" ");
line[c]='.';
}
line[c]='\0';
lcd_centerText(line);
}
void LCD_state_joy_calibration::update(void) {
int8_t turns = 50;
int8_t i;
@ -37,7 +41,7 @@ void LCD_state_joy_calibration::update(void) {
// min max calibration
lcd.setCursor(0,0);
lcd.print("min max Calib. ");
show_dots(1,16);
lcd_show_dots(1,16);
i = turns;
while(i > 0) {
input.update();
@ -45,43 +49,64 @@ void LCD_state_joy_calibration::update(void) {
i = turns;
}else {
i -= 1;
show_dots(1,(i *16)/turns);
lcd_show_dots(1,(i *16)/turns);
}
delay(100);
}
// center
lcd.setCursor(0,0);
lcd.print("center sticks ");
lcd.print("center stick ");
i = turns;
lcd_show_dots(1,16);
while(i > 0) {
input.update();
if (false == input.is_centered()) {
i = turns;
}else {
i -= 1;
show_dots(1,(i *16)/turns);
lcd_show_dots(1,(i *16)/turns);
}
if (input.is_centered(Input::CH_THROTTLE)) {
lcd.setCursor(12,0);
lcd.write('T');
}
if (input.is_centered(Input::CH_YAW)) {
lcd.setCursor(13,0);
lcd.write('Y');
}
if (input.is_centered(Input::CH_PITCH)) {
lcd.setCursor(14,0);
lcd.write('P');
}
if (input.is_centered(Input::CH_ROLL)) {
lcd.setCursor(15,0);
lcd.write('R');
}
delay(100);
}
for (uint8_t _ch = 0; _ch < 4 ; ++_ch) {
enum Input::input_channels ch = (enum Input::input_channels) _ch;
char line [17]="";
sprintf(line, "move max %s", ch_name[ch]);
lcd.setCursor(0,0);
lcd.print("move to max: ");
lcd.setCursor(0,1);
lcd.print(" ");
lcd.setCursor(0,1);
lcd.print(ch_name[ch]);
lcd.print(line);
i = turns;
lcd_show_dots(1,16);
while(i>0) {
delay(50);
input.update();
input.print_ch(ch);
if (input.is_high(ch)) {
i--;
i -= 1;
lcd.setCursor(0,1);
lcd_show_dots(1,(i *16)/turns);
continue;
}

8
remote/src/state_joy_usb.cpp

@ -36,6 +36,7 @@ void LCD_state_joy_usb::update(void) {
bool bt2 = ch_data[Input::CH_AUX3] == CHANNEL_MIN_100;
bool bt3 = ch_data[Input::CH_AUX4] == CHANNEL_MIN_100;
bool bt4 = ch_data[Input::CH_AUX5] == CHANNEL_MIN_100;
bool bt5 = ch_data[Input::CH_AUX6] == CHANNEL_MIN_100;
delay(50);
Joystick.X(x);
@ -47,12 +48,7 @@ void LCD_state_joy_usb::update(void) {
Joystick.button(2, bt2);
Joystick.button(3, bt3);
Joystick.button(4, bt4);
char line[17];
snprintf(line,sizeof(line),"%lu %lu", bt0 , input.ch_raw[Input::CH_AUX1]);
lcd.setCursor(0,1);
lcd.print(line);
Joystick.button(5, bt5);
if (input.is_menu_triggered()) {
debug("%lu menu button trigger\n", millis);

5
remote/src/state_menu.cpp

@ -26,7 +26,9 @@ void LCD_state_menu::update(void)
} menus[] = {
{ "Flight ", s_fly },
{ "Bind ", s_bind },
#ifdef ENABLE_DBEUG
{ "Joy usb ", s_usb},
#endif
{ "Joy calib ", s_joy },
{ "HF calib ", NULL },
{ " ", NULL },
@ -65,6 +67,7 @@ void LCD_state_menu::update(void)
lcd.print("entering ");
lcd.setCursor(0,1);
lcd.print(menus[this->curr_selected].name);
// do wait until its centered
while(false == input.is_centered(Input::MENU_LEFT_RIGHT)) {
input.update();
@ -77,7 +80,7 @@ void LCD_state_menu::update(void)
}
if(wait)
delay(500);
delay(1100);
}
void LCD_state_menu::leave(void)

8
remote/src/telemetry.cpp

@ -104,11 +104,15 @@ static void multi_send_frskyhub()
void frsky_check_telemetry(uint8_t *pkt,uint8_t len)
{
uint8_t clen = pkt[0] + 3 ;
if (len != clen) // wrong length
if (len != clen) {
// wrong length
debug("wrong length %d vs %d \n", len , clen);
return;
}
if(pkt[1] == rx_tx_addr[3] && pkt[2] == rx_tx_addr[2] ) {
telemetry_link |= 1; // Telemetry data is available
TX_RSSI = pkt[len-2];
debug("rssi %d\n", TX_RSSI);
if(TX_RSSI >=128)
TX_RSSI -= 128;
@ -116,6 +120,8 @@ void frsky_check_telemetry(uint8_t *pkt,uint8_t len)
TX_RSSI += 128;
TX_LQI = pkt[len-1]&0x7F;
debug("TX_LQI %d\n", TX_LQI);
for (uint8_t i=3;i<len-2;i++)
pktt[i]=pkt[i]; // Buffer telemetry values to be sent

Loading…
Cancel
Save