Skip to content

Commit 4290c75

Browse files
author
Pascal Langer
committed
HoTT: support for auto sensors discovery and sensors text config
1 parent cc6be60 commit 4290c75

1 file changed

Lines changed: 143 additions & 31 deletions

File tree

Multiprotocol/HOTT_cc2500.ino

Lines changed: 143 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,15 @@ enum {
3333
HOTT_RX2 = 0x04,
3434
};
3535

36+
#ifdef HOTT_FW_TELEMETRY
37+
#define HOTT_SENSOR_TYPE 6
38+
#define HOTT_SENSOR_SEARCH_PERIOD 120
39+
uint8_t HOTT_sensor_cur=0;
40+
uint8_t HOTT_sensor_pages=0;
41+
uint8_t HOTT_sensor_valid=false;
42+
uint8_t HOTT_sensor_ok[HOTT_SENSOR_TYPE];
43+
#endif
44+
3645
#define HOTT_FREQ0_VAL 0x6E
3746

3847
// Some important initialization parameters, all others are either default,
@@ -213,21 +222,30 @@ static void __attribute__((unused)) HOTT_data_packet()
213222

214223
#ifdef HOTT_FW_TELEMETRY
215224
static uint8_t prev_SerialRX_val=0;
216-
if(HoTT_SerialRX && HoTT_SerialRX_val >= 0xD7 && HoTT_SerialRX_val <= 0xDF)
217-
{
218-
if(prev_SerialRX_val!=HoTT_SerialRX_val)
219-
{
220-
prev_SerialRX_val=HoTT_SerialRX_val;
221-
packet[28] = HoTT_SerialRX_val; // send the touch being pressed only once
225+
if(HoTT_SerialRX)
226+
{//Text mode
227+
uint8_t sensor=HoTT_SerialRX_val&0xF0;
228+
if((sensor&0x80) && sensor!=0xF0 && (HoTT_SerialRX_val&0x0F) >= 0x07)
229+
{//Valid Text query
230+
if(sensor==0x80) HoTT_SerialRX_val&=0x0F; // RX only
231+
if(prev_SerialRX_val!=HoTT_SerialRX_val)
232+
{
233+
prev_SerialRX_val=HoTT_SerialRX_val;
234+
packet[28] = HoTT_SerialRX_val; // send the button being pressed only once
235+
}
236+
else
237+
packet[28] = HoTT_SerialRX_val | 0x0F; // no button pressed
238+
packet[29] = 0x01; // 0x01->Text config menu
222239
}
223-
else
224-
packet[28] = 0xDF; // no touch pressed
225-
packet[29] = 0x01; // 0x01->config menu
226240
}
227241
else
228242
{
229-
packet[28] = 0x8C; // unknown 0x80 when bind starts then when RX replies start normal, 0x89/8A/8B/8C/8D/8E during normal packets, 0x0F->config menu
230-
packet[29] = 0x02; // unknown 0x02 when bind starts then when RX replies cycle in sequence 0x1A/22/2A/0A/12, 0x02 during normal packets, 0x01->config menu, 0x0A->no more RX telemetry
243+
#ifdef HOTT_FW_TELEMETRY
244+
packet[28] = 0x89+HOTT_sensor_cur; // 0x89/8A/8B/8C/8D/8E during normal packets
245+
#else
246+
packet[28] = 0x80; // no sensor
247+
#endif
248+
packet[29] = 0x02; // unknown 0x02 when bind starts then when RX replies cycle in sequence 0x1A/22/2A/0A/12, 0x02 during normal packets, 0x01->text config menu, 0x0A->no more RX telemetry
231249
}
232250
#endif
233251

@@ -296,8 +314,8 @@ uint16_t ReadHOTT()
296314
if (len==HOTT_RX_PACKET_LEN+2)
297315
{
298316
CC2500_ReadData(packet_in, len);
299-
if(memcmp(rx_tx_addr,packet_in,5)==0)
300-
{ // TX ID matches
317+
if((packet_in[HOTT_RX_PACKET_LEN+1]&0x80) && memcmp(rx_tx_addr,packet_in,5)==0)
318+
{ // CRC OK and TX ID matches
301319
if(IS_BIND_IN_PROGRESS)
302320
{
303321
debug("B:");
@@ -317,39 +335,119 @@ uint16_t ReadHOTT()
317335
// [5..9] = RXID
318336
// [10] = 0x40 bind, 0x00 normal, 0x80 config menu
319337
// [11] = telmetry pages. For sensors 0x00 to 0x04, for config mennu 0x00 to 0x12.
320-
// Normal telem page 0 = 0x00, 0x33, 0x34, 0x46, 0x64, 0x33, 0x0A, 0x00, 0x00, 0x00
321-
// = 0x55, 0x32, 0x38, 0x55, 0x64, 0x32, 0xD0, 0x07, 0x00, 0x55
322-
// Page 0 [12] = [21] = ??
323-
// Page 0 [13] = RX_Voltage*10 in V
338+
// Normal telem page 0 = 0x55, 0x32, 0x38, 0x55, 0x64, 0x32, 0xD0, 0x07, 0x00, 0x55
339+
// Page 0 [12] = [21] = [15]
340+
// Page 0 [13] = RX_Voltage Cur*10 in V
324341
// Page 0 [14] = Temperature-20 in °C
325-
// Page 0 [15] = RX_RSSI
326-
// Page 0 [16] = RX_LQI ??
327-
// Page 0 [17] = RX_STR ??
342+
// Page 0 [15] = RX_RSSI CC2500 formated (a<128:a/2-71dBm, a>=128:(a-256)/2-71dBm)
343+
// Page 0 [16] = RX_LQI in %
344+
// Page 0 [17] = RX_Voltage Min*10 in V
328345
// Page 0 [18,19] = [19]*256+[18]=max lost packet time in ms, max value seems 2s=0x7D0
329346
// Page 0 [20] = 0x00 ??
347+
// Page 1 = 00 01 C0 00 00 72 00 70 00 00 00 34 // ESC Telem 1
348+
// Page 1 [12] = 0xC0 ?? ESC type ??
349+
// Page 1 [13] = 0x00 ??
350+
// Page 1 [14] = 0x00 ??
351+
// Page 1 [15] = Batt_L Cur voltage*10 in V
352+
// Page 1 [16] = Batt_H Cur -> not sure since I can't test but
353+
// Page 1 [17] = Batt_L Min voltage*10 in V
354+
// Page 1 [18] = Batt_H Min -> not sure since I can't test but
355+
// Page 1 [19] = 0x00 ??
356+
// Page 1 [20] = 0x00 ??
357+
// Page 1 [21] = 0x29..34 looks like temperature-20 in °C
358+
// Page 2 =00 02 30 00 00 00 00 B4 1F 8E 2E 14 // ESC Telem 2
359+
// Page 2 [12] = Page 1 [21] = 0x29..34 looks like temperature-20 in °C
360+
// Page 2 [13] = 0x00 ??
361+
// Page 2 [14] = 0x00 ??
362+
// Page 2 [15] = 0x00 ??
363+
// Page 2 [16] = 0x00 ??
364+
// Page 2 [17] = RPM_L Cur
365+
// Page 2 [18] = RPM_H Cur
366+
// Page 2 [19] = RPM_L Max
367+
// Page 2 [20] = RPM_H Max
368+
// Page 2 [21] = 0x14 ??
369+
// Page 3 =00 03 14 00 00 00 00 00 00 00 00 00 // ESC Telem 3
370+
// Page 3 [12] = Page 2 [21] = ??
371+
// Page 3 [13] = 0x00 ??
372+
// Page 3 [14] = 0x00 ??
373+
// Page 3 [15] = 0x00 ??
374+
// Page 3 [16] = 0x00 ??
375+
// Page 3 [17] = 0x00 ??
376+
// Page 3 [18] = 0x00 ??
377+
// Page 3 [19] = 0x00 ??
378+
// Page 3 [20] = 0x00 ??
379+
// Page 3 [21] = 0x00 ??
380+
//
330381
// Config menu consists of the different telem pages put all together
331382
// Page X [12] = seems like all the telem pages with the same value are going together to make the full config menu text. Seen so far 'a', 'b', 'c', 'd'
332383
// Page X [13..21] = 9 ascii chars to be displayed, char is highlighted when ascii|0x80
333384
// Screen display is 21 characters large which means that once the first 21 chars are filled go to the begining of the next line
334385
// Menu commands are sent through TX packets:
335386
// packet[28]= 0xXF=>no key press, 0xXD=>down, 0xXB=>up, 0xX9=>enter, 0xXE=>right, 0xX7=>left with X=0 or D
336387
// packet[29]= 0xX1/0xX9 with X=0 or X counting 0,1,1,2,2,..,9,9
337-
TX_RSSI = packet_in[22];
338-
if(TX_RSSI >=128)
339-
TX_RSSI -= 128;
340-
else
341-
TX_RSSI += 128;
342388
// Reduce telemetry to 14 bytes
343-
packet_in[0]= TX_RSSI;
389+
packet_in[0]= packet_in[HOTT_RX_PACKET_LEN];
344390
packet_in[1]= TX_LQI;
345-
debug("T=");
391+
bool send_telem=true;
392+
bool disp = true;
393+
if(packet[29]==2) // Requesting binary sensor
394+
{
395+
if( packet_in[11]==1 ) // Page 1
396+
{
397+
if(packet_sent)
398+
packet_sent--;
399+
if( packet_in[12] == ((HOTT_sensor_cur+9)<<4) ) // The current sensor is responding: 0x90/A0/B0/C0/D0/E0
400+
{
401+
HOTT_sensor_pages = 0; // Sensor first page received
402+
HOTT_sensor_valid = true; // Data from the expected sensor is being received
403+
HOTT_sensor_ok[HOTT_sensor_cur]=true;
404+
}
405+
else
406+
{
407+
HOTT_sensor_valid = false;
408+
HOTT_sensor_pages = 0x1E; // Switch to next sensor
409+
}
410+
}
411+
if(HOTT_sensor_valid && packet_in[11] ) // Valid & page !=0
412+
{
413+
packet_in[10] = HOTT_sensor_cur+9; // Marking telem with sensor ID
414+
HOTT_sensor_pages |= 1<<packet_in[11]; // Page received
415+
}
416+
if(packet_in[11] && !HOTT_sensor_valid)
417+
send_telem=false;
418+
}
419+
else
420+
{ //Text mode
421+
HOTT_sensor_pages = 0;
422+
HOTT_sensor_valid = false;
423+
packet_in[10] = 0x80; // Marking telem Text mode
424+
packet_in[12] = 0;
425+
for(uint8_t i=0; i<HOTT_SENSOR_TYPE;i++)
426+
packet_in[12] |= HOTT_sensor_ok[i]<<i; // Send detected sensors
427+
}
428+
if(disp) debug("T%d=",send_telem);
346429
for(uint8_t i=10;i < HOTT_RX_PACKET_LEN; i++)
347430
{
348431
packet_in[i-8]=packet_in[i];
349-
debug(" %02X",packet_in[i]);
432+
if(disp) debug(" %02X",packet_in[i]);
350433
}
351-
debugln("");
352-
telemetry_link=2;
434+
if(disp) debugln("");
435+
if(send_telem)
436+
telemetry_link=2;
437+
if((HOTT_sensor_pages&0x1E) == 0x1E) // All 4 pages received from the sensor
438+
{
439+
HOTT_sensor_valid=false;
440+
HOTT_sensor_pages=0;
441+
uint8_t loop=0;
442+
do
443+
{
444+
HOTT_sensor_cur++; // Switch to next sensor
445+
HOTT_sensor_cur %= HOTT_SENSOR_TYPE;
446+
loop++;
447+
}
448+
while(HOTT_sensor_ok[HOTT_sensor_cur]==false && loop<HOTT_SENSOR_TYPE+1 && packet_sent==0);
449+
debugln("Sensor:%02X",((HOTT_sensor_cur+9)<<4));
450+
}
353451
}
354452
pps_counter++;
355453
#endif
@@ -360,6 +458,14 @@ uint16_t ReadHOTT()
360458
if(packet_count>=100)
361459
{
362460
TX_LQI=pps_counter;
461+
if(pps_counter==0)
462+
{ // lost connection with RX, power cycle? research sensors again.
463+
HOTT_sensor_cur=0;
464+
HOTT_sensor_valid=false;
465+
for(uint8_t i=0; i<HOTT_SENSOR_TYPE;i++)
466+
HOTT_sensor_ok[i]=false; // no sensors detected
467+
packet_sent=HOTT_SENSOR_SEARCH_PERIOD;
468+
}
363469
pps_counter=packet_count=0;
364470
}
365471
#endif
@@ -375,10 +481,16 @@ uint16_t initHOTT()
375481
num_ch=random(0xfefefefe)%16;
376482
HOTT_init();
377483
HOTT_rf_init();
378-
packet_count=0;
379484
#ifdef HOTT_FW_TELEMETRY
380485
HoTT_SerialRX_val=0;
381486
HoTT_SerialRX=false;
487+
HOTT_sensor_cur=0;
488+
HOTT_sensor_pages=0;
489+
HOTT_sensor_valid=false;
490+
for(uint8_t i=0; i<HOTT_SENSOR_TYPE;i++)
491+
HOTT_sensor_ok[i]=false; // no sensors detected
492+
packet_count=0;
493+
packet_sent=HOTT_SENSOR_SEARCH_PERIOD;
382494
#endif
383495
phase = HOTT_START;
384496
return 10000;

0 commit comments

Comments
 (0)