- 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 =
|
||||
ServoESP32
|
||||
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;
|
||||
|
||||
#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 ############################
|
||||
// config AP
|
||||
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",
|
||||
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);
|
||||
uint8_t recData[2];
|
||||
uint8_t recData[3];
|
||||
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);
|
||||
|
||||
@ -110,6 +126,7 @@ void OnDataRecv(const uint8_t *mac_addr, const uint8_t *data, int data_len) {
|
||||
isConnected = true;
|
||||
// Could check mac here for some security
|
||||
writeServos(recData[0], recData[1]);
|
||||
setBoardOptions(recData[2]);
|
||||
|
||||
display.clear();
|
||||
char buf[25];
|
||||
@ -196,8 +213,19 @@ void checkTemperature() {
|
||||
temperature = sensors.getTempCByIndex(0);
|
||||
//Serial.print("Temp: ");
|
||||
//Serial.println(temperature);
|
||||
switch(fanMode) {
|
||||
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));
|
||||
sendTemperatureDecimals = (temperature - sendTemperature) * 100;
|
||||
}
|
||||
|
@ -252,9 +252,7 @@ bool manageBoard() {
|
||||
|
||||
// send data
|
||||
void sendData() {
|
||||
const uint8_t data[] = { esc1, esc2 };
|
||||
//const uint8_t data[] = { esc1, esc2, options};
|
||||
|
||||
const uint8_t data[] = { esc1, esc2, boardOptions };
|
||||
|
||||
const uint8_t *peer_addr = board.peer_addr;
|
||||
DEBUG_PRINT("Sending: "); DEBUG_PRINTLN(esc1);
|
||||
@ -404,6 +402,29 @@ void checkClicks(void * parameter) {
|
||||
//DEBUG_PRINT("Trig: "); DEBUG_PRINT(triggerActive()); DEBUG_PRINT(" LAST: "); DEBUG_PRINTLN(lastTriggerState);
|
||||
if(millis()-lastClick > clickDiff && clickCounter!=0) {
|
||||
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;
|
||||
}
|
||||
|
||||
@ -425,6 +446,7 @@ void checkClicks(void * parameter) {
|
||||
break;
|
||||
case 2:
|
||||
lightActive = !lightActive;
|
||||
updateBoardOptions();
|
||||
currentMode = M_NORMAL;
|
||||
break;
|
||||
case 3:
|
||||
@ -436,19 +458,10 @@ void checkClicks(void * parameter) {
|
||||
}
|
||||
}
|
||||
|
||||
if(timeSinceLastClick < clickDiff) clickCounter++;
|
||||
else clickCounter = 1;
|
||||
if(clickCounter == 3) {
|
||||
DEBUG_PRINTLN("YEAH TRIPPLE");
|
||||
|
||||
if(currentMode == M_NORMAL) {
|
||||
currentMode = M_SELECT;
|
||||
selectedIndex = 2;
|
||||
if(timeSinceLastClick < clickDiff) {
|
||||
clickCounter++;
|
||||
} else {
|
||||
currentMode = M_NORMAL;
|
||||
}
|
||||
|
||||
vTaskDelay(pdMS_TO_TICKS(2000));
|
||||
clickCounter = 1;
|
||||
}
|
||||
|
||||
lastClick = millis();
|
||||
@ -459,7 +472,6 @@ void checkClicks(void * parameter) {
|
||||
vTaskDelay(pdMS_TO_TICKS(20));
|
||||
}
|
||||
}
|
||||
|
||||
//############ End Hardware Helpers
|
||||
|
||||
//############ Drawing Functions
|
||||
@ -553,6 +565,7 @@ void drawPage() {
|
||||
int y = 16;
|
||||
|
||||
// Rotate the realtime data each 4s.
|
||||
if(settings[pageDisplay] == 0) {
|
||||
if ((millis() - lastDataRotation) >= 4000) {
|
||||
|
||||
lastDataRotation = millis();
|
||||
@ -562,6 +575,9 @@ void drawPage() {
|
||||
displayData = 0;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
displayData = settings[pageDisplay] - 1;
|
||||
}
|
||||
|
||||
switch (displayData) {
|
||||
case 0:
|
||||
|
@ -9,7 +9,6 @@
|
||||
#define wheelCircumference 26.062
|
||||
|
||||
TaskHandle_t rpmTaskHandle;
|
||||
|
||||
int rpmRight = 0;
|
||||
int rpmLeft = 0;
|
||||
|
||||
|
@ -1,18 +1,23 @@
|
||||
uint8_t currentSetting = 0;
|
||||
#define SETTINGS_COUNT 7
|
||||
|
||||
#define limitMode 0
|
||||
#define fanOveride 1
|
||||
#define wheelDiameter 2 // Speed factor
|
||||
#define minHallValue 3
|
||||
#define centerHallValue 4
|
||||
#define maxHallValue 5
|
||||
#define pageDisplay 0
|
||||
#define limitMode 1
|
||||
#define fanOveride 2
|
||||
#define wheelDiameter 3 // Speed factor
|
||||
#define minHallValue 4
|
||||
#define centerHallValue 5
|
||||
#define maxHallValue 6
|
||||
|
||||
int settings[SETTINGS_COUNT];
|
||||
|
||||
uint8_t boardOptions = 0b00000000;
|
||||
// Map:(Light, Fan) XXXXFFLL
|
||||
/*
|
||||
float gearRatio;
|
||||
float ratioRpmSpeed;
|
||||
float ratioPulseDistance;
|
||||
*/
|
||||
|
||||
// Defining variables for Settings menu
|
||||
bool changeSelectedSetting = false;
|
||||
@ -22,9 +27,9 @@ bool settingsChangeFlag = false;
|
||||
bool settingsChangeValueFlag = false;
|
||||
|
||||
const char *settingPages[SETTINGS_COUNT] = {
|
||||
"Page Display",
|
||||
"LimitMode",
|
||||
"FanOveride",
|
||||
"TriggerMode",
|
||||
"Wheel diameter",
|
||||
"Throttle Min",
|
||||
"Throttle Center",
|
||||
@ -33,9 +38,9 @@ const char *settingPages[SETTINGS_COUNT] = {
|
||||
|
||||
// Setting rules format: default, min, max.
|
||||
int settingRules[SETTINGS_COUNT][3] {
|
||||
{0, 0, 1}, // default is no limit
|
||||
{0, 0, 2}, // 0 no, 1 on, 2 off
|
||||
{0, 0, 3}, // 0 Killswitch, 1 cruise & 2 data toggle
|
||||
{0, 0, 3}, //page: 0 cycle, 1 speed, 2 volt, 3 temp
|
||||
{0, 0, 1}, //limit default is no limit
|
||||
{0, 0, 2}, //fan 0 no, 1 on, 2 off
|
||||
{83, 0, 250}, // wheel mm
|
||||
{HAL_MIN, 1000, 2000},
|
||||
{HAL_CENTER, 1000, 2000},
|
||||
@ -51,22 +56,33 @@ int settingRules[SETTINGS_COUNT][3] {
|
||||
//"Throttle Max"
|
||||
};
|
||||
*/
|
||||
|
||||
|
||||
// Check if an integer is within a min and max value
|
||||
bool inRange(int val, int minimum, int 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() {
|
||||
preferences.begin("remote-set", false);
|
||||
for (int i = 0; i < SETTINGS_COUNT; i++) {
|
||||
preferences.putInt(settingPages[i], settings[i]);
|
||||
}
|
||||
|
||||
preferences.end();
|
||||
DEBUG_PRINTLN("UPDATED");
|
||||
preferences.begin("remote-set", false);
|
||||
DEBUG_PRINTLN(preferences.getInt(settingPages[0], 0));
|
||||
preferences.end();
|
||||
//calculateRatios();
|
||||
updateBoardOptions();
|
||||
}
|
||||
|
||||
void setDefaultSettings() {
|
||||
@ -84,9 +100,7 @@ void loadSettings() {
|
||||
}
|
||||
preferences.end();
|
||||
|
||||
|
||||
bool rewriteSettings = false;
|
||||
|
||||
// Loop through all settings to check if everything is fine
|
||||
for (int i = 0; i < SETTINGS_COUNT; i++) {
|
||||
int val = settings[i];
|
||||
@ -97,12 +111,12 @@ void loadSettings() {
|
||||
settings[i] = settingRules[i][0];
|
||||
}
|
||||
}
|
||||
|
||||
if (rewriteSettings == true) {
|
||||
updateSettings();
|
||||
} else {
|
||||
// Calculate constants
|
||||
//calculateRatios();
|
||||
updateBoardOptions();
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user