Test ajout Nunchuck

This commit is contained in:
tipouic 2016-12-01 19:29:57 +01:00
parent 53c5af4bd7
commit 6934bbdcf6
12 changed files with 214 additions and 34 deletions

View File

@ -217,6 +217,14 @@ void A7105_Init(void)
for (uint8_t i = 0; i < 0x32; i++)
{
uint8_t val=pgm_read_byte_near(&A7105_Regs[i]);
#ifdef FLYSKY_A7105_INO
if(protocol==MODE_FLYSKY && sub_protocol==CX20)
{
if(i==0x0E) val=0x01;
if(i==0x1F) val=0x1F;
if(i==0x20) val=0x1E;
}
#endif
if( val != 0xFF)
A7105_WriteReg(i, val);
}

View File

@ -60,9 +60,6 @@ static void __attribute__((unused)) CX10_Write_Packet(uint8_t bind)
uint16_t aileron=Servo_data[AILERON];
uint16_t elevator=3000-Servo_data[ELEVATOR];
uint16_t rudder=3000-Servo_data[RUDDER];
packet[9+offset]= lowByte(Servo_data[THROTTLE]);
packet[10+offset]= highByte(Servo_data[THROTTLE]);
// Channel 5 - flip flag
packet[12+offset] = GET_FLAG(Servo_AUX1,CX10_FLAG_FLIP); // flip flag applied on rudder
@ -85,9 +82,9 @@ static void __attribute__((unused)) CX10_Write_Packet(uint8_t bind)
break;
case Q282:
case Q242:
case Q222:
aileron = 3000 - aileron;
rudder = 3000 - rudder;
case Q222:
memcpy(&packet[15], "\x10\x10\xaa\xaa\x00\x00", 6);
//FLIP|LED|PICTURE|VIDEO|HEADLESS|RTH|XCAL|YCAL
flags2 = GET_FLAG(Servo_AUX1, 0x80) // Channel 5 - FLIP
@ -152,6 +149,8 @@ static void __attribute__((unused)) CX10_Write_Packet(uint8_t bind)
packet[6+offset]= highByte(aileron);
packet[7+offset]= lowByte(elevator);
packet[8+offset]= highByte(elevator);
packet[9+offset] = lowByte(Servo_data[THROTTLE]);
packet[10+offset]= highByte(Servo_data[THROTTLE]);
packet[11+offset]= lowByte(rudder);
packet[12+offset]|= highByte(rudder);
packet[13+offset]=flags;

View File

@ -411,7 +411,9 @@ uint16_t ReadDsm()
if(len==10 && DSM_Check_RX_packet())
{
pkt[0]=0x80;
#if defined(TELEMETRY)
telemetry_link=1; // send received data on serial
#endif
phase++;
return 2000;
}
@ -493,7 +495,9 @@ uint16_t ReadDsm()
len=MAX_PKT-2;
CYRF_ReadDataPacketLen(pkt+1, len);
pkt[0]=CYRF_ReadRegister(CYRF_13_RSSI)&0x1F;// store RSSI of the received telemetry signal
#if defined(TELEMETRY)
telemetry_link=1;
#endif
}
CYRF_WriteRegister(CYRF_29_RX_ABORT, 0x20); // Abort RX operation
if (phase == DSM_CH2_READ_A && (sub_protocol==DSM2_22 || sub_protocol==DSMX_22) && DSM_num_ch < 8) // 22ms mode

View File

@ -13,7 +13,7 @@
along with Multiprotocol. If not, see <http://www.gnu.org/licenses/>.
*/
#if defined(DEVO_CYRF6936_INO)
#if defined(DEVO_CYRF6936_INO) && defined(CYRF6936_INSTALLED)
#include "iface_cyrf6936.h"

View File

@ -55,7 +55,6 @@ const uint8_t PROGMEM V912_X17_SEQ[10] = { 0x14, 0x31, 0x40, 0x49, 0x49, //
static void __attribute__((unused)) flysky_apply_extension_flags()
{
static uint8_t seq_counter;
switch(sub_protocol)
{
case V9X9:
@ -100,9 +99,9 @@ static void __attribute__((unused)) flysky_apply_extension_flags()
break;
case V912:
seq_counter++;
if( seq_counter > 9)
seq_counter = 0;
packet_count++;
if( packet_count > 9)
packet_count = 0;
packet[12] |= 0x20; // bit 6 is always set ?
packet[13] = 0x00; // unknown
packet[14] = 0x00;
@ -112,8 +111,8 @@ static void __attribute__((unused)) flysky_apply_extension_flags()
packet[14] |= FLAG_V912_TOPBTN;
packet[15] = 0x27; // [15] and [16] apparently hold an analog channel with a value lower than 1000
packet[16] = 0x03; // maybe it's there for a pitch channel for a CP copter ?
packet[17] = pgm_read_byte( &V912_X17_SEQ[seq_counter] ) ; // not sure what [17] & [18] are for
if(seq_counter == 0) // V912 Rx does not even read those bytes... [17-20]
packet[17] = pgm_read_byte( &V912_X17_SEQ[packet_count] ) ; // not sure what [17] & [18] are for
if(packet_count == 0) // V912 Rx does not even read those bytes... [17-20]
packet[18] = 0x02;
else
packet[18] = 0x00;
@ -121,6 +120,10 @@ static void __attribute__((unused)) flysky_apply_extension_flags()
packet[20] = 0x00; // unknown
break;
case CX20:
packet[19] = 0x00; // unknown
packet[20] = (hopping_frequency_no<<4)|0x0A;
break;
default:
break;
}
@ -160,11 +163,15 @@ uint16_t ReadFlySky()
else
{
flysky_build_packet(0);
A7105_WriteData(21, hopping_frequency[hopping_frequency_no]);
hopping_frequency_no = (hopping_frequency_no + 1) & 0x0F;
A7105_WriteData(21, hopping_frequency[hopping_frequency_no & 0x0F]);
A7105_SetPower();
}
return 1510; //1460 on deviation but not working with the latest V911 bricks... Turnigy 9X v2 is 1533, Flysky TX for 9XR/9XR Pro is 1510, V911 TX is 1490.
hopping_frequency_no++;
if(sub_protocol==CX20)
return 3984;
else
return 1510; //1460 on deviation but not working with the latest V911 bricks... Turnigy 9X v2 is 1533, Flysky TX for 9XR/9XR Pro is 1510, V911 TX is 1490.
}
const uint8_t PROGMEM tx_channels[8][4] = {
@ -188,24 +195,31 @@ uint16_t initFlySky()
if ((rx_tx_addr[3]&0xF0) > 0x90) // limit offset to 9 as higher values don't work with some RX (ie V912)
rx_tx_addr[3]=rx_tx_addr[3]-0x70;
// Build frequency hop table
chanrow=rx_tx_addr[3] & 0x0F;
chanoffset=rx_tx_addr[3]/16;
// Build frequency hop table
for(uint8_t i=0;i<16;i++)
{
temp=pgm_read_byte_near(&tx_channels[chanrow>>1][i>>2]);
if(i&0x01)
if(i&0x02)
temp&=0x0F;
else
temp>>=4;
temp*=0x0A;
if(i&0x02)
if(i&0x01)
temp+=0x50;
if(sub_protocol==CX20)
{//Might need more dumps to be 100% sure but this is how it looks like to work
if(temp==0x0A)
temp+=0x37;
if(temp==0xA0)
temp-=0x73;
}
hopping_frequency[((chanrow&1)?15-i:i)]=temp-chanoffset;
}
hopping_frequency_no=0;
packet_count=0;
if(IS_AUTOBIND_FLAG_on)
bind_counter = FLYSKY_BIND_COUNT;
else

View File

@ -0,0 +1,94 @@
#ifdef ENABLE_NUNCHUCK
#include <Wire.h>
#include <Adafruit_NeoPixel.h>
Adafruit_NeoPixel strip = Adafruit_NeoPixel(1, 3, NEO_GRB + NEO_KHZ800);
// Doit etre ajuste en fonction de chaque nunchuck
#define ZEROX 530
#define ZEROY 530
#define ZEROZ 530
#define WII_NUNCHUK_I2C_ADDRESS 0x52 // adresse I2C du nunchuck
int chan;
uint8_t tpsc=0, tpsz=0;
uint8_t data[6]; //nunchuck
boolean c=false, z=false, cl=false, zl=false, op=false;
void nunchuck_init() {
strip.begin();
strip.setPixelColor(0, color[0], color[0+1], color[0+2]);
strip.setBrightness(200);
strip.show();
Wire.begin();
Wire.beginTransmission(WII_NUNCHUK_I2C_ADDRESS);
Wire.write(0xF0);
Wire.write(0x55);
Wire.endTransmission();
Wire.beginTransmission(WII_NUNCHUK_I2C_ADDRESS);
Wire.write(0xFB);
Wire.write(0x00);
Wire.endTransmission();
nunchuck_read();
nunchuck_read();
}
void nunchuck_read() {
// on demande 6 octets au nunchuck
Wire.requestFrom(WII_NUNCHUK_I2C_ADDRESS, 6);
chan = 0;
// tant qu'il y a des donnees
while(Wire.available()) { data[chan++] = Wire.read(); } // on recupere les donnees
// on reinitialise le nunchuck pour la prochaine demande
Wire.beginTransmission(WII_NUNCHUK_I2C_ADDRESS);
Wire.write(0x00);
Wire.endTransmission();
}
void nunchuck_update() {
nunchuck_read();
if(chan >= 5) {
// on extrait les donnees
// dans mon exemple j'utilise uniquement les donnees d'acceleration sur l'axe Y
int JX = data[0];
int JY = data[1];
// on limite la valeur entre -180 et 180 puis reechantillonnage de 0-255
double accelX = constrain( ((data[2] << 2) + ((data[5] >> 2) & 0x03) - ZEROX), -180, 180); //droite / gauche
double accelY = constrain( ((data[3] << 2) + ((data[5] >> 4) & 0x03) - ZEROY), -180, 180); // av / ar
double accelZ = constrain( ((data[4] << 2) + ((data[5] >> 6) & 0x03) - ZEROZ), -180, 180); // haut / bas
// calcul appuis long sur boutton
if((data[5] >> 0) & 1) { tpsc++; } // compte temps
else if(tpsc>300) { cl=!cl; tpsc=0; } // RAZ tps + déclaration appuis LONG
else if(tpsc) { c=!c; tpsc=0; } // RAZ tps + déclaration appuis COURT
// boolean zButton = !((data[5] >> 0) & 1);
if((data[5] >> 1) & 1) { tpsz++; } else if(tpsz>300) { zl=!zl; tpsz=0; } else if(tpsz) { z=!z; tpsz=0; }
// boolean cButton = !((data[5] >> 1) & 1);
Servo_data[THROTTLE] = JY;
Servo_data[ELEVATOR] = accelY;
Servo_data[RUDDER] = accelX;
Servo_data[AILERON] = JX;
if(!op) {
Servo_data[AUX1] = z;
Servo_data[AUX2] = c;
Servo_data[AUX3] = cl;
}
}
}
/*
#define DIVISOR_PERCENTS (32)
#define PERCENT_TO_BYTE(P) ((int8_t)((((int)P) * DIVISOR_PERCENTS) / 100))
#define BYTE_TO_PERCENT(P) ((int8_t)((((int)P) * 100) / DIVISOR_PERCENTS))
int16_t expo(int8_t a, int32_t x) {
return (((BYTE_TO_PERCENT(a) * x * x) / 100) * x) / (((int32_t)MAX_LEVEL) * MAX_LEVEL)
+ (100 - BYTE_TO_PERCENT(a)) * x / 100;
}
*/
#endif

Binary file not shown.

View File

@ -31,6 +31,18 @@
#include "TX_Def.h"
#include "Validate.h"
#ifdef ENABLE_NUNCHUCK
#undef ENABLE_SERIAL
#undef ENABLE_PPM
#undef TELEMETRY
#undef CYRF6936_INSTALLED
#undef CC2500_INSTALLED
#undef NRF24L01_INSTALLED
#endif
#ifndef STM32_BOARD
#include <avr/eeprom.h>
#else
@ -163,7 +175,7 @@ void_function_t remote_callback = 0;
// Init
void setup()
{
// General pinout
// General pinout
#ifdef ORANGE_TX
//XMEGA
PORTD.OUTSET = 0x17 ;
@ -277,7 +289,7 @@ void setup()
for(uint8_t i=0;i<NUM_CHN;i++)
Servo_data[i]=1500;
Servo_data[THROTTLE]=servo_min_100;
#ifdef ENABLE_PPM
#if defined (ENABLE_PPM) || defined(ENABLE_NUNCHUCK)
memcpy((void *)PPM_data,Servo_data, sizeof(Servo_data));
#endif
@ -309,9 +321,9 @@ void setup()
//Init RF modules
modules_reset();
//Init the seed with a random value created from watchdog timer for all protocols requiring random values
#ifndef ORANGE_TX
//Init the seed with a random value created from watchdog timer for all protocols requiring random values
#ifdef STM32_BOARD
randomSeed((uint32_t)analogRead(PB0) << 10 | analogRead(PB1));
#else
@ -371,6 +383,11 @@ void setup()
servo_max_125=SERIAL_MAX_125; servo_min_125=SERIAL_MIN_125;
Mprotocol_serial_init(); // Configure serial and enable RX interrupt
#endif //ENABLE_SERIAL
#ifdef ENABLE_NUNCHUCK
analogReference(INTERNAL);
nunchuck_init();
#endif //ENABLE_NUNCHUCK
}
}

View File

@ -110,6 +110,34 @@ CH1|CH2|CH3|CH4|CH5|CH6|CH7
? | ? | ? | ? | ? | ? | ?
##NRF24L01 RF Module
###BAYANG
####Sub_protocol Normal
Models: EAchine H8(C) mini, BayangToys X6/X7/X9, JJRC JJ850, Floureon H101 ...
Autobind protocol
CH1|CH2|CH3|CH4|CH5|CH6|CH7|CH8|CH9|CH10
---|---|---|---|---|---|---|---|---|----
A|E|T|R|FLIP|RTH|PICTURE|VIDEO|HEADLESS|INVERTED
####Sub_protocol Telemetry
Add telemetry for https://github.com/bikemike/H101-acro/tree/telemetry
CH11|CH12|CH13
---|---|---
Data Select|Data adjust|FlightMode
Data select : 5 steps(use a POT for this)
- min =previous data set
- low = first item in data set
- mid = second item in data set
- high= third item in data set
- max = next data set
Data adjust : 3 steps
- min=decrease current data value
- mid=neutral
- max=increase current data value
Flight Mode : 4 steps
###BLUEFLY
Autobind
@ -127,7 +155,7 @@ CH1|CH2|CH3|CH4
A|E|T|R
###CG023
###Sub_protocol H8_3D
####Sub_protocol H8_3D
Models: EAchine H8 mini 3D, JJRC H20/H22, JJRC H11D
CH5|CH6|CH7|CH8|CH9|CH10|CH11

View File

@ -91,7 +91,7 @@
// #define BlueFly_NRF24L01_INO //probleme gene id
// #define FBL100_NRF24L01_INO // finir id //!\\ //pb voie ???
// #define INAV_NRF24L01_INO // a faire
#define Q303_NRF24L01_INO
// #define Q303_NRF24L01_INO
#define BAYANG_NRF24L01_INO
#define CG023_NRF24L01_INO
@ -140,6 +140,19 @@
//If you do not plan to use the Serial mode comment this line using "//" to save Flash space
#define ENABLE_SERIAL
/******************************/
/*** NUNCHUCK MODE SETTINGS ***/
/******************************/
//In this section you can configure the NUNCHUCK.
//If you do not plan to use the NUNCHUCK mode comment this line using "//" to save Flash space, you don't need to configure anything below in this case
//#define ENABLE_NUNCHUCK
const uint8_t color[] = {
0, 255, 0, 0, 255, 100, // VERT
255, 255, 0, 127, 255, 0, // rouge
0, 0, 255, 0, 255, 255, // BLEU
255, 255, 255, 255, 255, 255, // BLANC
255, 255, 0, 127, 255, 0, // jaune
};
/*************************/
/*** PPM MODE SETTINGS ***/
@ -200,6 +213,7 @@ const PPM_Parameters PPM_prot[15]= {
V9X9
V6X6
V912
CX20
MODE_HUBSAN
NONE
MODE_FRSKYD

View File

@ -71,7 +71,8 @@ enum Flysky
Flysky=0,
V9X9=1,
V6X6=2,
V912=3
V912 = 3,
CX20 = 4
};
enum AFHDS2A
{
@ -300,14 +301,14 @@ struct PPM_Parameters
//*** AUX flags ***
//*******************
#define GET_FLAG(ch, mask) ( ch ? mask : 0)
#define Servo_AUX1 Servo_AUX & _BV(0)
#define Servo_AUX2 Servo_AUX & _BV(1)
#define Servo_AUX3 Servo_AUX & _BV(2)
#define Servo_AUX4 Servo_AUX & _BV(3)
#define Servo_AUX5 Servo_AUX & _BV(4)
#define Servo_AUX6 Servo_AUX & _BV(5)
#define Servo_AUX7 Servo_AUX & _BV(6)
#define Servo_AUX8 Servo_AUX & _BV(7)
#define Servo_AUX1 (Servo_AUX & _BV(0))
#define Servo_AUX2 (Servo_AUX & _BV(1))
#define Servo_AUX3 (Servo_AUX & _BV(2))
#define Servo_AUX4 (Servo_AUX & _BV(3))
#define Servo_AUX5 (Servo_AUX & _BV(4))
#define Servo_AUX6 (Servo_AUX & _BV(5))
#define Servo_AUX7 (Servo_AUX & _BV(6))
#define Servo_AUX8 (Servo_AUX & _BV(7))
//************************
//*** Power settings ***
@ -475,6 +476,7 @@ Serial: 100000 Baud 8e2 _ xxxx xxxx p --
V9x9 1
V6x6 2
V912 3
CX20 4
sub_protocol==Hisky
Hisky 0
HK310 1

Binary file not shown.