|
|
@ -74,28 +74,26 @@ uint8_t esc2 = 127; |
|
|
|
|
|
|
|
byte hallCenterMargin = 5; |
|
|
|
|
|
|
|
const float minVoltage = 2.9; // These values are heavily strange since the devider is not working nicely yet...
|
|
|
|
const float maxVoltage = 3.6; |
|
|
|
const float minVoltage = 3.4; |
|
|
|
const float maxVoltage = 4.2; |
|
|
|
const float refVoltage = 3.3; |
|
|
|
// Resistors in Ohms
|
|
|
|
const float deviderR1 = 1500; |
|
|
|
const float deviderR2 = 22000; |
|
|
|
const float deviderR1 = 22000; |
|
|
|
const float deviderR2 = 11200; |
|
|
|
|
|
|
|
// Global copy of board
|
|
|
|
esp_now_peer_info_t board; |
|
|
|
#define CHANNEL 1
|
|
|
|
#define PRINTSCANRESULTS 0
|
|
|
|
#define DELETEBEFOREPAIR 0
|
|
|
|
#define HAL_MIN 1390
|
|
|
|
#define HAL_MAX 2230
|
|
|
|
#define HAL_CENTER 1880
|
|
|
|
#define TRIM_LOW 180
|
|
|
|
#define TRIM_HIGH 0
|
|
|
|
#define HAL_MIN 1390 // defaults
|
|
|
|
#define HAL_MAX 2230 // defaults
|
|
|
|
#define HAL_CENTER 1880 // defaults
|
|
|
|
|
|
|
|
//#define pairingMode
|
|
|
|
#define leverPin 36
|
|
|
|
#define triggerPin 17
|
|
|
|
#define batteryMeasurePin 38
|
|
|
|
#define batteryMeasurePin 39
|
|
|
|
|
|
|
|
bool triggerActive(); |
|
|
|
|
|
|
@ -113,6 +111,16 @@ void setCrusing(uint8_t speed) { |
|
|
|
} |
|
|
|
// ESPNOW functions ##############################
|
|
|
|
// Scan for boards in AP mode
|
|
|
|
// config AP
|
|
|
|
void configDeviceAP(bool hidden) { |
|
|
|
bool result = WiFi.softAP("ESK8", "ESK8_Password+vD8z2YAvoDBW?Zx", CHANNEL, hidden); |
|
|
|
if (!result) { |
|
|
|
Serial.println("AP Config failed."); |
|
|
|
} else { |
|
|
|
Serial.println("AP Config Success. Broadcasting with AP: " + String("ESK8")); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
#ifdef pairingMode
|
|
|
|
void ScanForBoard() { |
|
|
@ -158,6 +166,7 @@ void ScanForBoard() { |
|
|
|
|
|
|
|
board.channel = CHANNEL; // pick a channel
|
|
|
|
board.encrypt = 0; // no encryption
|
|
|
|
board.ifidx = ESP_IF_WIFI_STA; |
|
|
|
|
|
|
|
boardFound = 1; |
|
|
|
// we are planning to have only one board in this example;
|
|
|
@ -180,6 +189,7 @@ void ScanForBoard() { |
|
|
|
|
|
|
|
void deletePeer() { |
|
|
|
const esp_now_peer_info_t *peer = &board; |
|
|
|
|
|
|
|
const uint8_t *peer_addr = board.peer_addr; |
|
|
|
esp_err_t delStatus = esp_now_del_peer(peer_addr); |
|
|
|
DEBUG_PRINT("board Delete Status: "); |
|
|
@ -272,8 +282,11 @@ void sendData() { |
|
|
|
DEBUG_PRINTLN("ESP_ERR_ESPNOW_NO_MEM"); |
|
|
|
} else if (result == ESP_ERR_ESPNOW_NOT_FOUND) { |
|
|
|
DEBUG_PRINTLN("Peer not found."); |
|
|
|
} else if (result == ESP_ERR_ESPNOW_IF) { |
|
|
|
DEBUG_PRINTLN("Interface error."); |
|
|
|
} else { |
|
|
|
DEBUG_PRINTLN("Not sure what happened"); |
|
|
|
DEBUG_PRINT("Not sure what happened "); |
|
|
|
DEBUG_PRINTLN(result); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
@ -340,10 +353,10 @@ void calculateThrottlePosition() { |
|
|
|
int maxSpeed = 255; |
|
|
|
if(settings[limitMode] == 1) maxSpeed = 180; |
|
|
|
|
|
|
|
if (hallMeasurement >= HAL_CENTER) { |
|
|
|
throttle = c_map(hallMeasurement, HAL_CENTER, HAL_MAX, 127, maxSpeed); |
|
|
|
if (hallMeasurement >= settings[centerHallValue]) { |
|
|
|
throttle = c_map(hallMeasurement, settings[centerHallValue], settings[maxHallValue], 127, maxSpeed); |
|
|
|
} else { |
|
|
|
throttle = c_map(hallMeasurement, HAL_MIN, HAL_CENTER, 0, 127); |
|
|
|
throttle = c_map(hallMeasurement, settings[minHallValue], settings[centerHallValue], 0, 127); |
|
|
|
} |
|
|
|
// removeing center noise
|
|
|
|
if (abs(throttle - 127) < hallCenterMargin) { |
|
|
@ -647,25 +660,29 @@ void drawPage() { |
|
|
|
} |
|
|
|
|
|
|
|
void controlSelect() { |
|
|
|
if (hallMeasurement >= (HAL_MAX - 250) && settingsLoopFlag == false) { //settings[maxHallValue]
|
|
|
|
if (hallMeasurement >= (settings[maxHallValue] - 250) && settingsLoopFlag == false) { //settings[maxHallValue]
|
|
|
|
// Up
|
|
|
|
if (selectedIndex != 0) { |
|
|
|
selectedIndex--; |
|
|
|
settingsLoopFlag = true; |
|
|
|
} |
|
|
|
} else if (hallMeasurement <= (HAL_MIN + 250) && settingsLoopFlag == false) { //settings[minHallValue]
|
|
|
|
} else if (hallMeasurement <= (settings[minHallValue] + 250) && settingsLoopFlag == false) { |
|
|
|
// Down
|
|
|
|
if (selectedIndex < 4) { |
|
|
|
selectedIndex++; |
|
|
|
settingsLoopFlag = true; |
|
|
|
} |
|
|
|
} else if (inRange(hallMeasurement, HAL_CENTER - 50, HAL_CENTER + 50)) { // settings[centerHallValue]
|
|
|
|
} else if (inRange(hallMeasurement, settings[centerHallValue] - 50, settings[centerHallValue] + 50)) { // settings[centerHallValue]
|
|
|
|
settingsLoopFlag = false; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
String selectionItems[5] = { |
|
|
|
"Se","Li","B","St","Cr" |
|
|
|
String selectionTitles[5] = { |
|
|
|
"Settings","Limit","Light","Steering","Cruise" |
|
|
|
}; |
|
|
|
|
|
|
|
uint16_t selectionGlyphs[5] = { |
|
|
|
0x0081, 0x008d, 0x0103, 0x00f6, 0x0088 |
|
|
|
}; |
|
|
|
|
|
|
|
void drawSelectionMenu() { |
|
|
@ -676,21 +693,25 @@ void drawSelectionMenu() { |
|
|
|
u8g2.setFontMode(0); |
|
|
|
u8g2.setDrawColor(1); |
|
|
|
|
|
|
|
String title = "Select Action"; |
|
|
|
title.toCharArray(displayBuffer, 20); |
|
|
|
u8g2.setFont(u8g2_font_helvR10_tr ); |
|
|
|
u8g2.drawStr(20, 12, displayBuffer); |
|
|
|
|
|
|
|
for(int i = 0; i < 5; i++) { |
|
|
|
if(selectedIndex == i) { |
|
|
|
String title = selectionTitles[i]; |
|
|
|
title.toCharArray(displayBuffer, 20); |
|
|
|
u8g2.setFont(u8g2_font_helvR10_tr ); |
|
|
|
u8g2.drawStr(30, 12, displayBuffer); |
|
|
|
|
|
|
|
u8g2.setFontMode(0); |
|
|
|
u8g2.drawBox(xStart-2 + xSpace * i, y-12, 15, 15); |
|
|
|
//u8g2.drawBox(xStart-2 + xSpace * i, y-12, 15, 15);
|
|
|
|
u8g2.drawBox(xStart + xSpace * i, y-12, 15, 15); |
|
|
|
u8g2.setDrawColor(0); |
|
|
|
} |
|
|
|
|
|
|
|
selectionItems[i].toCharArray(displayBuffer, 10); |
|
|
|
u8g2.setFont(u8g2_font_profont12_tr); |
|
|
|
u8g2.drawStr(xStart + xSpace * i, y, displayBuffer); |
|
|
|
//selectionItems[i].toCharArray(displayBuffer, 10);
|
|
|
|
//u8g2.setFont(u8g2_font_profont12_tr);
|
|
|
|
//u8g2.drawStr(xStart + xSpace * i, y, displayBuffer);
|
|
|
|
|
|
|
|
u8g2.setFont(u8g2_font_open_iconic_all_2x_t); |
|
|
|
u8g2.drawGlyph(xStart + xSpace * i, y, selectionGlyphs[i]); |
|
|
|
|
|
|
|
u8g2.setFontMode(0); |
|
|
|
u8g2.setDrawColor(1); |
|
|
@ -776,7 +797,11 @@ void drawStartScreen() { |
|
|
|
void setup() { |
|
|
|
Serial.begin(115200); |
|
|
|
//Set device in STA mode to begin with
|
|
|
|
WiFi.mode(WIFI_STA); |
|
|
|
//WiFi.mode(WIFI_STA);
|
|
|
|
//Set device in AP mode to begin with
|
|
|
|
WiFi.mode(WIFI_AP_STA); |
|
|
|
// configure device AP mode
|
|
|
|
configDeviceAP(true); |
|
|
|
DEBUG_PRINTLN("ESPNowSkate"); |
|
|
|
|
|
|
|
loadSettings(); |
|
|
@ -787,8 +812,6 @@ void setup() { |
|
|
|
delay(50); |
|
|
|
digitalWrite(16, HIGH); |
|
|
|
|
|
|
|
analogSetPinAttenuation(batteryMeasurePin, ADC_6db); |
|
|
|
|
|
|
|
// setup other pins
|
|
|
|
pinMode(triggerPin, INPUT_PULLUP); |
|
|
|
|
|
|
@ -813,8 +836,8 @@ void setup() { |
|
|
|
} |
|
|
|
|
|
|
|
// This is the mac address of the Master in Station Mode
|
|
|
|
DEBUG_PRINT("STA MAC: "); DEBUG_PRINTLN(WiFi.macAddress()); |
|
|
|
|
|
|
|
DEBUG_PRINT("STA MAC: "); DEBUG_PRINTLN(WiFi.macAddress()); |
|
|
|
if (esp_now_init() == ESP_OK) { |
|
|
|
DEBUG_PRINTLN("ESPNow Init Success"); |
|
|
|
} |
|
|
@ -839,18 +862,27 @@ void setup() { |
|
|
|
} |
|
|
|
board.channel = CHANNEL; // pick a channel
|
|
|
|
board.encrypt = 0; // no encryption
|
|
|
|
//board.ifidx = ESP_IF_WIFI_STA;
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
void loop() { |
|
|
|
updateMainDisplay(); |
|
|
|
|
|
|
|
if(currentMode == M_STEERING) readAccel(); |
|
|
|
//if(currentMode == M_STEERING) readAccel();
|
|
|
|
readAccel(); |
|
|
|
DEBUG_PRINT("Accel Value Left Right (Y): "); |
|
|
|
DEBUG_PRINT(map(AcY, -15000, 15000, -100, 100)); |
|
|
|
//Serial.print("Help(Y): ");
|
|
|
|
//Serial.println(map(GyY, -15000, 15000, -100, 100));
|
|
|
|
|
|
|
|
Serial.print("Accel Value Left Right( Y): "); |
|
|
|
Serial.print(map(AcY, -15000, 15000, -100, 100)); |
|
|
|
Serial.print("Help(Y): "); |
|
|
|
Serial.println(map(GyY, -15000, 15000, -100, 100)); |
|
|
|
DEBUG_PRINT(" (X): "); |
|
|
|
DEBUG_PRINT(map(AcX, -15000, 15000, -100, 100)); |
|
|
|
|
|
|
|
DEBUG_PRINT(" (Z): "); |
|
|
|
DEBUG_PRINTLN(map(AcZ, -15000, 15000, -100, 100)); |
|
|
|
|
|
|
|
// left rigt : Z forward Back : Y
|
|
|
|
calculateThrottlePosition(); |
|
|
|
|
|
|
|
if (currentMode == M_SELECT) { |
|
|
@ -865,7 +897,7 @@ void loop() { |
|
|
|
if (triggerActive()) { |
|
|
|
if(currentMode == M_STEERING) { |
|
|
|
DEBUG_PRINT("Value: "); |
|
|
|
int map = c_map(AcX, 15000, -15000, -60, 60); |
|
|
|
int map = c_map(AcZ, -15000, 15000, -60, 60); |
|
|
|
DEBUG_PRINTLN(map); |
|
|
|
|
|
|
|
#ifdef steeringInfluential
|
|
|
@ -878,6 +910,12 @@ void loop() { |
|
|
|
esc1 = throttle; |
|
|
|
esc2 = throttle; |
|
|
|
} |
|
|
|
|
|
|
|
// ignore reverse
|
|
|
|
if(throttle < 127) { |
|
|
|
esc1 = throttle; |
|
|
|
esc2 = throttle; |
|
|
|
} |
|
|
|
#endif
|
|
|
|
if(throttle == 127) { |
|
|
|
esc1 = 127; |
|
|
|