From 75e5543ecf6d6423a590d5d7371e548ad38eda8e Mon Sep 17 00:00:00 2001 From: "Schoenberger, Philipp" Date: Thu, 4 Apr 2019 15:24:35 +0200 Subject: [PATCH] add usb state class --- remote/include/state.h | 11 ++++++++ remote/src/FrSkyD_cc2500.cpp | 3 +++ remote/src/state.cpp | 2 ++ remote/src/state_joy_usb.cpp | 52 ++++++++++++++++++++++++++++++++++++ remote/src/state_menu.cpp | 1 + 5 files changed, 69 insertions(+) create mode 100644 remote/src/state_joy_usb.cpp diff --git a/remote/include/state.h b/remote/include/state.h index 23ddd41..f7f1e2b 100644 --- a/remote/include/state.h +++ b/remote/include/state.h @@ -93,6 +93,16 @@ public: void update(void); void leave(void); }; + +class LCD_state_joy_usb: public State { +private: + unsigned long time_enter; +public: + LCD_state_joy_usb(void); + void enter(void); + void update(void); + void leave(void); +}; extern State *curr_state; extern State *new_state; @@ -100,5 +110,6 @@ extern State *s_init; extern State *s_bind; extern State *s_fly; extern State *s_joy; +extern State *s_usb; extern State *s_menu; #endif /*_STATE_H_*/ diff --git a/remote/src/FrSkyD_cc2500.cpp b/remote/src/FrSkyD_cc2500.cpp index 9af091e..af77df4 100644 --- a/remote/src/FrSkyD_cc2500.cpp +++ b/remote/src/FrSkyD_cc2500.cpp @@ -245,13 +245,16 @@ uint16_t ReadFrSky_2way() //debugln("%d len",len); if (len && len<=(0x11+3)) { // 20bytes + debug("rx tel\n"); CC2500_ReadData(pkt, len); //received telemetry packets #if defined(TELEMETRY) if(pkt[len-1] & 0x80) {//with valid crc + debug("rx invalid crc\n"); packet_count=0; frsky_check_telemetry(pkt,len); //check if valid telemetry packets and buffer them. } + debug("rx end crc\n"); #endif } else { packet_count++; diff --git a/remote/src/state.cpp b/remote/src/state.cpp index bd3b669..dc13aed 100644 --- a/remote/src/state.cpp +++ b/remote/src/state.cpp @@ -17,6 +17,7 @@ State *s_init = NULL; State *s_bind = NULL; State *s_fly = NULL; State *s_joy = NULL; +State *s_usb = NULL; State *s_menu = NULL; @@ -32,6 +33,7 @@ void init_state(void) { s_bind = new LCD_state_bind(); s_fly = new LCD_state_fly(); s_joy = new LCD_state_joy_calibration(); + s_usb = new LCD_state_joy_usb(); s_menu = new LCD_state_menu(); lcd.backlight(); curr_state = NULL; diff --git a/remote/src/state_joy_usb.cpp b/remote/src/state_joy_usb.cpp new file mode 100644 index 0000000..8a6db0d --- /dev/null +++ b/remote/src/state_joy_usb.cpp @@ -0,0 +1,52 @@ +#include +#include +#include "Arduino.h" +#include "state.h" +#include "input.h" +#include "debug.h" + +//#include + +/* USBHID* HID; */ +/* HIDJoystick* Joystick; */ + +LCD_state_joy_usb::LCD_state_joy_usb(void) { + +} +void LCD_state_joy_usb::enter(void) { + lcd.setCursor(0,0); + lcd.print("joystick mode "); + lcd.setCursor(0,1); + lcd.print(" "); + delay(500); + + /* HID = new USBHID(); */ + /* Joystick = new HIDJoystick(*HID); */ + /* HID->begin(HID_JOYSTICK); */ +} +void LCD_state_joy_usb::update(void) { + + input.update(); + input.print(); + while(1) { + /* Joystick->X(0); */ + /* delay(500); */ + /* Joystick->X(1023); */ + /* delay(500); */ + + input.update(); + + if (input.is_menu_triggered()) { + debug("%lu menu button trigger\n", millis()); + input.print(); + break; + } + } + new_state = s_menu; +} +void LCD_state_joy_usb::leave(void) { + lcd.setCursor(0,0); + lcd.print("finished "); + lcd.setCursor(0,1); + lcd.print("usb mode "); +} diff --git a/remote/src/state_menu.cpp b/remote/src/state_menu.cpp index c76d8c1..c3fae82 100644 --- a/remote/src/state_menu.cpp +++ b/remote/src/state_menu.cpp @@ -26,6 +26,7 @@ void LCD_state_menu::update(void) } menus[] = { { "Flight ", s_fly }, { "Bind ", s_bind }, + { "Joy usb ", s_usb}, { "Joy calib ", s_joy }, { "HF calib ", NULL }, { " ", NULL },