Correction script LUA + suivit

This commit is contained in:
tipouic 2016-01-28 20:32:53 +01:00
parent c5d819be81
commit 8faf5abe38
9 changed files with 55 additions and 46 deletions

View File

@ -196,19 +196,8 @@ const uint8_t PROGMEM FLYSKY_A7105_regs[] = {
0x13, 0xc3, 0x00, 0xff, 0x00, 0x00, 0x3b, 0x00, 0x17, 0x47, 0x80, 0x03, 0x01, 0x45, 0x18, 0x00, 0x13, 0xc3, 0x00, 0xff, 0x00, 0x00, 0x3b, 0x00, 0x17, 0x47, 0x80, 0x03, 0x01, 0x45, 0x18, 0x00,
0x01, 0x0f, 0xff 0x01, 0x0f, 0xff
}; };
#define ID_NORMAL 0x55201041 #define ID_NORMAL 0x55201041
#define ID_PLUS 0xAA201041 #define ID_PLUS 0xAA201041
/*
static const uint8_t a7105Regs[] = {
-1, 0x42, 0x00, 0x14, 0x00, -1 , -1 , 0x00, 0x00, 0x00, 0x00, 0x01, 0x21, 0x05, 0x00, 0x50,
0x9e, 0x4b, 0x00, 0x02, 0x16, 0x2b, 0x12, 0x00, 0x62, 0x80, 0x80, 0x00, 0x0a, 0x32, 0xc3, 0x0f,
0x13, 0xc3, 0x00, -1, 0x00, 0x00, 0x3b, 0x00, 0x17, 0x47, 0x80, 0x03, 0x01, 0x45, 0x18, 0x00,
0x01, 0x0f, -1,
};
*/
void A7105_Init(uint8_t protocol) void A7105_Init(uint8_t protocol)
{ {
void *A7105_Regs; void *A7105_Regs;

View File

@ -181,14 +181,15 @@ static void __attribute__((unused)) hubsan_build_packet()
} }
#if defined(TELEMETRY) #if defined(TELEMETRY)
/*static uint8_t hubsan_check_integrity() static uint8_t __attribute__((unused)) hubsan_check_integrity()
{ {
int sum = 0; if( (packet[0]&0xFE) != 0xE0 )
return 0;
uint8_t sum = 0;
for(uint8_t i = 0; i < 15; i++) for(uint8_t i = 0; i < 15; i++)
sum += packet[i]; sum += packet[i];
return packet[15] == ((256 - (sum % 256)) & 0xFF); return ( packet[15] == (uint8_t)(-sum) );
} }
*/
#endif #endif
uint16_t ReadHubsan() uint16_t ReadHubsan()
@ -295,7 +296,8 @@ uint16_t ReadHubsan()
} }
else { else {
#if defined(TELEMETRY) #if defined(TELEMETRY)
if( rfMode == A7105_TX) {// switch to rx mode 3ms after packet sent if( rfMode == A7105_TX)
{// switch to rx mode 3ms after packet sent
for( i=0; i<10; i++) for( i=0; i<10; i++)
{ {
if( !(A7105_ReadReg(A7105_00_MODE) & 0x01)) {// wait for tx completion if( !(A7105_ReadReg(A7105_00_MODE) & 0x01)) {// wait for tx completion
@ -306,15 +308,23 @@ uint16_t ReadHubsan()
} }
} }
} }
if( rfMode == A7105_RX) { // check for telemetry frame if( rfMode == A7105_RX)
for( i=0; i<10; i++) { { // check for telemetry frame
if( !(A7105_ReadReg(A7105_00_MODE) & 0x01)) { // data received for( i=0; i<10; i++)
{
if( !(A7105_ReadReg(A7105_00_MODE) & 0x01))
{ // data received
A7105_ReadData(); A7105_ReadData();
if( !(A7105_ReadReg(A7105_00_MODE) & 0x01)){ // data received if( hubsan_check_integrity() )
v_lipo=packet[13];// hubsan lipo voltage 8bits the real value is h_lipo/10(0x2A=42-4.2V) {
v_lipo=packet[13];// hubsan lipo voltage 8bits the real value is h_lipo/10(0x2A=42 -> 4.2V)
telemetry_link=1; telemetry_link=1;
} }
A7105_Strobe(A7105_RX); A7105_Strobe(A7105_RX);
// Read TX RSSI
RSSI_dBm=256-(A7105_ReadReg(A7105_1D_RSSI_THOLD)*8)/5; // value from A7105 is between 8 for maximum signal strength to 160 or less
if(RSSI_dBm<0) RSSI_dBm=0;
else if(RSSI_dBm>255) RSSI_dBm=255;
break; break;
} }
} }
@ -344,7 +354,6 @@ uint16_t initHubsan() {
packet_count=0; packet_count=0;
id_data=ID_NORMAL; id_data=ID_NORMAL;
#if defined(TELEMETRY) #if defined(TELEMETRY)
v_lipo=0;
telemetry_link=0; telemetry_link=0;
#endif #endif
return 10000; return 10000;

View File

@ -100,7 +100,6 @@ uint8_t pktt[MAX_PKT];//telemetry receiving packets
int16_t RSSI_dBm; int16_t RSSI_dBm;
//const uint8_t RSSI_offset=72;//69 71.72 values db //const uint8_t RSSI_offset=72;//69 71.72 values db
uint8_t telemetry_link=0; uint8_t telemetry_link=0;
#include "telemetry.h"
#endif #endif
// Callback // Callback
@ -623,11 +622,11 @@ uint16_t limit_channel_100(uint8_t ch)
#if defined(TELEMETRY) #if defined(TELEMETRY)
void Serial_write(uint8_t data) void Serial_write(uint8_t data)
{ {
uint8_t t=tx_head; cli(); // disable global int
if(++t>=TXBUFFER_SIZE) if(++tx_head>=TXBUFFER_SIZE)
t=0; tx_head=0;
tx_buff[t]=data; tx_buff[tx_head]=data;
tx_head=t; sei(); // enable global int
UCSR0B |= (1<<UDRIE0);//enable UDRE interrupt UCSR0B |= (1<<UDRIE0);//enable UDRE interrupt
} }
#endif #endif
@ -647,6 +646,7 @@ static void Mprotocol_serial_init()
UCSR0B |= (1<<TXEN0);//tx enable UCSR0B |= (1<<TXEN0);//tx enable
} }
#if defined(TELEMETRY)
static void PPM_Telemetry_serial_init() static void PPM_Telemetry_serial_init()
{ {
//9600 bauds //9600 bauds
@ -656,6 +656,7 @@ static void PPM_Telemetry_serial_init()
UCSR0C |= (1<<UCSZ01)|(1<<UCSZ00); UCSR0C |= (1<<UCSZ01)|(1<<UCSZ00);
UCSR0B |= (1<<TXEN0);//tx enable UCSR0B |= (1<<TXEN0);//tx enable
} }
#endif
// Convert 32b id to rx_tx_addr // Convert 32b id to rx_tx_addr
static void set_rx_tx_addr(uint32_t id) static void set_rx_tx_addr(uint32_t id)

View File

@ -39,25 +39,24 @@ void compute_RSSIdbm(){
void frsky_link_frame() void frsky_link_frame()
{ {
frame[0] = 0xfe; frame[0] = 0xFE;
if ((cur_protocol[0]&0x1F)==MODE_FRSKY) if ((cur_protocol[0]&0x1F)==MODE_FRSKY)
{ {
compute_RSSIdbm(); compute_RSSIdbm();
frame[1] = pktt[3]; frame[1] = pktt[3];
frame[2] = pktt[4]; frame[2] = pktt[4];
frame[3] = (uint8_t)RSSI_dBm; frame[3] = (uint8_t)RSSI_dBm;
frame[4] = pktt[5]*2; frame[4] = pktt[5]*2;
frame[5] = frame[6] = frame[7] = frame[8] = 0; }
}
else else
if ((cur_protocol[0]&0x1F)==MODE_HUBSAN) if ((cur_protocol[0]&0x1F)==MODE_HUBSAN)
{ {
frame[1] = v_lipo*2; //v_lipo; common 0x2A=42/10=4.2V frame[1] = v_lipo*2; //v_lipo; common 0x2A=42/10=4.2V
frame[2] = frame[1]; frame[2] = frame[1];
frame[3] =0X6e; frame[3] = 0x00;
frame[4] =2*0x6e; frame[4] = (uint8_t)RSSI_dBm;
frame[5] = frame[6] = frame[7] = frame[8] = 0; }
} frame[5] = frame[6] = frame[7] = frame[8] = 0;
frskySendStuffed(); frskySendStuffed();
} }
@ -141,7 +140,7 @@ void frskyUpdate()
return; return;
} }
#if defined HUB_TELEMETRY #if defined HUB_TELEMETRY
if(!telemetry_link) if(!telemetry_link && (cur_protocol[0]&0x1F) != MODE_HUBSAN )
frsky_user_frame(); frsky_user_frame();
#endif #endif
} }

View File

@ -44,7 +44,7 @@ local function run_func(proto, sw)
-- delais init -- delais init
if proto ~= debut then if proto ~= debut then
tps = getTime() + 500 -- delai pour mini 12 cycle PPM tps = getTime() + 250 -- delai pour mini 12 cycle PPM
tpsact = 1024 tpsact = 1024
debut = proto debut = proto
end end
@ -54,7 +54,7 @@ local function run_func(proto, sw)
local dir = 0 local dir = 0
local pro = 0 local pro = 0
if tpsact == 0 and sw < 200 then if tpsact == 0 and sw < 100 then
-- reprise valeur input -- reprise valeur input
pro = getValue(1) pro = getValue(1)
ail = getValue(2) ail = getValue(2)
@ -82,7 +82,10 @@ local function run_func(proto, sw)
if proto % 3 == 1 then dir = -1024 end if proto % 3 == 1 then dir = -1024 end
if proto % 3 == 0 then dir = 1024 end if proto % 3 == 0 then dir = 1024 end
if tps < getTime() then tpsact = 0 end if tps < getTime() then
tpsact = tpsact - 512
if tpsact>-20 then tps = getTime() + 250 end
end
sw = tpsact sw = tpsact
end end

View File

@ -13,6 +13,14 @@
along with Multiprotocol. If not, see <http://www.gnu.org/licenses/>. along with Multiprotocol. If not, see <http://www.gnu.org/licenses/>.
*/ */
// Check selected board type
#ifndef ARDUINO_AVR_PRO
#error You must select the board type "Arduino Pro or Pro Mini"
#endif
#if F_CPU != 16000000L || not defined(__AVR_ATmega328P__)
#error You must select the processor type "ATmega328(5V, 16MHz)"
#endif
//****************** //******************
// Protocols // Protocols
//****************** //******************

Binary file not shown.

Binary file not shown.

Binary file not shown.

Before

Width:  |  Height:  |  Size: 70 KiB

After

Width:  |  Height:  |  Size: 77 KiB