forked from tjfenwick/DIY-Sim-Racing-Active-Pedal
-
Notifications
You must be signed in to change notification settings - Fork 23
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
1. Add Rudder checkbox into Advanced area 2. Recommend using linear force curve for rudder 3. Use Rudder function in your own Risk 4. Add ESPNow comunication 5. I2C is a nogo 6. Displacement-calucation for Rudder is in Plan
- Loading branch information
Showing
11 changed files
with
815 additions
and
21 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,95 @@ | ||
#include <WiFi.h> | ||
#include <esp_wifi.h> | ||
#include <Arduino.h> | ||
#include "ESPNowW.h" | ||
//#define ESPNow_debug | ||
uint8_t Clu_mac[] = {0x36, 0x33, 0x33, 0x33, 0x33, 0x32}; | ||
uint8_t Gas_mac[] = {0x36, 0x33, 0x33, 0x33, 0x33, 0x33}; | ||
uint8_t Brk_mac[] = {0x36, 0x33, 0x33, 0x33, 0x33, 0x34}; | ||
uint8_t* Recv_mac; | ||
uint16_t ESPNow_send=0; | ||
uint16_t ESPNow_recieve=0; | ||
//bool MAC_get=false; | ||
bool ESPNOW_status =false; | ||
bool ESPNow_initial_status=false; | ||
bool ESPNow_update= false; | ||
//https://github.com/nickgammon/I2C_Anything/tree/master | ||
struct ESPNow_Send_Struct | ||
{ | ||
uint16_t pedal_position; | ||
float pedal_position_ratio; | ||
}; | ||
ESPNow_Send_Struct _ESPNow_Recv; | ||
ESPNow_Send_Struct _ESPNow_Send; | ||
|
||
void onRecv(const uint8_t *mac_addr, const uint8_t *data, int data_len) | ||
{ | ||
/* | ||
if(ESPNOW_status) | ||
{ | ||
memcpy(&ESPNow_recieve, data, sizeof(ESPNow_recieve)); | ||
ESPNow_update=true; | ||
} | ||
*/ | ||
if(ESPNOW_status) | ||
{ | ||
memcpy(&_ESPNow_Recv, data, sizeof(_ESPNow_Recv)); | ||
ESPNow_update=true; | ||
} | ||
|
||
} | ||
void OnSent(const uint8_t *mac_addr, esp_now_send_status_t status) | ||
{ | ||
|
||
} | ||
void ESPNow_initialize() | ||
{ | ||
|
||
WiFi.mode(WIFI_MODE_STA); | ||
Serial.println("Initializing Rudder, please wait"); | ||
Serial.print("Current MAC Address: "); | ||
Serial.println(WiFi.macAddress()); | ||
if(dap_config_st.payLoadPedalConfig_.pedal_type==0) | ||
{ | ||
esp_wifi_set_mac(WIFI_IF_STA, &Clu_mac[0]); | ||
} | ||
if(dap_config_st.payLoadPedalConfig_.pedal_type==1) | ||
{ | ||
esp_wifi_set_mac(WIFI_IF_STA, &Brk_mac[0]); | ||
} | ||
if(dap_config_st.payLoadPedalConfig_.pedal_type==2) | ||
{ | ||
esp_wifi_set_mac(WIFI_IF_STA, &Gas_mac[0]); | ||
} | ||
delay(300); | ||
Serial.print("Modified MAC Address: "); | ||
Serial.println(WiFi.macAddress()); | ||
ESPNow.init(); | ||
Serial.println("wait 10s for ESPNOW initialized"); | ||
delay(10000); | ||
|
||
if(dap_config_st.payLoadPedalConfig_.pedal_type==1) | ||
{ | ||
Recv_mac=Gas_mac; | ||
} | ||
|
||
if(dap_config_st.payLoadPedalConfig_.pedal_type==2) | ||
{ | ||
Recv_mac=Brk_mac; | ||
} | ||
if(ESPNow.add_peer(Recv_mac)== ESP_OK) | ||
{ | ||
ESPNOW_status=true; | ||
Serial.println("Sucess to add peer"); | ||
} | ||
else | ||
{ | ||
ESPNOW_status=false; | ||
Serial.println("Fail to add peer"); | ||
} | ||
ESPNow.reg_recv_cb(onRecv); | ||
ESPNow.reg_send_cb(OnSent); | ||
ESPNow_initial_status=true; | ||
Serial.println("Rudder Initialized"); | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
#include <Wire.h> | ||
#include <Arduino.h> | ||
#include "Main.h" | ||
|
||
uint16_t I2C_Read; | ||
#define I2C_rate 100000 | ||
#define I2C_debug_out | ||
//TwoWire I2C_sync(0); | ||
bool I2C_sync_status=false; | ||
bool I2C_data_read=false; | ||
uint16_t I2C_send; | ||
uint32_t iii = 0; | ||
|
||
//https://github.com/nickgammon/I2C_Anything/tree/master | ||
template <typename T> unsigned int I2C_writeAnything (const T& value) | ||
{ | ||
Wire.write((byte *) &value, sizeof (value)); | ||
return sizeof (value); | ||
} // end of I2C_writeAnything | ||
|
||
template <typename T> unsigned int I2C_readAnything(T& value) | ||
{ | ||
byte * p = (byte*) &value; | ||
unsigned int i; | ||
for (i = 0; i < sizeof value; i++) | ||
*p++ = Wire.read(); | ||
return i; | ||
} // end of I2C_readAnything | ||
|
||
void SynconReceive(int len) | ||
{ | ||
/* | ||
Serial.printf("onReceive[%d]: ", len); | ||
while (I2C_sync.available()) { | ||
Serial.write(I2C_sync.read()); | ||
} | ||
Serial.println(); | ||
*/ | ||
if(len>0) | ||
{ | ||
I2C_readAnything(I2C_Read); | ||
I2C_data_read=true; | ||
} | ||
|
||
|
||
//Serial.println(); | ||
|
||
} | ||
void SynconRequest() | ||
{ | ||
/* | ||
I2C_sync.print(iii++); | ||
I2C_sync.print(" Packets."); | ||
Serial.println("onRequest"); | ||
Serial.println(); | ||
*/ | ||
I2C_writeAnything(I2C_send); | ||
//Wire.write(I2C_send); | ||
} | ||
|
||
void I2C_initialize() | ||
{ | ||
Wire.begin(I2C_SDA,I2C_SCL,I2C_rate); | ||
delay(3000); | ||
Serial.println("Sync as Master"); | ||
} | ||
|
||
void I2C_initialize_slave() | ||
{ | ||
Wire.onReceive(SynconReceive); | ||
Wire.onRequest(SynconRequest); | ||
Wire.begin((uint8_t)I2C_slave_address,I2C_SDA,I2C_SCL,I2C_rate); | ||
//I2C_sync.begin(I2C_SDA,I2C_SCL,(uint8_t)I2C_slave_address); | ||
Serial.println("Sync as Slave"); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.