mirror of
https://github.com/pascallanger/DIY-Multiprotocol-TX-Module.git
synced 2025-07-01 01:57:52 +00:00
Multi Config
This commit is contained in:
parent
37e029c612
commit
84780a9d90
142
Lua_scripts/MultiConfig.lua
Normal file
142
Lua_scripts/MultiConfig.lua
Normal file
@ -0,0 +1,142 @@
|
||||
---- #########################################################################
|
||||
---- # #
|
||||
---- # Copyright (C) OpenTX #
|
||||
-----# #
|
||||
---- # License GPLv2: http://www.gnu.org/licenses/gpl-2.0.html #
|
||||
---- # #
|
||||
---- # This program is free software; you can redistribute it and/or modify #
|
||||
---- # it under the terms of the GNU General Public License version 2 as #
|
||||
---- # published by the Free Software Foundation. #
|
||||
---- # #
|
||||
---- # This program 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. #
|
||||
---- # #
|
||||
---- #########################################################################
|
||||
|
||||
|
||||
--###############################################################################
|
||||
-- Multi buffer for Config description
|
||||
-- To start operation:
|
||||
-- Write 0xFF at address 4 will request the buffer to be cleared
|
||||
-- Write "Conf" at address 0..3
|
||||
-- Read
|
||||
-- Read at address 12 gives the current config page
|
||||
-- Read at address 13..172 gives the current data of the page = 8 lines * 20 caracters
|
||||
-- Write
|
||||
-- Write at address 5..11 the command
|
||||
-- Write 0x01 at address 4 will send the command to the module
|
||||
--###############################################################################
|
||||
|
||||
local function Config_Release()
|
||||
end
|
||||
|
||||
local function Config_Page( event )
|
||||
end
|
||||
|
||||
local function Config_Menu( event )
|
||||
end
|
||||
|
||||
local function Config_Draw_LCD()
|
||||
local i
|
||||
local value
|
||||
local line
|
||||
local result
|
||||
local offset=0
|
||||
|
||||
lcd.clear()
|
||||
|
||||
if LCD_W == 480 then
|
||||
--Draw title
|
||||
lcd.drawFilledRectangle(0, 0, LCD_W, 30, TITLE_BGCOLOR)
|
||||
if multiBuffer(13) == 0x00 then
|
||||
lcd.drawText(1, 5, "Multi Config", MENU_TITLE_COLOR)
|
||||
lcd.drawText(10,50,"No Config telemetry...", BLINK)
|
||||
else
|
||||
lcd.drawText(1, 5, "Multi Config v" .. string.char(multiBuffer(13)) .. "." .. string.char(multiBuffer(14)) .. "." .. string.char(multiBuffer(15)) .. "." .. string.char(multiBuffer(16)), MENU_TITLE_COLOR)
|
||||
--Draw RX Menu
|
||||
for line = 1, 7, 1 do
|
||||
for i = 0, 20-1, 1 do
|
||||
value=multiBuffer( line*20+13+i )
|
||||
if value > 0x00 and value < 0x80 then
|
||||
lcd.drawText(10+i*16,32+20*line,string.char(value))
|
||||
--lcd.drawText(10+i*16,32+20*line,string.char(value).." ",INVERS)
|
||||
else
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
else
|
||||
--Draw RX Menu on LCD_W=128
|
||||
-- if multiBuffer( 4 ) == 0xFF then
|
||||
-- lcd.drawText(2,17,"No Config telemetry...",SMLSIZE)
|
||||
-- else
|
||||
-- if Timer_128 ~= 0 then
|
||||
--Intro page
|
||||
-- Timer_128 = Timer_128 - 1
|
||||
-- lcd.drawScreenTitle("Graupner Hott",0,0)
|
||||
-- lcd.drawText(2,17,"Configuration of RX" .. sensor_name[Config_Sensor+1] ,SMLSIZE)
|
||||
-- lcd.drawText(2,37,"Press menu to cycle Sensors" ,SMLSIZE)
|
||||
-- else
|
||||
--Menu page
|
||||
-- for line = 0, 7, 1 do
|
||||
-- for i = 0, 21-1, 1 do
|
||||
-- value=multiBuffer( line*21+6+i )
|
||||
-- if value > 0x80 then
|
||||
-- value = value - 0x80
|
||||
-- lcd.drawText(2+i*6,1+8*line,string.char(value).." ",SMLSIZE+INVERS)
|
||||
-- else
|
||||
-- lcd.drawText(2+i*6,1+8*line,string.char(value),SMLSIZE)
|
||||
-- end
|
||||
-- end
|
||||
-- end
|
||||
-- end
|
||||
-- end
|
||||
end
|
||||
end
|
||||
|
||||
-- Init
|
||||
local function Config_Init()
|
||||
--Set protocol to talk to
|
||||
multiBuffer( 0, string.byte('C') )
|
||||
--test if value has been written
|
||||
if multiBuffer( 0 ) ~= string.byte('C') then
|
||||
error("Not enough memory!")
|
||||
return 2
|
||||
end
|
||||
--Request init of the buffer
|
||||
multiBuffer( 4, 0xFF )
|
||||
--Continue buffer init
|
||||
multiBuffer( 1, string.byte('o') )
|
||||
multiBuffer( 2, string.byte('n') )
|
||||
multiBuffer( 3, string.byte('f') )
|
||||
end
|
||||
|
||||
-- Main
|
||||
local function Config_Run(event)
|
||||
if event == nil then
|
||||
error("Cannot be run as a model script!")
|
||||
return 2
|
||||
elseif event == EVT_VIRTUAL_EXIT then
|
||||
Config_Release()
|
||||
return 2
|
||||
else
|
||||
if event == EVT_VIRTUAL_PREV_PAGE then
|
||||
killEvents(event)
|
||||
Config_Page( event )
|
||||
elseif event == EVT_VIRTUAL_ENTER then
|
||||
Config_Menu( event )
|
||||
elseif event == EVT_VIRTUAL_PREV then
|
||||
Config_Menu( event )
|
||||
elseif event == EVT_VIRTUAL_NEXT then
|
||||
Config_Menu( event )
|
||||
elseif event == EVT_VIRTUAL_NEXT_PAGE then
|
||||
Config_Page( event )
|
||||
end
|
||||
Config_Draw_LCD()
|
||||
return 0
|
||||
end
|
||||
end
|
||||
|
||||
return { init=Config_Init, run=Config_Run }
|
179
Multiprotocol/Multi_Config.ino
Normal file
179
Multiprotocol/Multi_Config.ino
Normal file
@ -0,0 +1,179 @@
|
||||
/*
|
||||
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/>.
|
||||
*/
|
||||
|
||||
#if defined(MULTI_CONFIG_INO)
|
||||
|
||||
#ifdef CYRF6936_INSTALLED
|
||||
#include "iface_cyrf6936.h"
|
||||
#endif
|
||||
|
||||
void CONFIG_write_ID(uint32_t id)
|
||||
{
|
||||
for(uint8_t i=0;i<4;i++)
|
||||
eeprom_write_byte((EE_ADDR)EEPROM_ID_OFFSET+i,id >> (i*8));
|
||||
eeprom_write_byte((EE_ADDR)(EEPROM_ID_OFFSET+10),0xf0);
|
||||
}
|
||||
|
||||
uint16_t CONFIG_callback()
|
||||
{
|
||||
static uint8_t line=0, page=0;
|
||||
uint32_t id=0;
|
||||
// [0] = page<<4|line number
|
||||
// [1..6] = max 6 bytes
|
||||
if(CONFIG_SerialRX)
|
||||
{
|
||||
debug("config");
|
||||
for(uint8_t i=0; i<7; i++)
|
||||
debug("%02X ",CONFIG_SerialRX_val[i]);
|
||||
debugln("");
|
||||
CONFIG_SerialRX = false;
|
||||
switch(CONFIG_SerialRX_val[0]&0x0F)
|
||||
{
|
||||
//case 0:
|
||||
// Page change
|
||||
// break;
|
||||
case 1:
|
||||
for(uint8_t i=0; i<4; i++)
|
||||
{
|
||||
id <<= 8;
|
||||
id |= CONFIG_SerialRX_val[i+1];
|
||||
}
|
||||
debugln("Update ID to %lx", id);
|
||||
CONFIG_write_ID(id);
|
||||
break;
|
||||
case 2:
|
||||
if(CONFIG_SerialRX_val[1]==0xAA)
|
||||
{
|
||||
#define STM32_UUID ((uint32_t *)0x1FFFF7E8)
|
||||
id = STM32_UUID[0] ^ STM32_UUID[1] ^ STM32_UUID[2];
|
||||
debugln("Reset GID to %lx", id);
|
||||
CONFIG_write_ID(id);
|
||||
}
|
||||
break;
|
||||
#ifdef CYRF6936_INSTALLED
|
||||
case 4:
|
||||
debug("Update CID to ");
|
||||
for(uint8_t i=0; i<6; i++)
|
||||
debug("%02X ",CONFIG_SerialRX_val[i+1]);
|
||||
debugln("");
|
||||
case 5:
|
||||
if(CONFIG_SerialRX_val[1]==0xAA)
|
||||
{
|
||||
uint8_t data[6];
|
||||
CYRF_WriteRegister(CYRF_25_MFG_ID, 0xFF); /* Fuses power on */
|
||||
CYRF_ReadRegisterMulti(CYRF_25_MFG_ID, data, 6);
|
||||
CYRF_WriteRegister(CYRF_25_MFG_ID, 0x00); /* Fuses power off */
|
||||
debug("Reset CID to ");
|
||||
for(uint8_t i=0; i<6; i++)
|
||||
debug("%02X ",data[i]);
|
||||
debugln("");
|
||||
}
|
||||
break;
|
||||
#endif
|
||||
case 7:
|
||||
if(CONFIG_SerialRX_val[1]==0xAA)
|
||||
{
|
||||
debugln("Format EE");
|
||||
EEPROM.format();
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if( telemetry_link )
|
||||
return 10000;
|
||||
// [0] = page<<4|line number
|
||||
// line=0: VERSION_MAJOR, VERSION_MINOR, VERSION_REVISION, VERSION_PATCH_LEVEL, Channel order:RUDDER<<6|THROTTLE<<4|ELEVATOR<<2|AILERON
|
||||
// [1..21] = max 20 characters, any displayable chars followed by:
|
||||
// 0x00 : end of line
|
||||
// 0x80+len: selectable text to follow
|
||||
// 0x90+len: selectable text to follow with "Are you sure?"
|
||||
// 0xA0+len: not editable dec value
|
||||
// 0xB0+len: editable dec value
|
||||
// 0xC0+len: not editable hex value
|
||||
// 0xD0+len: editable hex value
|
||||
memset(&packet_in[1],0,20);
|
||||
do
|
||||
{
|
||||
packet_in[0] = (page<<4) | line;
|
||||
switch(line)
|
||||
{
|
||||
case 0:
|
||||
packet_in[1]=VERSION_MAJOR;
|
||||
packet_in[2]=VERSION_MINOR;
|
||||
packet_in[3]=VERSION_REVISION;
|
||||
packet_in[4]=VERSION_PATCH_LEVEL;
|
||||
packet_in[5]=RUDDER<<6|THROTTLE<<4|ELEVATOR<<2|AILERON;
|
||||
break;
|
||||
case 1:
|
||||
//Global ID
|
||||
#ifndef FORCE_GLOBAL_ID
|
||||
memcpy(&packet_in[1],"Global ID",9);
|
||||
packet_in[10] = 0xD0 + 4;
|
||||
#else
|
||||
memcpy(&packet_in[1],"Fixed ID ",9);
|
||||
packet_in[10] = 0xC0 + 4;
|
||||
#endif
|
||||
MProtocol_id_master = random_id(EEPROM_ID_OFFSET,false);
|
||||
set_rx_tx_addr(MProtocol_id_master);
|
||||
for(uint8_t i=0; i<4; i++)
|
||||
packet_in[11+i]=rx_tx_addr[i];
|
||||
break;
|
||||
#if defined(STM32_BOARD) && not defined(FORCE_GLOBAL_ID)
|
||||
case 2:
|
||||
//Reset global ID
|
||||
packet_in[1] = 0x90+9;
|
||||
memcpy(&packet_in[2],"Reset GID",9);
|
||||
break;
|
||||
#endif
|
||||
#ifdef CYRF6936_INSTALLED
|
||||
case 4:
|
||||
//Cyrf ID
|
||||
#ifndef FORCE_CYRF_ID
|
||||
memcpy(&packet_in[1],"Cyrf ID",7);
|
||||
packet_in[8] = 0xD0 + 6;
|
||||
CYRF_GetMfgData(&packet_in[9]);
|
||||
#else
|
||||
memcpy(&packet_in[1],"Fixed CID",9);
|
||||
packet_in[10] = 0xC0 + 6;
|
||||
CYRF_GetMfgData(&packet_in[11]);
|
||||
#endif
|
||||
break;
|
||||
#ifndef FORCE_CYRF_ID
|
||||
case 5:
|
||||
//Reset Cyrf ID
|
||||
packet_in[1] = 0x90+9;
|
||||
memcpy(&packet_in[2],"Reset CID",9);
|
||||
break;
|
||||
#endif
|
||||
#endif
|
||||
case 7:
|
||||
packet_in[1] = 0x90+13;
|
||||
memcpy(&packet_in[2],"Format EEPROM",13);
|
||||
break;
|
||||
}
|
||||
line++;
|
||||
line %= 8;
|
||||
}
|
||||
while(packet_in[1]==0); // next line if empty
|
||||
telemetry_link = 1;
|
||||
return 10000;
|
||||
}
|
||||
|
||||
void CONFIG_init()
|
||||
{
|
||||
}
|
||||
|
||||
#endif
|
@ -98,6 +98,7 @@ const char STR_E010R5[] ="E010r5";
|
||||
const char STR_LOLI[] ="LOLI";
|
||||
const char STR_E129[] ="E129";
|
||||
const char STR_E016H[] ="E016H";
|
||||
const char STR_CONFIG[] ="Config";
|
||||
|
||||
const char STR_SUBTYPE_FLYSKY[] = "\x04""Std\0""V9x9""V6x6""V912""CX20";
|
||||
const char STR_SUBTYPE_HUBSAN[] = "\x04""H107""H301""H501";
|
||||
@ -187,6 +188,7 @@ enum
|
||||
const mm_protocol_definition multi_protocols[] = {
|
||||
// Protocol number, Protocol String, Sub_protocol strings, Number of sub_protocols, Option type, Failsafe, ChMap, RF switch, Init, Callback
|
||||
#if defined(MULTI_CONFIG_INO)
|
||||
{0x00, STR_CONFIG, NO_SUBTYPE, 0, OPTION_NONE, 0, 0, 0, CONFIG_init, CONFIG_callback },
|
||||
{PROTO_CONFIG, STR_CONFIG, NO_SUBTYPE, 0, OPTION_NONE, 0, 0, 0, CONFIG_init, CONFIG_callback },
|
||||
#endif
|
||||
#if defined(ASSAN_NRF24L01_INO)
|
||||
@ -449,5 +451,5 @@ const mm_protocol_definition multi_protocols[] = {
|
||||
#if defined(NANORF_NRF24L01_INO)
|
||||
{PROTO_NANORF, STR_NANORF, NO_SUBTYPE, 0, OPTION_NONE, 0, 0, SW_NRF, NANORF_init, NANORF_callback },
|
||||
#endif
|
||||
{0x00, nullptr, nullptr, 0, 0, 0, 0, 0, nullptr, nullptr }
|
||||
{0xFF, nullptr, nullptr, 0, 0, 0, 0, 0, nullptr, nullptr }
|
||||
};
|
||||
|
@ -19,7 +19,7 @@
|
||||
#define VERSION_MAJOR 1
|
||||
#define VERSION_MINOR 3
|
||||
#define VERSION_REVISION 2
|
||||
#define VERSION_PATCH_LEVEL 62
|
||||
#define VERSION_PATCH_LEVEL 63
|
||||
|
||||
#define MODE_SERIAL 0
|
||||
|
||||
@ -113,6 +113,7 @@ enum PROTOCOLS
|
||||
PROTO_E129 = 83, // =>CYRF6936
|
||||
PROTO_JOYSWAY = 84, // =>A7105
|
||||
PROTO_E016H = 85, // =>NRF24L01
|
||||
PROTO_CONFIG = 86, // Module config
|
||||
|
||||
PROTO_NANORF = 126, // =>NRF24L01
|
||||
PROTO_TEST = 127, // =>CC2500
|
||||
@ -1258,4 +1259,8 @@ Serial: 100000 Baud 8e2 _ xxxx xxxx p --
|
||||
data[1] = TX_LQI
|
||||
data[2] = telem_type
|
||||
data[3-9] = data
|
||||
|
||||
Type 0x10 Config telemetry
|
||||
length: 22
|
||||
data[0..21] = Config data
|
||||
*/
|
||||
|
@ -1191,7 +1191,7 @@ static void protocol_init()
|
||||
#if defined(FRSKYX_CC2500_INO) && defined(EU_MODULE)
|
||||
if( ! ( (protocol == PROTO_FRSKYX || protocol == PROTO_FRSKYX2) && sub_protocol < 2 ) )
|
||||
#endif
|
||||
while(multi_protocols[index].protocol != 0)
|
||||
while(multi_protocols[index].protocol != 0xFF)
|
||||
{
|
||||
if(multi_protocols[index].protocol==protocol)
|
||||
{
|
||||
@ -1831,7 +1831,7 @@ static uint32_t random_id(uint16_t address, uint8_t create_new)
|
||||
}
|
||||
if(id!=0x2AD141A7) //ID with seed=0
|
||||
{
|
||||
debugln("Read ID from EEPROM");
|
||||
//debugln("Read ID from EEPROM");
|
||||
return id;
|
||||
}
|
||||
}
|
||||
|
@ -188,11 +188,11 @@ static void multi_send_status()
|
||||
else
|
||||
{
|
||||
// Protocol next/prev
|
||||
if(multi_protocols[multi_protocols_index+1].protocol != 0)
|
||||
if(multi_protocols[multi_protocols_index+1].protocol != 0xFF)
|
||||
{
|
||||
if(multi_protocols[multi_protocols_index+1].protocol == PROTO_SCANNER)
|
||||
{// if next is scanner
|
||||
if(multi_protocols[multi_protocols_index+2].protocol != 0)
|
||||
if(multi_protocols[multi_protocols_index+2].protocol != 0xFF)
|
||||
Serial_write(multi_protocols[multi_protocols_index+2].protocol); // skip to next protocol number
|
||||
else
|
||||
Serial_write(multi_protocols[multi_protocols_index].protocol); // or end of list
|
||||
@ -202,7 +202,7 @@ static void multi_send_status()
|
||||
}
|
||||
else
|
||||
Serial_write(multi_protocols[multi_protocols_index].protocol); // end of list
|
||||
if(multi_protocols_index>0)
|
||||
if(multi_protocols_index>0 && multi_protocols[multi_protocols_index-1].protocol != 0)
|
||||
{
|
||||
if(multi_protocols[multi_protocols_index-1].protocol==PROTO_SCANNER)
|
||||
{// if prev is scanner
|
||||
@ -241,8 +241,8 @@ static void multi_send_status()
|
||||
#ifdef MULTI_CONFIG_INO
|
||||
void CONFIG_frame()
|
||||
{
|
||||
multi_send_header(MULTI_TELEMETRY_CONFIG, packet_in[0]);
|
||||
for (uint8_t i = 1; i <= packet_in[0]; i++) // config data
|
||||
multi_send_header(MULTI_TELEMETRY_CONFIG, 21);
|
||||
for (uint8_t i = 0; i < 21; i++) // Config data
|
||||
Serial_write(packet_in[i]);
|
||||
}
|
||||
#endif
|
||||
|
Loading…
x
Reference in New Issue
Block a user