- Cool Paging for Telemetry
- Added basic led library - updated readme - implemented fanoverride and lightActive transmission
This commit is contained in:
parent
0c3d258bd0
commit
d6027e093b
@ -33,3 +33,4 @@ monitor_baud = 115200
|
|||||||
lib_deps =
|
lib_deps =
|
||||||
ServoESP32
|
ServoESP32
|
||||||
DallasTemperature
|
DallasTemperature
|
||||||
|
FastLED
|
||||||
|
35
readme.md
35
readme.md
@ -1 +1,34 @@
|
|||||||
This is my take on a eskate remote
|
This is my take on an *eskate remote*
|
||||||
|
|
||||||
|
it uses:
|
||||||
|
|
||||||
|
* ESPNow on 2 ESP32
|
||||||
|
* Hal sensor based remote
|
||||||
|
* 3D model by SolidGeek
|
||||||
|
|
||||||
|
it features:
|
||||||
|
|
||||||
|
* Basic Skateboard control
|
||||||
|
* FANCY Displays
|
||||||
|
* Encryption (Not yet)
|
||||||
|
* Lights !
|
||||||
|
* Cruise Mode
|
||||||
|
* Experimental SteeringMode (for walking your board like a dog)
|
||||||
|
* Limit Mode
|
||||||
|
* Telemetry: Voltage, Electronics Temperature, Speed (with cool paging)
|
||||||
|
* Basic ESC Fan control (relay based...)
|
||||||
|
|
||||||
|
# TODO:
|
||||||
|
|
||||||
|
### Software:
|
||||||
|
|
||||||
|
implement ws2812
|
||||||
|
add graphics to quick selection
|
||||||
|
implement display on reciever
|
||||||
|
rpm direction and calibration
|
||||||
|
enable ecryption for espnow
|
||||||
|
Improve steeringmode using rpm knowledge
|
||||||
|
|
||||||
|
### Hardware:
|
||||||
|
improve voltage resistors
|
||||||
|
improve fans to be PWM controlled
|
23
src/lights.h
Normal file
23
src/lights.h
Normal file
@ -0,0 +1,23 @@
|
|||||||
|
#include "FastLED.h"
|
||||||
|
|
||||||
|
#define NUM_STRIPS 2
|
||||||
|
#define NUM_LEDS_PER_STRIP 10
|
||||||
|
CRGB leds[NUM_STRIPS][NUM_LEDS_PER_STRIP];
|
||||||
|
#define PIN_STRIP1 34
|
||||||
|
|
||||||
|
void setupLights() {
|
||||||
|
FastLED.addLeds<NEOPIXEL, PIN_STRIP1>(leds[0], NUM_LEDS_PER_STRIP);
|
||||||
|
}
|
||||||
|
|
||||||
|
void loopLights() {
|
||||||
|
// This outer loop will go over each strip, one at a time
|
||||||
|
for(int x = 0; x < NUM_STRIPS; x++) {
|
||||||
|
// This inner loop will go over each led in the current strip, one at a time
|
||||||
|
for(int i = 0; i < NUM_LEDS_PER_STRIP; i++) {
|
||||||
|
leds[x][i] = CRGB::Red;
|
||||||
|
FastLED.show();
|
||||||
|
leds[x][i] = CRGB::Black;
|
||||||
|
delay(100);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -54,6 +54,22 @@ long lastPacket = 0;
|
|||||||
|
|
||||||
bool isConnected = false;
|
bool isConnected = false;
|
||||||
|
|
||||||
|
#define FANS_AUTO 0
|
||||||
|
#define FANS_ON 1
|
||||||
|
#define FANS_OFF 2
|
||||||
|
|
||||||
|
bool lightActive = false;
|
||||||
|
int fanMode = FANS_AUTO;
|
||||||
|
|
||||||
|
#include "lights.h"
|
||||||
|
|
||||||
|
void setBoardOptions(uint8_t options) {
|
||||||
|
Serial.print("opt: ");
|
||||||
|
Serial.println(options, BIN);
|
||||||
|
lightActive = options & 1;
|
||||||
|
fanMode = (options >> 2) & 3;
|
||||||
|
}
|
||||||
|
|
||||||
// ESPNOW Functions ############################
|
// ESPNOW Functions ############################
|
||||||
// config AP
|
// config AP
|
||||||
void configDeviceAP(bool hidden) {
|
void configDeviceAP(bool hidden) {
|
||||||
@ -76,7 +92,7 @@ void OnDataRecv(const uint8_t *mac_addr, const uint8_t *data, int data_len) {
|
|||||||
snprintf(macStr, sizeof(macStr), "%02x:%02x:%02x:%02x:%02x:%02x",
|
snprintf(macStr, sizeof(macStr), "%02x:%02x:%02x:%02x:%02x:%02x",
|
||||||
mac_addr[0], mac_addr[1], mac_addr[2], mac_addr[3], mac_addr[4], mac_addr[5]);
|
mac_addr[0], mac_addr[1], mac_addr[2], mac_addr[3], mac_addr[4], mac_addr[5]);
|
||||||
Serial.print("Last Packet Recv from: "); Serial.println(macStr);
|
Serial.print("Last Packet Recv from: "); Serial.println(macStr);
|
||||||
uint8_t recData[2];
|
uint8_t recData[3];
|
||||||
memcpy(recData, data, data_len);
|
memcpy(recData, data, data_len);
|
||||||
Serial.print("Last Packet Recv Data: "); Serial.println(recData[0]); Serial.print(" "); Serial.print(recData[1]); Serial.print(" len:"); Serial.println(data_len);
|
Serial.print("Last Packet Recv Data: "); Serial.println(recData[0]); Serial.print(" "); Serial.print(recData[1]); Serial.print(" len:"); Serial.println(data_len);
|
||||||
|
|
||||||
@ -110,6 +126,7 @@ void OnDataRecv(const uint8_t *mac_addr, const uint8_t *data, int data_len) {
|
|||||||
isConnected = true;
|
isConnected = true;
|
||||||
// Could check mac here for some security
|
// Could check mac here for some security
|
||||||
writeServos(recData[0], recData[1]);
|
writeServos(recData[0], recData[1]);
|
||||||
|
setBoardOptions(recData[2]);
|
||||||
|
|
||||||
display.clear();
|
display.clear();
|
||||||
char buf[25];
|
char buf[25];
|
||||||
@ -196,8 +213,19 @@ void checkTemperature() {
|
|||||||
temperature = sensors.getTempCByIndex(0);
|
temperature = sensors.getTempCByIndex(0);
|
||||||
//Serial.print("Temp: ");
|
//Serial.print("Temp: ");
|
||||||
//Serial.println(temperature);
|
//Serial.println(temperature);
|
||||||
if(temperature < 35) digitalWrite(fanRelais, LOW);
|
switch(fanMode) {
|
||||||
if(temperature > 40) digitalWrite(fanRelais, HIGH);
|
case FANS_AUTO:
|
||||||
|
if(temperature < 35) digitalWrite(fanRelais, LOW);
|
||||||
|
if(temperature > 40) digitalWrite(fanRelais, HIGH);
|
||||||
|
break;
|
||||||
|
case FANS_ON:
|
||||||
|
digitalWrite(fanRelais, HIGH);
|
||||||
|
break;
|
||||||
|
case FANS_OFF:
|
||||||
|
digitalWrite(fanRelais, LOW);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
sendTemperature = abs(floor(temperature));
|
sendTemperature = abs(floor(temperature));
|
||||||
sendTemperatureDecimals = (temperature - sendTemperature) * 100;
|
sendTemperatureDecimals = (temperature - sendTemperature) * 100;
|
||||||
}
|
}
|
||||||
|
@ -252,9 +252,7 @@ bool manageBoard() {
|
|||||||
|
|
||||||
// send data
|
// send data
|
||||||
void sendData() {
|
void sendData() {
|
||||||
const uint8_t data[] = { esc1, esc2 };
|
const uint8_t data[] = { esc1, esc2, boardOptions };
|
||||||
//const uint8_t data[] = { esc1, esc2, options};
|
|
||||||
|
|
||||||
|
|
||||||
const uint8_t *peer_addr = board.peer_addr;
|
const uint8_t *peer_addr = board.peer_addr;
|
||||||
DEBUG_PRINT("Sending: "); DEBUG_PRINTLN(esc1);
|
DEBUG_PRINT("Sending: "); DEBUG_PRINTLN(esc1);
|
||||||
@ -404,11 +402,34 @@ void checkClicks(void * parameter) {
|
|||||||
//DEBUG_PRINT("Trig: "); DEBUG_PRINT(triggerActive()); DEBUG_PRINT(" LAST: "); DEBUG_PRINTLN(lastTriggerState);
|
//DEBUG_PRINT("Trig: "); DEBUG_PRINT(triggerActive()); DEBUG_PRINT(" LAST: "); DEBUG_PRINTLN(lastTriggerState);
|
||||||
if(millis()-lastClick > clickDiff && clickCounter!=0) {
|
if(millis()-lastClick > clickDiff && clickCounter!=0) {
|
||||||
DEBUG_PRINTLN("reset");
|
DEBUG_PRINTLN("reset");
|
||||||
|
//timeout, check amount
|
||||||
|
if(clickCounter == 2) {
|
||||||
|
// cycle page if active
|
||||||
|
DEBUG_PRINTLN("Double, rotate page");
|
||||||
|
if(settings[pageDisplay] != 0) {
|
||||||
|
displayData++;
|
||||||
|
if (displayData > 2) {
|
||||||
|
displayData = 0;
|
||||||
|
}
|
||||||
|
// write and save
|
||||||
|
settings[pageDisplay] = displayData + 1;
|
||||||
|
shouldUpdateSettings = true;
|
||||||
|
}
|
||||||
|
} else if(clickCounter == 3) {
|
||||||
|
DEBUG_PRINTLN("YEAH TRIPPLE");
|
||||||
|
|
||||||
|
if(currentMode == M_NORMAL) {
|
||||||
|
currentMode = M_SELECT;
|
||||||
|
selectedIndex = 2;
|
||||||
|
} else {
|
||||||
|
currentMode = M_NORMAL;
|
||||||
|
}
|
||||||
|
}
|
||||||
clickCounter = 0;
|
clickCounter = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(!triggerActive() && lastTriggerState) {
|
if(!triggerActive() && lastTriggerState) {
|
||||||
DEBUG_PRINTLN("CLICK##################### ");
|
DEBUG_PRINTLN("CLICK ##################### ");
|
||||||
int timeSinceLastClick = millis()-lastClick;
|
int timeSinceLastClick = millis()-lastClick;
|
||||||
lastClick = millis();
|
lastClick = millis();
|
||||||
|
|
||||||
@ -425,6 +446,7 @@ void checkClicks(void * parameter) {
|
|||||||
break;
|
break;
|
||||||
case 2:
|
case 2:
|
||||||
lightActive = !lightActive;
|
lightActive = !lightActive;
|
||||||
|
updateBoardOptions();
|
||||||
currentMode = M_NORMAL;
|
currentMode = M_NORMAL;
|
||||||
break;
|
break;
|
||||||
case 3:
|
case 3:
|
||||||
@ -436,19 +458,10 @@ void checkClicks(void * parameter) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if(timeSinceLastClick < clickDiff) clickCounter++;
|
if(timeSinceLastClick < clickDiff) {
|
||||||
else clickCounter = 1;
|
clickCounter++;
|
||||||
if(clickCounter == 3) {
|
} else {
|
||||||
DEBUG_PRINTLN("YEAH TRIPPLE");
|
clickCounter = 1;
|
||||||
|
|
||||||
if(currentMode == M_NORMAL) {
|
|
||||||
currentMode = M_SELECT;
|
|
||||||
selectedIndex = 2;
|
|
||||||
} else {
|
|
||||||
currentMode = M_NORMAL;
|
|
||||||
}
|
|
||||||
|
|
||||||
vTaskDelay(pdMS_TO_TICKS(2000));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
lastClick = millis();
|
lastClick = millis();
|
||||||
@ -459,7 +472,6 @@ void checkClicks(void * parameter) {
|
|||||||
vTaskDelay(pdMS_TO_TICKS(20));
|
vTaskDelay(pdMS_TO_TICKS(20));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
//############ End Hardware Helpers
|
//############ End Hardware Helpers
|
||||||
|
|
||||||
//############ Drawing Functions
|
//############ Drawing Functions
|
||||||
@ -553,14 +565,18 @@ void drawPage() {
|
|||||||
int y = 16;
|
int y = 16;
|
||||||
|
|
||||||
// Rotate the realtime data each 4s.
|
// Rotate the realtime data each 4s.
|
||||||
if ((millis() - lastDataRotation) >= 4000) {
|
if(settings[pageDisplay] == 0) {
|
||||||
|
if ((millis() - lastDataRotation) >= 4000) {
|
||||||
|
|
||||||
lastDataRotation = millis();
|
lastDataRotation = millis();
|
||||||
displayData++;
|
displayData++;
|
||||||
|
|
||||||
if (displayData > 2) {
|
if (displayData > 2) {
|
||||||
displayData = 0;
|
displayData = 0;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
displayData = settings[pageDisplay] - 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
switch (displayData) {
|
switch (displayData) {
|
||||||
|
@ -9,7 +9,6 @@
|
|||||||
#define wheelCircumference 26.062
|
#define wheelCircumference 26.062
|
||||||
|
|
||||||
TaskHandle_t rpmTaskHandle;
|
TaskHandle_t rpmTaskHandle;
|
||||||
|
|
||||||
int rpmRight = 0;
|
int rpmRight = 0;
|
||||||
int rpmLeft = 0;
|
int rpmLeft = 0;
|
||||||
|
|
||||||
|
@ -1,18 +1,23 @@
|
|||||||
uint8_t currentSetting = 0;
|
uint8_t currentSetting = 0;
|
||||||
#define SETTINGS_COUNT 7
|
#define SETTINGS_COUNT 7
|
||||||
|
|
||||||
#define limitMode 0
|
#define pageDisplay 0
|
||||||
#define fanOveride 1
|
#define limitMode 1
|
||||||
#define wheelDiameter 2 // Speed factor
|
#define fanOveride 2
|
||||||
#define minHallValue 3
|
#define wheelDiameter 3 // Speed factor
|
||||||
#define centerHallValue 4
|
#define minHallValue 4
|
||||||
#define maxHallValue 5
|
#define centerHallValue 5
|
||||||
|
#define maxHallValue 6
|
||||||
|
|
||||||
int settings[SETTINGS_COUNT];
|
int settings[SETTINGS_COUNT];
|
||||||
|
|
||||||
float gearRatio;
|
uint8_t boardOptions = 0b00000000;
|
||||||
float ratioRpmSpeed;
|
// Map:(Light, Fan) XXXXFFLL
|
||||||
float ratioPulseDistance;
|
/*
|
||||||
|
float gearRatio;
|
||||||
|
float ratioRpmSpeed;
|
||||||
|
float ratioPulseDistance;
|
||||||
|
*/
|
||||||
|
|
||||||
// Defining variables for Settings menu
|
// Defining variables for Settings menu
|
||||||
bool changeSelectedSetting = false;
|
bool changeSelectedSetting = false;
|
||||||
@ -22,9 +27,9 @@ bool settingsChangeFlag = false;
|
|||||||
bool settingsChangeValueFlag = false;
|
bool settingsChangeValueFlag = false;
|
||||||
|
|
||||||
const char *settingPages[SETTINGS_COUNT] = {
|
const char *settingPages[SETTINGS_COUNT] = {
|
||||||
|
"Page Display",
|
||||||
"LimitMode",
|
"LimitMode",
|
||||||
"FanOveride",
|
"FanOveride",
|
||||||
"TriggerMode",
|
|
||||||
"Wheel diameter",
|
"Wheel diameter",
|
||||||
"Throttle Min",
|
"Throttle Min",
|
||||||
"Throttle Center",
|
"Throttle Center",
|
||||||
@ -33,9 +38,9 @@ const char *settingPages[SETTINGS_COUNT] = {
|
|||||||
|
|
||||||
// Setting rules format: default, min, max.
|
// Setting rules format: default, min, max.
|
||||||
int settingRules[SETTINGS_COUNT][3] {
|
int settingRules[SETTINGS_COUNT][3] {
|
||||||
{0, 0, 1}, // default is no limit
|
{0, 0, 3}, //page: 0 cycle, 1 speed, 2 volt, 3 temp
|
||||||
{0, 0, 2}, // 0 no, 1 on, 2 off
|
{0, 0, 1}, //limit default is no limit
|
||||||
{0, 0, 3}, // 0 Killswitch, 1 cruise & 2 data toggle
|
{0, 0, 2}, //fan 0 no, 1 on, 2 off
|
||||||
{83, 0, 250}, // wheel mm
|
{83, 0, 250}, // wheel mm
|
||||||
{HAL_MIN, 1000, 2000},
|
{HAL_MIN, 1000, 2000},
|
||||||
{HAL_CENTER, 1000, 2000},
|
{HAL_CENTER, 1000, 2000},
|
||||||
@ -51,22 +56,33 @@ int settingRules[SETTINGS_COUNT][3] {
|
|||||||
//"Throttle Max"
|
//"Throttle Max"
|
||||||
};
|
};
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
|
||||||
// Check if an integer is within a min and max value
|
// Check if an integer is within a min and max value
|
||||||
bool inRange(int val, int minimum, int maximum) {
|
bool inRange(int val, int minimum, int maximum) {
|
||||||
return ((minimum <= val) && (val <= maximum));
|
return ((minimum <= val) && (val <= maximum));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void updateBoardOptions() {
|
||||||
|
boardOptions = 0;
|
||||||
|
boardOptions |= (uint8_t) settings[fanOveride] << 2;
|
||||||
|
boardOptions |= boardOptions | (uint8_t) lightActive;
|
||||||
|
Serial.print("board: "); Serial.println(boardOptions);
|
||||||
|
}
|
||||||
|
|
||||||
void updateSettings() {
|
void updateSettings() {
|
||||||
preferences.begin("remote-set", false);
|
preferences.begin("remote-set", false);
|
||||||
for (int i = 0; i < SETTINGS_COUNT; i++) {
|
for (int i = 0; i < SETTINGS_COUNT; i++) {
|
||||||
preferences.putInt(settingPages[i], settings[i]);
|
preferences.putInt(settingPages[i], settings[i]);
|
||||||
}
|
}
|
||||||
|
|
||||||
preferences.end();
|
preferences.end();
|
||||||
DEBUG_PRINTLN("UPDATED");
|
DEBUG_PRINTLN("UPDATED");
|
||||||
preferences.begin("remote-set", false);
|
preferences.begin("remote-set", false);
|
||||||
DEBUG_PRINTLN(preferences.getInt(settingPages[0], 0));
|
DEBUG_PRINTLN(preferences.getInt(settingPages[0], 0));
|
||||||
preferences.end();
|
preferences.end();
|
||||||
//calculateRatios();
|
//calculateRatios();
|
||||||
|
updateBoardOptions();
|
||||||
}
|
}
|
||||||
|
|
||||||
void setDefaultSettings() {
|
void setDefaultSettings() {
|
||||||
@ -84,9 +100,7 @@ void loadSettings() {
|
|||||||
}
|
}
|
||||||
preferences.end();
|
preferences.end();
|
||||||
|
|
||||||
|
|
||||||
bool rewriteSettings = false;
|
bool rewriteSettings = false;
|
||||||
|
|
||||||
// Loop through all settings to check if everything is fine
|
// Loop through all settings to check if everything is fine
|
||||||
for (int i = 0; i < SETTINGS_COUNT; i++) {
|
for (int i = 0; i < SETTINGS_COUNT; i++) {
|
||||||
int val = settings[i];
|
int val = settings[i];
|
||||||
@ -97,12 +111,12 @@ void loadSettings() {
|
|||||||
settings[i] = settingRules[i][0];
|
settings[i] = settingRules[i][0];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (rewriteSettings == true) {
|
if (rewriteSettings == true) {
|
||||||
updateSettings();
|
updateSettings();
|
||||||
} else {
|
} else {
|
||||||
// Calculate constants
|
// Calculate constants
|
||||||
//calculateRatios();
|
//calculateRatios();
|
||||||
|
updateBoardOptions();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user