ESPNOW fixes, Icons, Lights and much more
This commit is contained in:
parent
6fa5a11350
commit
25baa3a5bb
@ -16,7 +16,7 @@ build_flags = -DLOG_LOCAL_LEVEL=ESP_LOG_DEBUG
|
|||||||
|
|
||||||
src_filter = +<remote.cpp>
|
src_filter = +<remote.cpp>
|
||||||
|
|
||||||
monitor_baud = 115200
|
monitor_speed = 115200
|
||||||
upload_speed = 921600
|
upload_speed = 921600
|
||||||
|
|
||||||
|
|
||||||
@ -27,7 +27,7 @@ framework = arduino
|
|||||||
|
|
||||||
src_filter = +<receiver.cpp>
|
src_filter = +<receiver.cpp>
|
||||||
|
|
||||||
monitor_baud = 115200
|
monitor_speed = 115200
|
||||||
; upload_speed = 921600
|
; upload_speed = 921600
|
||||||
|
|
||||||
lib_deps =
|
lib_deps =
|
||||||
|
45
src/lights.h
45
src/lights.h
@ -3,6 +3,7 @@
|
|||||||
#define NUM_LEDS 40
|
#define NUM_LEDS 40
|
||||||
#define PIN_STRIP 17
|
#define PIN_STRIP 17
|
||||||
bool shouldUpdateLights = false;
|
bool shouldUpdateLights = false;
|
||||||
|
int lightMode = 0;
|
||||||
|
|
||||||
Adafruit_NeoPixel pixels = Adafruit_NeoPixel(NUM_LEDS, PIN_STRIP, NEO_GRB + NEO_KHZ800);
|
Adafruit_NeoPixel pixels = Adafruit_NeoPixel(NUM_LEDS, PIN_STRIP, NEO_GRB + NEO_KHZ800);
|
||||||
|
|
||||||
@ -24,10 +25,33 @@ void lightWhite() {
|
|||||||
portENABLE_INTERRUPTS();
|
portENABLE_INTERRUPTS();
|
||||||
}
|
}
|
||||||
|
|
||||||
void lightBackFront() {
|
void lightPolice() {
|
||||||
// Implement me :-)
|
// Temporary mode to test
|
||||||
for(int i = 0; i < NUM_LEDS; i++) {
|
for(int i = 0; i < NUM_LEDS; i++) {
|
||||||
pixels.setPixelColor(i, pixels.Color(180,180,180));
|
pixels.setPixelColor(i, pixels.Color(0,0,180));
|
||||||
|
}
|
||||||
|
|
||||||
|
portDISABLE_INTERRUPTS();
|
||||||
|
pixels.show();
|
||||||
|
portENABLE_INTERRUPTS();
|
||||||
|
}
|
||||||
|
|
||||||
|
void lightBlinkers(bool isLeft) {
|
||||||
|
// Temporary mode to test
|
||||||
|
for(int i = 0; i < NUM_LEDS; i++) {
|
||||||
|
if(i<10 && isLeft) pixels.setPixelColor(i, pixels.Color(180,180,0));
|
||||||
|
else if(i>30 && !isLeft) pixels.setPixelColor(i, pixels.Color(180,180,0));
|
||||||
|
else pixels.setPixelColor(i, pixels.Color(180,180,180));
|
||||||
|
}
|
||||||
|
portDISABLE_INTERRUPTS();
|
||||||
|
pixels.show();
|
||||||
|
portENABLE_INTERRUPTS();
|
||||||
|
}
|
||||||
|
|
||||||
|
void lightBackFront() {
|
||||||
|
for(int i = 0; i < NUM_LEDS; i++) {
|
||||||
|
if(i<5 || i>34) pixels.setPixelColor(i, pixels.Color(190,0,0));
|
||||||
|
else pixels.setPixelColor(i, pixels.Color(180,180,180));
|
||||||
}
|
}
|
||||||
portDISABLE_INTERRUPTS();
|
portDISABLE_INTERRUPTS();
|
||||||
pixels.show();
|
pixels.show();
|
||||||
@ -36,7 +60,20 @@ void lightBackFront() {
|
|||||||
|
|
||||||
void updateLights() {
|
void updateLights() {
|
||||||
if(lightActive) {
|
if(lightActive) {
|
||||||
lightWhite();
|
switch(lightMode) {
|
||||||
|
case 0:
|
||||||
|
lightBackFront();
|
||||||
|
break;
|
||||||
|
case 1:
|
||||||
|
lightBlinkers(true); // left
|
||||||
|
break;
|
||||||
|
case 2:
|
||||||
|
lightBlinkers(false); // right
|
||||||
|
break;
|
||||||
|
case 3:
|
||||||
|
lightPolice();
|
||||||
|
break;
|
||||||
|
}
|
||||||
}else {
|
}else {
|
||||||
lightOff();
|
lightOff();
|
||||||
}
|
}
|
||||||
|
@ -4,4 +4,4 @@
|
|||||||
uint8_t mac_receiver[] = {0xB4, 0xE6, 0x2D, 0x8C, 0x34, 0xAE};
|
uint8_t mac_receiver[] = {0xB4, 0xE6, 0x2D, 0x8C, 0x34, 0xAE};
|
||||||
|
|
||||||
// remote macStr
|
// remote macStr
|
||||||
uint8_t mac_remote[] = {0x24, 0x0a, 0xc4, 0x82, 0x51, 0x70};
|
uint8_t mac_remote[] = {0xB4, 0xE6, 0x2D, 0x8C, 0x38, 0x79};
|
||||||
|
@ -62,15 +62,14 @@ bool lightActive = false;
|
|||||||
int fanMode = FANS_AUTO;
|
int fanMode = FANS_AUTO;
|
||||||
|
|
||||||
#include "lights.h"
|
#include "lights.h"
|
||||||
|
|
||||||
void setBoardOptions(uint8_t options) {
|
void setBoardOptions(uint8_t options) {
|
||||||
Serial.print("opt: ");
|
if(lightActive != (options >> 4) & 1) {
|
||||||
Serial.println(options, BIN);
|
lightActive = (options >> 4) & 1;
|
||||||
if(lightActive != options & 1) {
|
|
||||||
lightActive = options & 1;
|
|
||||||
shouldUpdateLights = true;
|
shouldUpdateLights = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
lightMode = options & 3;
|
||||||
|
|
||||||
fanMode = (options >> 2) & 3;
|
fanMode = (options >> 2) & 3;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -312,6 +311,7 @@ void setup() {
|
|||||||
Serial.println("ESPNow Init Failed");
|
Serial.println("ESPNow Init Failed");
|
||||||
ESP.restart();
|
ESP.restart();
|
||||||
}
|
}
|
||||||
|
esp_now_set_self_role(ESP_NOW_ROLE_COMBO);
|
||||||
|
|
||||||
// Once ESPNow is successfully Init, we will register for recv CB to
|
// Once ESPNow is successfully Init, we will register for recv CB to
|
||||||
// get recv packer info.
|
// get recv packer info.
|
||||||
|
114
src/remote.cpp
114
src/remote.cpp
@ -74,28 +74,26 @@ uint8_t esc2 = 127;
|
|||||||
|
|
||||||
byte hallCenterMargin = 5;
|
byte hallCenterMargin = 5;
|
||||||
|
|
||||||
const float minVoltage = 2.9; // These values are heavily strange since the devider is not working nicely yet...
|
const float minVoltage = 3.4;
|
||||||
const float maxVoltage = 3.6;
|
const float maxVoltage = 4.2;
|
||||||
const float refVoltage = 3.3;
|
const float refVoltage = 3.3;
|
||||||
// Resistors in Ohms
|
// Resistors in Ohms
|
||||||
const float deviderR1 = 1500;
|
const float deviderR1 = 22000;
|
||||||
const float deviderR2 = 22000;
|
const float deviderR2 = 11200;
|
||||||
|
|
||||||
// Global copy of board
|
// Global copy of board
|
||||||
esp_now_peer_info_t board;
|
esp_now_peer_info_t board;
|
||||||
#define CHANNEL 1
|
#define CHANNEL 1
|
||||||
#define PRINTSCANRESULTS 0
|
#define PRINTSCANRESULTS 0
|
||||||
#define DELETEBEFOREPAIR 0
|
#define DELETEBEFOREPAIR 0
|
||||||
#define HAL_MIN 1390
|
#define HAL_MIN 1390 // defaults
|
||||||
#define HAL_MAX 2230
|
#define HAL_MAX 2230 // defaults
|
||||||
#define HAL_CENTER 1880
|
#define HAL_CENTER 1880 // defaults
|
||||||
#define TRIM_LOW 180
|
|
||||||
#define TRIM_HIGH 0
|
|
||||||
|
|
||||||
//#define pairingMode
|
//#define pairingMode
|
||||||
#define leverPin 36
|
#define leverPin 36
|
||||||
#define triggerPin 17
|
#define triggerPin 17
|
||||||
#define batteryMeasurePin 38
|
#define batteryMeasurePin 39
|
||||||
|
|
||||||
bool triggerActive();
|
bool triggerActive();
|
||||||
|
|
||||||
@ -113,6 +111,16 @@ void setCrusing(uint8_t speed) {
|
|||||||
}
|
}
|
||||||
// ESPNOW functions ##############################
|
// ESPNOW functions ##############################
|
||||||
// Scan for boards in AP mode
|
// 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
|
#ifdef pairingMode
|
||||||
void ScanForBoard() {
|
void ScanForBoard() {
|
||||||
@ -158,6 +166,7 @@ void ScanForBoard() {
|
|||||||
|
|
||||||
board.channel = CHANNEL; // pick a channel
|
board.channel = CHANNEL; // pick a channel
|
||||||
board.encrypt = 0; // no encryption
|
board.encrypt = 0; // no encryption
|
||||||
|
board.ifidx = ESP_IF_WIFI_STA;
|
||||||
|
|
||||||
boardFound = 1;
|
boardFound = 1;
|
||||||
// we are planning to have only one board in this example;
|
// we are planning to have only one board in this example;
|
||||||
@ -180,6 +189,7 @@ void ScanForBoard() {
|
|||||||
|
|
||||||
void deletePeer() {
|
void deletePeer() {
|
||||||
const esp_now_peer_info_t *peer = &board;
|
const esp_now_peer_info_t *peer = &board;
|
||||||
|
|
||||||
const uint8_t *peer_addr = board.peer_addr;
|
const uint8_t *peer_addr = board.peer_addr;
|
||||||
esp_err_t delStatus = esp_now_del_peer(peer_addr);
|
esp_err_t delStatus = esp_now_del_peer(peer_addr);
|
||||||
DEBUG_PRINT("board Delete Status: ");
|
DEBUG_PRINT("board Delete Status: ");
|
||||||
@ -272,8 +282,11 @@ void sendData() {
|
|||||||
DEBUG_PRINTLN("ESP_ERR_ESPNOW_NO_MEM");
|
DEBUG_PRINTLN("ESP_ERR_ESPNOW_NO_MEM");
|
||||||
} else if (result == ESP_ERR_ESPNOW_NOT_FOUND) {
|
} else if (result == ESP_ERR_ESPNOW_NOT_FOUND) {
|
||||||
DEBUG_PRINTLN("Peer not found.");
|
DEBUG_PRINTLN("Peer not found.");
|
||||||
|
} else if (result == ESP_ERR_ESPNOW_IF) {
|
||||||
|
DEBUG_PRINTLN("Interface error.");
|
||||||
} else {
|
} 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;
|
int maxSpeed = 255;
|
||||||
if(settings[limitMode] == 1) maxSpeed = 180;
|
if(settings[limitMode] == 1) maxSpeed = 180;
|
||||||
|
|
||||||
if (hallMeasurement >= HAL_CENTER) {
|
if (hallMeasurement >= settings[centerHallValue]) {
|
||||||
throttle = c_map(hallMeasurement, HAL_CENTER, HAL_MAX, 127, maxSpeed);
|
throttle = c_map(hallMeasurement, settings[centerHallValue], settings[maxHallValue], 127, maxSpeed);
|
||||||
} else {
|
} else {
|
||||||
throttle = c_map(hallMeasurement, HAL_MIN, HAL_CENTER, 0, 127);
|
throttle = c_map(hallMeasurement, settings[minHallValue], settings[centerHallValue], 0, 127);
|
||||||
}
|
}
|
||||||
// removeing center noise
|
// removeing center noise
|
||||||
if (abs(throttle - 127) < hallCenterMargin) {
|
if (abs(throttle - 127) < hallCenterMargin) {
|
||||||
@ -647,25 +660,29 @@ void drawPage() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void controlSelect() {
|
void controlSelect() {
|
||||||
if (hallMeasurement >= (HAL_MAX - 250) && settingsLoopFlag == false) { //settings[maxHallValue]
|
if (hallMeasurement >= (settings[maxHallValue] - 250) && settingsLoopFlag == false) { //settings[maxHallValue]
|
||||||
// Up
|
// Up
|
||||||
if (selectedIndex != 0) {
|
if (selectedIndex != 0) {
|
||||||
selectedIndex--;
|
selectedIndex--;
|
||||||
settingsLoopFlag = true;
|
settingsLoopFlag = true;
|
||||||
}
|
}
|
||||||
} else if (hallMeasurement <= (HAL_MIN + 250) && settingsLoopFlag == false) { //settings[minHallValue]
|
} else if (hallMeasurement <= (settings[minHallValue] + 250) && settingsLoopFlag == false) {
|
||||||
// Down
|
// Down
|
||||||
if (selectedIndex < 4) {
|
if (selectedIndex < 4) {
|
||||||
selectedIndex++;
|
selectedIndex++;
|
||||||
settingsLoopFlag = true;
|
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;
|
settingsLoopFlag = false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
String selectionItems[5] = {
|
String selectionTitles[5] = {
|
||||||
"Se","Li","B","St","Cr"
|
"Settings","Limit","Light","Steering","Cruise"
|
||||||
|
};
|
||||||
|
|
||||||
|
uint16_t selectionGlyphs[5] = {
|
||||||
|
0x0081, 0x008d, 0x0103, 0x00f6, 0x0088
|
||||||
};
|
};
|
||||||
|
|
||||||
void drawSelectionMenu() {
|
void drawSelectionMenu() {
|
||||||
@ -676,21 +693,25 @@ void drawSelectionMenu() {
|
|||||||
u8g2.setFontMode(0);
|
u8g2.setFontMode(0);
|
||||||
u8g2.setDrawColor(1);
|
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++) {
|
for(int i = 0; i < 5; i++) {
|
||||||
if(selectedIndex == 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.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);
|
u8g2.setDrawColor(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
selectionItems[i].toCharArray(displayBuffer, 10);
|
//selectionItems[i].toCharArray(displayBuffer, 10);
|
||||||
u8g2.setFont(u8g2_font_profont12_tr);
|
//u8g2.setFont(u8g2_font_profont12_tr);
|
||||||
u8g2.drawStr(xStart + xSpace * i, y, displayBuffer);
|
//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.setFontMode(0);
|
||||||
u8g2.setDrawColor(1);
|
u8g2.setDrawColor(1);
|
||||||
@ -776,7 +797,11 @@ void drawStartScreen() {
|
|||||||
void setup() {
|
void setup() {
|
||||||
Serial.begin(115200);
|
Serial.begin(115200);
|
||||||
//Set device in STA mode to begin with
|
//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");
|
DEBUG_PRINTLN("ESPNowSkate");
|
||||||
|
|
||||||
loadSettings();
|
loadSettings();
|
||||||
@ -787,8 +812,6 @@ void setup() {
|
|||||||
delay(50);
|
delay(50);
|
||||||
digitalWrite(16, HIGH);
|
digitalWrite(16, HIGH);
|
||||||
|
|
||||||
analogSetPinAttenuation(batteryMeasurePin, ADC_6db);
|
|
||||||
|
|
||||||
// setup other pins
|
// setup other pins
|
||||||
pinMode(triggerPin, INPUT_PULLUP);
|
pinMode(triggerPin, INPUT_PULLUP);
|
||||||
|
|
||||||
@ -813,8 +836,8 @@ void setup() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// This is the mac address of the Master in Station Mode
|
// 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) {
|
if (esp_now_init() == ESP_OK) {
|
||||||
DEBUG_PRINTLN("ESPNow Init Success");
|
DEBUG_PRINTLN("ESPNow Init Success");
|
||||||
}
|
}
|
||||||
@ -839,18 +862,27 @@ void setup() {
|
|||||||
}
|
}
|
||||||
board.channel = CHANNEL; // pick a channel
|
board.channel = CHANNEL; // pick a channel
|
||||||
board.encrypt = 0; // no encryption
|
board.encrypt = 0; // no encryption
|
||||||
|
//board.ifidx = ESP_IF_WIFI_STA;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void loop() {
|
void loop() {
|
||||||
updateMainDisplay();
|
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): ");
|
DEBUG_PRINT(" (X): ");
|
||||||
Serial.print(map(AcY, -15000, 15000, -100, 100));
|
DEBUG_PRINT(map(AcX, -15000, 15000, -100, 100));
|
||||||
Serial.print("Help(Y): ");
|
|
||||||
Serial.println(map(GyY, -15000, 15000, -100, 100));
|
|
||||||
|
|
||||||
|
DEBUG_PRINT(" (Z): ");
|
||||||
|
DEBUG_PRINTLN(map(AcZ, -15000, 15000, -100, 100));
|
||||||
|
|
||||||
|
// left rigt : Z forward Back : Y
|
||||||
calculateThrottlePosition();
|
calculateThrottlePosition();
|
||||||
|
|
||||||
if (currentMode == M_SELECT) {
|
if (currentMode == M_SELECT) {
|
||||||
@ -865,7 +897,7 @@ void loop() {
|
|||||||
if (triggerActive()) {
|
if (triggerActive()) {
|
||||||
if(currentMode == M_STEERING) {
|
if(currentMode == M_STEERING) {
|
||||||
DEBUG_PRINT("Value: ");
|
DEBUG_PRINT("Value: ");
|
||||||
int map = c_map(AcX, 15000, -15000, -60, 60);
|
int map = c_map(AcZ, -15000, 15000, -60, 60);
|
||||||
DEBUG_PRINTLN(map);
|
DEBUG_PRINTLN(map);
|
||||||
|
|
||||||
#ifdef steeringInfluential
|
#ifdef steeringInfluential
|
||||||
@ -878,6 +910,12 @@ void loop() {
|
|||||||
esc1 = throttle;
|
esc1 = throttle;
|
||||||
esc2 = throttle;
|
esc2 = throttle;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// ignore reverse
|
||||||
|
if(throttle < 127) {
|
||||||
|
esc1 = throttle;
|
||||||
|
esc2 = throttle;
|
||||||
|
}
|
||||||
#endif
|
#endif
|
||||||
if(throttle == 127) {
|
if(throttle == 127) {
|
||||||
esc1 = 127;
|
esc1 = 127;
|
||||||
|
@ -15,8 +15,8 @@
|
|||||||
#include "driver/pcnt.h"
|
#include "driver/pcnt.h"
|
||||||
|
|
||||||
TaskHandle_t rpmTaskHandle;
|
TaskHandle_t rpmTaskHandle;
|
||||||
int rpmRight = 0;
|
float rpmRight = 0;
|
||||||
int rpmLeft = 0;
|
float rpmLeft = 0;
|
||||||
|
|
||||||
int lastState[2] = {1, 1};
|
int lastState[2] = {1, 1};
|
||||||
int16_t counter[2] = {0, 0};
|
int16_t counter[2] = {0, 0};
|
||||||
@ -123,7 +123,7 @@ void measureRpm(void * parameter) {
|
|||||||
rpmRight = (counter[0]/pulsesPerRotation)*4;
|
rpmRight = (counter[0]/pulsesPerRotation)*4;
|
||||||
rpmLeft = (counter[1]/pulsesPerRotation)*4;
|
rpmLeft = (counter[1]/pulsesPerRotation)*4;
|
||||||
kmh = (wheelCircumference/100) * (rpmRight+rpmLeft)/2 * 3600/1000;
|
kmh = (wheelCircumference/100) * (rpmRight+rpmLeft)/2 * 3600/1000;
|
||||||
Serial.print(kmh); Serial.print(" "); Serial.println(direction[0]);
|
//Serial.print(kmh); Serial.print(" "); Serial.println(direction[0]);
|
||||||
sendSpeed = abs(floor(kmh));
|
sendSpeed = abs(floor(kmh));
|
||||||
sendSpeedDecimals = (kmh - sendSpeed) * 100;
|
sendSpeedDecimals = (kmh - sendSpeed) * 100;
|
||||||
counter[true] = 0;
|
counter[true] = 0;
|
||||||
|
@ -1,18 +1,19 @@
|
|||||||
uint8_t currentSetting = 0;
|
uint8_t currentSetting = 0;
|
||||||
#define SETTINGS_COUNT 7
|
#define SETTINGS_COUNT 8
|
||||||
|
|
||||||
#define pageDisplay 0
|
#define pageDisplay 0
|
||||||
#define limitMode 1
|
#define limitMode 1
|
||||||
#define fanOveride 2
|
#define fanOveride 2
|
||||||
#define wheelDiameter 3 // Speed factor
|
#define wheelDiameter 3 // Speed factor
|
||||||
#define minHallValue 4
|
#define lightMode 4
|
||||||
#define centerHallValue 5
|
#define minHallValue 5
|
||||||
#define maxHallValue 6
|
#define centerHallValue 6
|
||||||
|
#define maxHallValue 7
|
||||||
|
|
||||||
int settings[SETTINGS_COUNT];
|
int settings[SETTINGS_COUNT];
|
||||||
|
|
||||||
uint8_t boardOptions = 0b00000000;
|
uint8_t boardOptions = 0b00000000;
|
||||||
// Map:(Light, Fan) XXXXFFLL
|
// Map:(LightActive, Fan, LightMode) XXXAFFLL
|
||||||
/*
|
/*
|
||||||
float gearRatio;
|
float gearRatio;
|
||||||
float ratioRpmSpeed;
|
float ratioRpmSpeed;
|
||||||
@ -31,6 +32,7 @@ const char *settingPages[SETTINGS_COUNT] = {
|
|||||||
"LimitMode",
|
"LimitMode",
|
||||||
"FanOveride",
|
"FanOveride",
|
||||||
"Wheel diameter",
|
"Wheel diameter",
|
||||||
|
"Light Mode",
|
||||||
"Throttle Min",
|
"Throttle Min",
|
||||||
"Throttle Center",
|
"Throttle Center",
|
||||||
"Throttle Max"
|
"Throttle Max"
|
||||||
@ -42,9 +44,10 @@ int settingRules[SETTINGS_COUNT][3] {
|
|||||||
{0, 0, 1}, //limit default is no limit
|
{0, 0, 1}, //limit default is no limit
|
||||||
{0, 0, 2}, //fan 0 no, 1 on, 2 off
|
{0, 0, 2}, //fan 0 no, 1 on, 2 off
|
||||||
{83, 0, 250}, // wheel mm
|
{83, 0, 250}, // wheel mm
|
||||||
{HAL_MIN, 1000, 2000},
|
{0, 0, 3}, // LightMode
|
||||||
{HAL_CENTER, 1000, 2000},
|
{HAL_MIN, 1000, 3000},
|
||||||
{HAL_MAX, 1000, 2000}
|
{HAL_CENTER, 1000, 3000},
|
||||||
|
{HAL_MAX, 1000, 3000}
|
||||||
};
|
};
|
||||||
/*
|
/*
|
||||||
const char *settingAliases[SETTINGS_COUNT] = {
|
const char *settingAliases[SETTINGS_COUNT] = {
|
||||||
@ -66,8 +69,10 @@ bool inRange(int val, int minimum, int maximum) {
|
|||||||
void updateBoardOptions() {
|
void updateBoardOptions() {
|
||||||
boardOptions = 0;
|
boardOptions = 0;
|
||||||
boardOptions |= (uint8_t) settings[fanOveride] << 2;
|
boardOptions |= (uint8_t) settings[fanOveride] << 2;
|
||||||
boardOptions |= boardOptions | (uint8_t) lightActive;
|
|
||||||
Serial.print("board: "); Serial.println(boardOptions);
|
boardOptions |= boardOptions | (uint8_t) lightActive << 3;
|
||||||
|
boardOptions |= boardOptions | (uint8_t) settings[lightMode];
|
||||||
|
DEBUG_PRINT("board: "); DEBUG_PRINTLN(boardOptions);
|
||||||
}
|
}
|
||||||
|
|
||||||
void updateSettings() {
|
void updateSettings() {
|
||||||
@ -188,7 +193,7 @@ void controlSettingsMenu() {
|
|||||||
settingsChangeFlag = false;
|
settingsChangeFlag = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (hallMeasurement >= (HAL_MAX - 250) && settingsLoopFlag == false) { //settings[maxHallValue]
|
if (hallMeasurement >= (settings[maxHallValue] - 250) && settingsLoopFlag == false) {
|
||||||
// Up
|
// Up
|
||||||
if (changeSelectedSetting == true) {
|
if (changeSelectedSetting == true) {
|
||||||
int val = settings[currentSetting] - 1;
|
int val = settings[currentSetting] - 1;
|
||||||
@ -204,7 +209,7 @@ void controlSettingsMenu() {
|
|||||||
settingsLoopFlag = true;
|
settingsLoopFlag = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else if (hallMeasurement <= (HAL_MIN + 250) && settingsLoopFlag == false) { //settings[minHallValue]
|
} else if (hallMeasurement <= (settings[minHallValue] + 250) && settingsLoopFlag == false) {
|
||||||
// Down
|
// Down
|
||||||
if (changeSelectedSetting == true) {
|
if (changeSelectedSetting == true) {
|
||||||
int val = settings[currentSetting] + 1;
|
int val = settings[currentSetting] + 1;
|
||||||
@ -219,7 +224,7 @@ void controlSettingsMenu() {
|
|||||||
settingsLoopFlag = true;
|
settingsLoopFlag = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else if (inRange(hallMeasurement, HAL_CENTER - 50, HAL_CENTER + 50)) { // settings[centerHallValue]
|
} else if (inRange(hallMeasurement, settings[centerHallValue] - 50, settings[centerHallValue] + 50)) {
|
||||||
settingsLoopFlag = false;
|
settingsLoopFlag = false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user