changed valuerange to 255 and tested device

This commit is contained in:
Lukas Bachschwell 2018-04-17 21:57:25 +02:00
parent c01d36fc34
commit 76fb5d0dcf
2 changed files with 69 additions and 106 deletions

View File

@ -8,6 +8,7 @@
#define esc1pin 15 #define esc1pin 15
#define esc2pin 13 #define esc2pin 13
#define fallbackpin 36 #define fallbackpin 36
#define failsafeValue 127
Servo esc1; Servo esc1;
@ -72,8 +73,8 @@ void setup() {
// Init escs, min and max value similar as Traxxas TQI 1100, 1900 // Init escs, min and max value similar as Traxxas TQI 1100, 1900
// chanel, minAngel, maxAngel, minPulseWidth, maxPulseWidth // chanel, minAngel, maxAngel, minPulseWidth, maxPulseWidth
esc1.attach(esc1pin, 0, 0, 180, 1100, 1900); esc1.attach(esc1pin, 0, 0, 255, 1100, 1900);
esc2.attach(esc2pin, 1, 0, 180, 1100, 1900); esc2.attach(esc2pin, 1, 0, 255, 1100, 1900);
//Set device in AP mode to begin with //Set device in AP mode to begin with
WiFi.mode(WIFI_AP); WiFi.mode(WIFI_AP);
@ -103,7 +104,8 @@ void setup() {
void loop() { void loop() {
if(millis() - lastPacket > CONNECTION_TIMEOUT ) { if(millis() - lastPacket > CONNECTION_TIMEOUT ) {
isConnected = false; isConnected = false;
int failsafeValue = map(analogRead(fallbackpin), 0, 4095, 0, 180); //int failsafeValue = map(analogRead(fallbackpin), 0, 4095, 0, 180);
// Taking 127 because it should be the center value anyway
writeServos(failsafeValue, failsafeValue); writeServos(failsafeValue, failsafeValue);
display.clear(); display.clear();
char buf[25]; char buf[25];

View File

@ -36,22 +36,24 @@ const byte numOfSettings = 11;
const float minVoltage = 3.2; const float minVoltage = 3.2;
const float maxVoltage = 4.1; const float maxVoltage = 4.1;
const float refVoltage = 3.3;
// Global copy of slave // Global copy of slave
esp_now_peer_info_t slave; esp_now_peer_info_t slave;
#define CHANNEL 3 #define CHANNEL 3
#define PRINTSCANRESULTS 0 #define PRINTSCANRESULTS 0
#define DELETEBEFOREPAIR 0 #define DELETEBEFOREPAIR 0
#define HAL_MIN 1290 #define HAL_MIN 1390
#define HAL_MAX 2285 #define HAL_MAX 2260
#define HAL_CENTER 1785 #define HAL_CENTER 1890
#define TRIM_LOW 180 #define TRIM_LOW 180
#define TRIM_HIGH 0 #define TRIM_HIGH 0
//#define pairingMode //#define pairingMode
#define leverPin 36 #define leverPin 36
#define triggerPin 37 #define triggerPin 17
#define batteryMeasurePin 35 #define batteryMeasurePin 38
// ESPNOW functions ############################## // ESPNOW functions ##############################
@ -193,7 +195,7 @@ bool manageSlave() {
// send data // send data
void sendData() { void sendData() {
uint8_t esc1 = map(analogRead(leverPin), HAL_MIN, HAL_MAX, TRIM_LOW, TRIM_HIGH); uint8_t esc1 = sendThrottle;
uint8_t esc2 = esc1; uint8_t esc2 = esc1;
const uint8_t data[] = { esc1, esc2 }; // no mixture for the normal mode const uint8_t data[] = { esc1, esc2 }; // no mixture for the normal mode
@ -252,7 +254,7 @@ void calculateThrottlePosition() {
total += analogRead(leverPin); total += analogRead(leverPin);
} }
hallMeasurement = total / 10; hallMeasurement = total / 10;
Serial.println(hallMeasurement);
//DEBUG_PRINT( (String)hallMeasurement ); //DEBUG_PRINT( (String)hallMeasurement );
if (hallMeasurement >= HAL_CENTER) { if (hallMeasurement >= HAL_CENTER) {
@ -271,16 +273,13 @@ float batteryVoltage() {
float batteryVoltage = 0.0; float batteryVoltage = 0.0;
int total = 0; int total = 0;
return 3.6; // for now always full for (int i = 0; i < 10; i++) {
/*
for (int i = 0; i < 10; i++) {
total += analogRead(batteryMeasurePin); total += analogRead(batteryMeasurePin);
} }
batteryVoltage = (refVoltage / 1024.0) * ((float)total / 10.0); batteryVoltage = (refVoltage / 4096.0) * ((float)total / 10.0);
Serial.println(batteryVoltage);
return batteryVoltage; return batteryVoltage;
*/
} }
// Function used to indicate the remotes battery level. // Function used to indicate the remotes battery level.
@ -392,84 +391,47 @@ void drawTitleScreen(String title) {
delay(1500); delay(1500);
} }
void drawPage() { void drawBoardVoltage() {
/*
int decimals;
float value;
String suffix;
String prefix;
int first, last; int x = 0;
int y = 16;
String suffix = "V";
String prefix = "BATTERY";
float value = 0.0; // TODO: No info this yet, measure in the board
int x = 0; // Display prefix (title)
int y = 16; displayString = prefix;
displayString.toCharArray(displayBuffer, 10);
u8g2.setFont(u8g2_font_profont12_tr);
u8g2.drawStr(x, y - 1, displayBuffer);
// Rotate the realtime data each 4s. // Split up the float value: a number, b decimals.
if ((millis() - lastDataRotation) >= 4000) { int first = abs(floor(value));
int last = value * pow(10, 3) - first * pow(10, 3);
lastDataRotation = millis(); // Add leading zero
displayData++; if (first <= 9) {
displayString = "0" + (String)first;
} else {
displayString = (String)first;
}
if (displayData > 2) { // Display numbers
displayData = 0; displayString.toCharArray(displayBuffer, 10);
} u8g2.setFont(u8g2_font_logisoso22_tn );
} u8g2.drawStr(x + 55, y + 13, displayBuffer);
switch (displayData) { // Display decimals
case 0: displayString = "." + (String)last;
value = ratioRpmSpeed * data.rpm; displayString.toCharArray(displayBuffer, 3);
suffix = "KMH"; u8g2.setFont(u8g2_font_profont12_tr);
prefix = "SPEED"; u8g2.drawStr(x + 86, y - 1, displayBuffer);
decimals = 1;
break;
case 1:
value = ratioPulseDistance * data.tachometerAbs;
suffix = "KM";
prefix = "DISTANCE";
decimals = 2;
break;
case 2:
value = data.inpVoltage;
suffix = "V";
prefix = "BATTERY";
decimals = 1;
break;
}
// Display prefix (title) // Display suffix
displayString = prefix; displayString = suffix;
displayString.toCharArray(displayBuffer, 10); displayString.toCharArray(displayBuffer, 10);
u8g2.setFont(u8g2_font_profont12_tr); u8g2.setFont(u8g2_font_profont12_tr);
u8g2.drawStr(x, y - 1, displayBuffer); u8g2.drawStr(x + 86 + 2, y + 13, displayBuffer);
// Split up the float value: a number, b decimals.
first = abs(floor(value));
last = value * pow(10, 3) - first * pow(10, 3);
// Add leading zero
if (first <= 9) {
displayString = "0" + (String)first;
} else {
displayString = (String)first;
}
// Display numbers
displayString.toCharArray(displayBuffer, 10);
u8g2.setFont(u8g2_font_logisoso22_tn );
u8g2.drawStr(x + 55, y + 13, displayBuffer);
// Display decimals
displayString = "." + (String)last;
displayString.toCharArray(displayBuffer, decimals + 2);
u8g2.setFont(u8g2_font_profont12_tr);
u8g2.drawStr(x + 86, y - 1, displayBuffer);
// Display suffix
displayString = suffix;
displayString.toCharArray(displayBuffer, 10);
u8g2.setFont(u8g2_font_profont12_tr);
u8g2.drawStr(x + 86 + 2, y + 13, displayBuffer);
*/
} }
void drawSettingsMenu() { void drawSettingsMenu() {
@ -519,11 +481,11 @@ void updateMainDisplay() {
do { do {
if (changeSettings == true) { if (changeSettings == true) {
//drawSettingsMenu(); drawSettingsMenu();
drawSettingNumber(); drawSettingNumber();
} else { } else {
drawThrottle(); drawThrottle();
drawPage(); drawBoardVoltage();
drawBatteryLevel(); drawBatteryLevel();
drawSignal(); drawSignal();
} }
@ -564,12 +526,12 @@ void setup() {
Serial.println("ESPNowSkate Sender"); Serial.println("ESPNowSkate Sender");
u8g2.begin(); u8g2.begin();
drawStartScreen(); drawStartScreen();
/*
if (triggerActive()) { if (triggerActive()) {
changeSettings = true; changeSettings = true;
drawTitleScreen("Remote Settings"); drawTitleScreen("Remote Settings");
} }
*/
// This is the mac address of the Master in Station Mode // This is the mac address of the Master in Station Mode
Serial.print("STA MAC: "); Serial.println(WiFi.macAddress()); Serial.print("STA MAC: "); Serial.println(WiFi.macAddress());
@ -599,17 +561,6 @@ void loop() {
// Call function to update display and LED // Call function to update display and LED
updateMainDisplay(); updateMainDisplay();
/* update Value
char buf[10];
sprintf(buf, "%i", map(analogRead(leverPin), HAL_MIN, HAL_MAX, TRIM_LOW, TRIM_HIGH));
u8g2.firstPage();
do {
u8g2.setFont(u8g2_font_10x20_tr );
u8g2.drawStr(0, 20, buf);
} while ( u8g2.nextPage() );
*/
calculateThrottlePosition(); calculateThrottlePosition();
if (changeSettings == true) { if (changeSettings == true) {
@ -633,7 +584,17 @@ void loop() {
if (isPaired) { if (isPaired) {
// pair success or already paired // pair success or already paired
// Send data to device // Send data to device
sendData(); sendData();
/* update Value
char buf[10];
sprintf(buf, "%i", map(analogRead(leverPin), HAL_MIN, HAL_MAX, TRIM_LOW, TRIM_HIGH));
u8g2.firstPage();
do {
u8g2.setFont(u8g2_font_10x20_tr );
u8g2.drawStr(0, 20, buf);
} while ( u8g2.nextPage() );
*/
} else { } else {
// slave pair failed // slave pair failed