diff --git a/ESP32/include/DiyActivePedal_types.h b/ESP32/include/DiyActivePedal_types.h
index e02aaf73..5ed22e74 100644
--- a/ESP32/include/DiyActivePedal_types.h
+++ b/ESP32/include/DiyActivePedal_types.h
@@ -32,7 +32,7 @@ struct payloadHeader {
struct payloadPedalAction {
uint8_t triggerAbs_u8;
//uint8_t resetPedalPos_u8; //1=reset position, 2=restart ESP
- uint8_t system_action_u8; //1=reset position, 2=restart ESP
+ uint8_t system_action_u8; //1=reset position, 2=restart ESP, 3=OTA Enable, 4=enable pairing
uint8_t startSystemIdentification_u8;
uint8_t returnPedalConfig_u8;
uint8_t RPM_u8;
@@ -70,6 +70,7 @@ struct payloadPedalState_Extended {
struct payloadBridgeState {
uint8_t Pedal_RSSI;
uint8_t Pedal_availability[3];
+ uint8_t Bridge_action;//0=none, 1=enable pairing
};
struct payloadPedalConfig {
diff --git a/ESP32/include/ESPNOW_lib.h b/ESP32/include/ESPNOW_lib.h
index ad29023e..c1c3642e 100644
--- a/ESP32/include/ESPNOW_lib.h
+++ b/ESP32/include/ESPNOW_lib.h
@@ -27,6 +27,7 @@ uint8_t ESPNow_error_code=0;
bool ESPNow_Pairing_status = false;
bool UpdatePairingToEeprom = false;
bool ESPNow_pairing_action_b = false;
+bool software_pairing_action_b = false;
diff --git a/ESP32/src/Main.cpp b/ESP32/src/Main.cpp
index 0f77487b..5695bfaf 100644
--- a/ESP32/src/Main.cpp
+++ b/ESP32/src/Main.cpp
@@ -1374,6 +1374,12 @@ void serialCommunicationTask( void * pvParameters )
//OTA_enable_start=true;
ESPNow_OTA_enable=false;
}
+ //4 Enable pairing
+ if (dap_actions_st.payloadPedalAction_.system_action_u8==4)
+ {
+ Serial.println("Get Pairing command");
+ software_pairing_action_b=true;
+ }
// trigger ABS effect
if (dap_actions_st.payloadPedalAction_.triggerAbs_u8)
@@ -1675,7 +1681,7 @@ void ESPNOW_SyncTask( void * pvParameters )
else
{
#ifdef ESPNow_Pairing_function
- if(digitalRead(Pairing_GPIO)==LOW)
+ if(digitalRead(Pairing_GPIO)==LOW||software_pairing_action_b)
{
Serial.println("Pedal Pairing.....");
delay(1000);
@@ -1683,6 +1689,7 @@ void ESPNOW_SyncTask( void * pvParameters )
Pairing_state_last_sending=millis();
ESPNow_pairing_action_b=true;
building_dap_esppairing_lcl=true;
+ software_pairing_action_b=false;
}
if(ESPNow_pairing_action_b)
diff --git a/ESP32_master/include/DiyActivePedal_types.h b/ESP32_master/include/DiyActivePedal_types.h
index 7b650fe9..8d33dc11 100644
--- a/ESP32_master/include/DiyActivePedal_types.h
+++ b/ESP32_master/include/DiyActivePedal_types.h
@@ -67,7 +67,7 @@ struct payloadPedalState_Extended {
struct payloadBridgeState {
uint8_t Pedal_RSSI;
uint8_t Pedal_availability[3];
-
+ uint8_t Bridge_action;//0=none, 1=enable pairing
};
struct payloadPedalConfig {
diff --git a/ESP32_master/include/ESPNOW_lib.h b/ESP32_master/include/ESPNOW_lib.h
index a7d12d16..05e75d50 100644
--- a/ESP32_master/include/ESPNOW_lib.h
+++ b/ESP32_master/include/ESPNOW_lib.h
@@ -36,6 +36,7 @@ uint8_t pedal_status=0;
bool ESPNow_Pairing_status = false;
bool UpdatePairingToEeprom = false;
bool ESPNow_pairing_action_b = false;
+bool software_pairing_action_b = false;
bool MacCheck(uint8_t* Mac_A, uint8_t* Mac_B)
{
diff --git a/ESP32_master/src/Main.cpp b/ESP32_master/src/Main.cpp
index 413dfd79..74b4d096 100644
--- a/ESP32_master/src/Main.cpp
+++ b/ESP32_master/src/Main.cpp
@@ -84,6 +84,7 @@ DAP_config_st dap_config_st_Temp;
DAP_ESPPairing_st dap_esppairing_st;//saving
DAP_ESPPairing_st dap_esppairing_lcl;//sending
//DAP_config_st dap_config_st_store[3];
+DAP_bridge_state_st dap_bridge_state_lcl;//
#include "CycleTimer.h"
@@ -127,6 +128,7 @@ DAP_ESPPairing_st dap_esppairing_lcl;//sending
static const crgb_t L_PURPLE = 0x800080;
*/
Adafruit_NeoPixel pixels(LEDS_COUNT, LED_GPIO, NEO_RGB + NEO_KHZ800);
+ uint8_t LED_Status=0; //0=normal 1= pairing
#endif
@@ -407,7 +409,7 @@ void ESPNOW_SyncTask( void * pvParameters )
for(;;)
{
#ifdef ESPNow_Pairing_function
- if(digitalRead(Pairing_GPIO)==LOW)
+ if(digitalRead(Pairing_GPIO)==LOW||software_pairing_action_b)
{
Serial.println("Bridge Pairing.....");
delay(1000);
@@ -415,7 +417,8 @@ void ESPNOW_SyncTask( void * pvParameters )
Pairing_state_last_sending=millis();
ESPNow_pairing_action_b=true;
building_dap_esppairing_lcl=true;
-
+ LED_Status=1;
+ software_pairing_action_b=false;
}
if(ESPNow_pairing_action_b)
{
@@ -444,6 +447,7 @@ void ESPNOW_SyncTask( void * pvParameters )
{
Serial.println("Reach timeout");
ESPNow_pairing_action_b=false;
+ LED_Status=0;
if(UpdatePairingToEeprom)
{
EEPROM.put(EEPROM_offset,_ESP_pairing_reg);
@@ -656,17 +660,55 @@ void Serial_Task( void * pvParameters)
Serial.print(", CRC received: ");
Serial.println(dap_config_st.payloadFooter_.checkSum);
}
-
-
- // if checks are successfull, overwrite global configuration struct
- if (structChecker == true)
- {
+ // if checks are successfull, overwrite global configuration struct
+ if (structChecker == true)
+ {
//Serial.println("Updating pedal config");
- configUpdateAvailable = true;
+ configUpdateAvailable = true;
//memcpy(&dap_config_st, &dap_config_st_local, sizeof(dap_config_st));
- }
-
+ }
+ break;
+ case sizeof(DAP_bridge_state_st) :
+ DAP_bridge_state_st * dap_bridge_state_local_ptr;
+ dap_bridge_state_local_ptr = &dap_bridge_state_lcl;
+ Serial.readBytes((char*)dap_bridge_state_local_ptr, sizeof(DAP_bridge_state_st));
+ // check if data is plausible
+ if ( dap_bridge_state_lcl.payLoadHeader_.payloadType != DAP_PAYLOAD_TYPE_BRIDGE_STATE )
+ {
+ structChecker = false;
+ Serial.print("Payload type expected: ");
+ Serial.print(DAP_PAYLOAD_TYPE_BRIDGE_STATE);
+ Serial.print(", Payload type received: ");
+ Serial.println(dap_bridge_state_lcl.payLoadHeader_.payloadType);
+ }
+ if ( dap_bridge_state_lcl.payLoadHeader_.version != DAP_VERSION_CONFIG )
+ {
+ structChecker = false;
+ Serial.print("Config version expected: ");
+ Serial.print(DAP_VERSION_CONFIG);
+ Serial.print(", Config version received: ");
+ Serial.println(dap_bridge_state_lcl.payLoadHeader_.version);
+ }
+ // checksum validation
+ crc = checksumCalculator((uint8_t*)(&(dap_bridge_state_lcl.payLoadHeader_)), sizeof(dap_bridge_state_lcl.payLoadHeader_) + sizeof(dap_bridge_state_lcl.payloadBridgeState_));
+ if (crc != dap_bridge_state_lcl.payloadFooter_.checkSum)
+ {
+ structChecker = false;
+ Serial.print("CRC expected: ");
+ Serial.print(crc);
+ Serial.print(", CRC received: ");
+ Serial.println(dap_bridge_state_lcl.payloadFooter_.checkSum);
+ }
+ // if checks are successfull, overwrite global configuration struct
+ if (structChecker == true)
+ {
+ if(dap_bridge_state_lcl.payloadBridgeState_.Bridge_action==1)
+ {
+ Serial.println("Get action from Simhub:1");
+ software_pairing_action_b=true;
+ }
+ }
break;
default:
@@ -754,7 +796,7 @@ void Serial_Task( void * pvParameters)
Serial.println(dap_state_basic_st.payloadPedalState_Basic_.error_code_u8);
ESPNow_error_b=false;
}
- if(basic_rssi_update)
+ if(basic_rssi_update)//Bridge action
{
int rssi_filter_value=constrain(rssi_filter.process(rssi_display),-100,0) ;
dap_bridge_state_st.payloadBridgeState_.Pedal_RSSI=(uint8_t)(rssi_filter_value+101);
@@ -763,6 +805,7 @@ void Serial_Task( void * pvParameters)
dap_bridge_state_st.payLoadHeader_.version=DAP_VERSION_CONFIG;
crc = checksumCalculator((uint8_t*)(&(dap_bridge_state_st.payLoadHeader_)), sizeof(dap_bridge_state_st.payLoadHeader_) + sizeof(dap_bridge_state_st.payloadBridgeState_));
dap_bridge_state_st.payloadFooter_.checkSum=crc;
+ dap_bridge_state_st.payloadBridgeState_.Bridge_action=0;
DAP_bridge_state_st * dap_bridge_st_local_ptr;
dap_bridge_st_local_ptr = &dap_bridge_state_st;
Serial.write((char*)dap_bridge_st_local_ptr, sizeof(DAP_bridge_state_st));
@@ -900,57 +943,75 @@ void LED_Task( void * pvParameters)
{
#ifdef LED_ENABLE_WAVESHARE
//LED status update
- if(LED_bright_index>30)
- {
- LED_bright_direction=-1;
- }
- if(LED_bright_index<2)
+ if(LED_Status==0)
{
- LED_bright_direction=1;
+ if(LED_bright_index>30)
+ {
+ LED_bright_direction=-1;
+ }
+ if(LED_bright_index<2)
+ {
+ LED_bright_direction=1;
+ }
+ LED_bright_index=LED_bright_index+LED_bright_direction;
+ pixels.setBrightness(LED_bright_index);
+ uint8_t led_status=dap_bridge_state_st.payloadBridgeState_.Pedal_availability[0]+dap_bridge_state_st.payloadBridgeState_.Pedal_availability[1]*2+dap_bridge_state_st.payloadBridgeState_.Pedal_availability[2]*4;
+ switch (led_status)
+ {
+ case 0:
+ pixels.setPixelColor(0,0xff,0xff,0xff);
+ //pixels.setPixelColor(0,0x52,0x00,0xff);//Orange
+ pixels.show();
+ break;
+ case 1:
+ pixels.setPixelColor(0,0xff,0x00,0x00);//Red
+ pixels.show();
+ break;
+ case 2:
+ pixels.setPixelColor(0,0xff,0x0f,0x00);//Orange
+ pixels.show();
+ break;
+ case 3:
+ pixels.setPixelColor(0,0x52,0x00,0xff);//Cyan
+ pixels.show();
+ break;
+ case 4:
+ pixels.setPixelColor(0,0x5f,0x5f,0x00);//Yellow
+ pixels.show();
+ break;
+ case 5:
+ pixels.setPixelColor(0,0x00,0x00,0xff);//Blue
+ pixels.show();
+ break;
+ case 6:
+ pixels.setPixelColor(0,0x00,0xff,0x00);//Green
+ pixels.show();
+ break;
+ case 7:
+ pixels.setPixelColor(0, 0x80, 0x00, 0x80);//Purple
+ pixels.show();
+ break;
+ default:
+ break;
+ }
+ delay(150);
}
- LED_bright_index=LED_bright_index+LED_bright_direction;
- pixels.setBrightness(LED_bright_index);
- uint8_t led_status=dap_bridge_state_st.payloadBridgeState_.Pedal_availability[0]+dap_bridge_state_st.payloadBridgeState_.Pedal_availability[1]*2+dap_bridge_state_st.payloadBridgeState_.Pedal_availability[2]*4;
- switch (led_status)
+ if(LED_Status==1)//pairing
{
- case 0:
- pixels.setPixelColor(0,0xff,0xff,0xff);
- //pixels.setPixelColor(0,0x52,0x00,0xff);//Orange
- pixels.show();
- break;
- case 1:
- pixels.setPixelColor(0,0xff,0x00,0x00);//Red
- pixels.show();
- break;
- case 2:
- pixels.setPixelColor(0,0xff,0x0f,0x00);//Orange
- pixels.show();
- break;
- case 3:
- pixels.setPixelColor(0,0x52,0x00,0xff);//Cyan
- pixels.show();
- break;
- case 4:
- pixels.setPixelColor(0,0x5f,0x5f,0x00);//Yellow
- pixels.show();
- break;
- case 5:
- pixels.setPixelColor(0,0x00,0x00,0xff);//Blue
- pixels.show();
- break;
- case 6:
- pixels.setPixelColor(0,0x00,0xff,0x00);//Green
- pixels.show();
- break;
- case 7:
- pixels.setPixelColor(0, 0x80, 0x00, 0x80);//Purple
- pixels.show();
- break;
- default:
- break;
+
+ //delay(1000);
+ pixels.setPixelColor(0,0xff,0x00,0x00);//Red
+ pixels.setBrightness(25);
+ pixels.show();
+ delay(500);
+ pixels.setPixelColor(0,0x00,0x00,0x00);//fill no color
+ //pixels.setBrightness(0);
+ pixels.show();
+ delay(500);
}
- delay(150);
+
#endif
+ delay(10);
}
}
diff --git a/SimHubPlugin/DataPluginDemo.cs b/SimHubPlugin/DataPluginDemo.cs
index f8c51e5b..040bdabc 100644
--- a/SimHubPlugin/DataPluginDemo.cs
+++ b/SimHubPlugin/DataPluginDemo.cs
@@ -96,6 +96,7 @@ public struct payloadBridgeState
public byte Pedal_availability_0;
public byte Pedal_availability_1;
public byte Pedal_availability_2;
+ public byte Bridge_action;//0=none, 1=enable pairing
};
public struct payloadPedalConfig
@@ -433,7 +434,18 @@ public byte[] getBytes_Action(DAP_action_st aux)
return myBuffer;
}
+ public byte[] getBytes_Bridge(DAP_bridge_state_st aux)
+ {
+ int length = Marshal.SizeOf(aux);
+ IntPtr ptr = Marshal.AllocHGlobal(length);
+ byte[] myBuffer = new byte[length];
+
+ Marshal.StructureToPtr(aux, ptr, true);
+ Marshal.Copy(ptr, myBuffer, 0, length);
+ Marshal.FreeHGlobal(ptr);
+ return myBuffer;
+ }
unsafe public void DataUpdate(PluginManager pluginManager, ref GameData data)
{
diff --git a/SimHubPlugin/SettingsControlDemo.xaml b/SimHubPlugin/SettingsControlDemo.xaml
index 4c5abd22..2c675f27 100644
--- a/SimHubPlugin/SettingsControlDemo.xaml
+++ b/SimHubPlugin/SettingsControlDemo.xaml
@@ -828,14 +828,14 @@
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
@@ -920,19 +920,19 @@
-
+
-
+
-
-
-
-
-
+
+
+
+
+
@@ -950,15 +950,15 @@
-
+
-
+
-
+
@@ -968,9 +968,10 @@
-
-
-
+
+
+
+
diff --git a/SimHubPlugin/SettingsControlDemo.xaml.cs b/SimHubPlugin/SettingsControlDemo.xaml.cs
index d62cd036..ceef7d8f 100644
--- a/SimHubPlugin/SettingsControlDemo.xaml.cs
+++ b/SimHubPlugin/SettingsControlDemo.xaml.cs
@@ -6733,6 +6733,76 @@ private void Slider_Pedal_interval_trigger_ValueChanged(object sender, RoutedPro
Label_Pedal_interval_trigger.Content = "Action Interval: "+ Plugin.Settings.Pedal_action_interval[indexOfSelectedPedal_u]+"ms";
}
}
+
+ unsafe private void btn_Pairing_Click(object sender, RoutedEventArgs e)
+ {
+ //write to pedal
+ DAP_action_st tmp;
+ tmp.payloadHeader_.version = (byte)Constants.pedalConfigPayload_version;
+ tmp.payloadHeader_.payloadType = (byte)Constants.pedalActionPayload_type;
+ tmp.payloadHeader_.PedalTag = (byte)indexOfSelectedPedal_u;
+ tmp.payloadPedalAction_.system_action_u8 = 4; //1=reset pedal position, 2 =restart esp, 3=enable wifi OTA, 4= pairing
+
+ DAP_action_st* v = &tmp;
+ byte* p = (byte*)v;
+ tmp.payloadFooter_.checkSum = Plugin.checksumCalc(p, sizeof(payloadHeader) + sizeof(payloadPedalAction));
+ int length = sizeof(DAP_action_st);
+ byte[] newBuffer = new byte[length];
+ newBuffer = Plugin.getBytes_Action(tmp);
+ for (uint pedalIDX = 0; pedalIDX < 3; pedalIDX++)
+ {
+ if (Plugin._serialPort[pedalIDX].IsOpen)
+ {
+ try
+ {
+ // clear inbuffer
+ Plugin._serialPort[pedalIDX].DiscardInBuffer();
+
+ // send query command
+ Plugin._serialPort[pedalIDX].Write(newBuffer, 0, newBuffer.Length);
+ }
+ catch (Exception caughtEx)
+ {
+ string errorMessage = caughtEx.Message;
+ TextBox_debugOutput.Text = errorMessage;
+ }
+ }
+ }
+
+ //write to bridge
+ DAP_bridge_state_st tmp_2;
+ tmp_2.payLoadHeader_.version = (byte)Constants.pedalConfigPayload_version;
+ tmp_2.payLoadHeader_.payloadType = (byte)Constants.bridgeStatePayloadType;
+ tmp_2.payLoadHeader_.PedalTag = (byte)indexOfSelectedPedal_u;
+ tmp_2.payloadBridgeState_.Pedal_RSSI = 0;
+ tmp_2.payloadBridgeState_.Pedal_availability_0 = 0;
+ tmp_2.payloadBridgeState_.Pedal_availability_1 = 0;
+ tmp_2.payloadBridgeState_.Pedal_availability_2 = 0;
+ tmp_2.payloadBridgeState_.Bridge_action = 1; //enable pairing
+ DAP_bridge_state_st* v_2 = &tmp_2;
+ byte* p_2 = (byte*)v_2;
+ tmp_2.payloadFooter_.checkSum = Plugin.checksumCalc(p_2, sizeof(payloadHeader) + sizeof(payloadBridgeState));
+ length = sizeof(DAP_bridge_state_st);
+ byte[] newBuffer_2 = new byte[length];
+ newBuffer_2 = Plugin.getBytes_Bridge(tmp_2);
+ if (Plugin.ESPsync_serialPort.IsOpen)
+ {
+ try
+ {
+ // clear inbuffer
+ Plugin.ESPsync_serialPort.DiscardInBuffer();
+ // send query command
+ Plugin.ESPsync_serialPort.Write(newBuffer_2, 0, newBuffer_2.Length);
+ }
+ catch (Exception caughtEx)
+ {
+ string errorMessage = caughtEx.Message;
+ TextBox_debugOutput.Text = errorMessage;
+ }
+ }
+
+
+ }
}
}