change display ui

This commit is contained in:
interfisch 2024-07-13 20:58:27 +02:00
parent f5cfe91fcb
commit abdff38ae4
5 changed files with 225 additions and 154 deletions

View File

@ -91,7 +91,7 @@ bool error_brake_outofrange=false;
bool error_ads_max_read_interval=false; bool error_ads_max_read_interval=false;
bool error_sdfile_unavailable=false; bool error_sdfile_unavailable=false;
#define REVERSE_ENABLE_TIME 1000 //ms. how long standstill to be able to drive backward #define REVERSE_ENABLE_TIME 500 //ms. how long standstill to be able to drive backward
#define NORMAL_MAX_ACCELERATION_RATE 10000 #define NORMAL_MAX_ACCELERATION_RATE 10000

View File

@ -15,6 +15,8 @@
#define SCREEN_ADDRESS 0x3C ///< See datasheet for Address; 0x3D for 128x64, 0x3C for 128x32 #define SCREEN_ADDRESS 0x3C ///< See datasheet for Address; 0x3D for 128x64, 0x3C for 128x32
Adafruit_SSD1306 display(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, OLED_RESET); Adafruit_SSD1306 display(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, OLED_RESET);
uint8_t standingDisplayScreen=0;
#define NUM_STANDINGDISPLAYSCREEN 3
bool display_init(); bool display_init();
@ -29,6 +31,7 @@ void display_debugDisplay(ESCSerialComm& escFront, ESCSerialComm& escRear);
bool display_init(){ bool display_init(){
if(!display.begin(SSD1306_SWITCHCAPVCC, SCREEN_ADDRESS)) { if(!display.begin(SSD1306_SWITCHCAPVCC, SCREEN_ADDRESS)) {
Serial.println(F("SSD1306 allocation failed")); Serial.println(F("SSD1306 allocation failed"));
writeLogComment((unsigned long)millis(), "SSD1306 allocation failed");
return false; return false;
} }
display.clearDisplay(); display.clearDisplay();
@ -81,17 +84,14 @@ void display_update(ESCSerialComm& escFront, ESCSerialComm& escRear){
display.print(errorstring); display.print(errorstring);
}else{ }else{
//Normal Display Routinges here //Normal Display Routines here
if (armed) { if (armed) {
if (loopmillis-last_notidle>5000) { if (loopmillis-last_notidle>5000) {
display_standingDisplay(escFront,escRear); display_standingDisplay(escFront,escRear);
}else{ }else{
if (!control_buttonA) { display_drivingDisplay(escFront,escRear);
display_drivingDisplay(escFront,escRear); //display_debugDisplay(escFront,escRear);
}else{
display_debugDisplay(escFront,escRear);
}
} }
}else{ }else{
@ -108,13 +108,16 @@ void display_update(ESCSerialComm& escFront, ESCSerialComm& escRear){
void display_drivingDisplay(ESCSerialComm& escFront, ESCSerialComm& escRear) { void display_drivingDisplay(ESCSerialComm& escFront, ESCSerialComm& escRear) {
//Display stuff here for when bobbycar is moving or was moving recently and is armed
//## Km/h Display //## Km/h Display
display.setFont(&FreeMonoBold18pt7b); display.setFont(&FreeMonoBold18pt7b);
display.setTextSize(1); // Normal 1:1 pixel scale display.setTextSize(1); // Normal 1:1 pixel scale
display.setTextColor(SSD1306_WHITE); // Draw white text display.setTextColor(SSD1306_WHITE); // Draw white text
display.setCursor(0,SCREEN_HEIGHT-(SCREEN_HEIGHT-18)/2 - 3); // Start at top-left corner display.setCursor(0,SCREEN_HEIGHT-(SCREEN_HEIGHT-18)/2 - 3); // Start at top-left corner
//float _speeddisplay=(escFront.getMeanSpeed()+escRear.getMeanSpeed())/2.0*3.6; //float _speeddisplay=(escFront.getMeanSpeed()+escRear.getMeanSpeed())/2.0*3.6;
float _speeddisplay=minSpeedms*3.6; float _speeddisplay=minSpeedms*3.6;
@ -151,40 +154,36 @@ void display_drivingDisplay(ESCSerialComm& escFront, ESCSerialComm& escRear) {
//## Trip / Current Consumed Display //## Trip / Current Consumed Display
display.setCursor(1,SCREEN_HEIGHT-7); display.setCursor(1,SCREEN_HEIGHT-7);
//if (((millis()/2500)%2)==0) {
if (control_buttonB) {
//## Speed statistic
display.print("max: ");
dtostrf(max_meanSpeed*3.6,1,0,buf);
display.print((String)buf);
display.print("km/h");
}else{
//## Current Consumed
/*
dtostrf(min_filtered_currentAll,1,1,buf);
display.print("min:");
display.print((String)buf);
display.print("A max:");
dtostrf(max_filtered_currentAll,1,1,buf); //## Current
display.print((String)buf); /*
display.print("A"); dtostrf(min_filtered_currentAll,1,1,buf);
*/ display.print("min:");
//## Watt Hours Consumed display.print((String)buf);
dtostrf(min_filtered_wattAll,1,0,buf); display.print("A max:");
display.print("min:");
display.print((String)buf);
display.print("W max:");
dtostrf(max_filtered_wattAll,1,0,buf); dtostrf(max_filtered_currentAll,1,1,buf);
display.print((String)buf); display.print((String)buf);
display.print("W"); display.print("A");
} */
//## Watt
dtostrf(min_filtered_wattAll,1,0,buf);
display.print((String)buf);
display.print(" / ");
dtostrf(max_filtered_wattAll,1,0,buf);
display.print((String)buf);
display.print("W ");
display.setCursor(SCREEN_WIDTH-6*6,SCREEN_HEIGHT-7);
dtostrf(max_meanSpeed*3.6,1,0,buf);
display.print((String)buf);
display.print("km/h");
} }
void display_debugDisplay(ESCSerialComm& escFront, ESCSerialComm& escRear) { void display_debugDisplay(ESCSerialComm& escFront, ESCSerialComm& escRear) {
//Debug //Debug
display.setTextSize(2); // Normal 1:1 pixel scale display.setTextSize(2); // Normal 1:1 pixel scale
@ -220,30 +219,157 @@ void display_debugDisplay(ESCSerialComm& escFront, ESCSerialComm& escRear) {
display.print(" thrpos="); display.print(" thrpos=");
display.print(throttle_pos); display.print(throttle_pos);
*/ */
} }
void display_standingDisplay(ESCSerialComm& escFront, ESCSerialComm& escRear) { void display_standingDisplay(ESCSerialComm& escFront, ESCSerialComm& escRear) {
//Display stuff here when ESCs are powered on and bobbycar is armed but was not moving for a while
double _displaytrip=trip; double _displaytrip=trip;
//double _displaycurrent=currentConsumed; //double _displaycurrent=currentConsumed;
double _displaywatthours=watthoursConsumed; double _displaywatthours=watthoursConsumed;
//bool _displayOverall= ((millis()/3000)%2==0); //switch based on time bool _displayOverall= ((millis()/2500)%2==0); //switch based on time
bool _displayOverall=control_buttonB; //switch with button
bool _displayParameters=control_buttonA;
char buf[8]; char buf[8];
display.setFont(); display.setFont();
display.setCursor(0,0); display.setCursor(0,0);
if (_displayParameters) {
if (_displayOverall) { //alternate between this trip and overall trip
_displaytrip=overallTrip;
//_displaycurrent=overallCurrentConsumed;
_displaywatthours=overallWatthoursConsumed;
}
//Row 1
display.print(F("Vbat:")); display.print(escFront.getFeedback_batVoltage());
display.print(F("/")); display.print(escRear.getFeedback_batVoltage());
display.print(" V");
display.println();
//Row 2
//display.print(F("Temp:")); display.print(escFront.getFeedback_boardTemp());
//display.print(F("/")); display.print(escRear.getFeedback_boardTemp());
display.print(F("T:")); display.print(temp_ESCFront,0);
display.print(F("/")); display.print(temp_ESCRear,0);
display.print(F("/")); display.print(temp_Air,0);
display.print(" C");
display.println();
//Row 3
display.print(F("Trip:"));
dtostrf(_displaytrip,1,0,buf);
display.print((String)buf);
display.print("m ");
//dtostrf(_displaycurrent,1,2,buf);
dtostrf(_displaywatthours,1,2,buf);
display.print((String)buf);
//display.print(" Ah");
display.print("Wh");
display.println();
//Row 4
display.print(F(""));
//dtostrf( _displaytrip/1000/_displaycurrent ,1,2,buf);
dtostrf( _displaywatthours/_displaytrip*100,1,2,buf);
display.print((String)buf);
//display.print(" km/Ah");
display.print(" kWh/100km");
if (_displayOverall){
display.print(" sum");
}
display.println();
}
void display_standingDisarmedDisplay(ESCSerialComm& escFront, ESCSerialComm& escRear) {
//Displayed stuff here when escs are powered off / disconnected or bobbycar is not armed
char buf[8];
display.setFont();
display.setCursor(0,0);
switch(standingDisplayScreen)
{
case 0:
//Quick overview of inputs and status
//Row1
if (getDatalogging()) {
display.print(getLogFilename());
}else{
display.print("LOG DISABLED");
}
display.print(F(" ")); display.print(loopmillis/1000);
display.print(F("s"));
display.println();
//Row2
display.print("Throttle ");
dtostrf(ads_throttle_A_raw,1,0,buf);
display.print((String)buf);
display.print("/");
dtostrf(ads_throttle_B_raw,1,0,buf);
display.print((String)buf);
display.println();
//Row3
display.print("Brake ");
dtostrf(ads_brake_raw,1,0,buf);
display.print((String)buf);
display.println();
/*display.print(" c=");
dtostrf(ads_control_raw,1,0,buf);
display.print((String)buf); */
break;
case 1:
//Trip Stats (trip / overall)
//Row 1
display.print(F("Trip ")); display.print(trip,0); display.print(F(" / ")); display.print(overallTrip,0); display.print(F("m"));
display.println();
//Row 2
display.print(F("Curr ")); display.print(currentConsumed*1000,0); display.print(F(" / ")); display.print(overallCurrentConsumed*1000,0); display.print(F("mAh"));
display.println();
//Row 3
display.print(F("Pow ")); display.print(watthoursConsumed,0); display.print(F(" / ")); display.print(overallWatthoursConsumed,0); display.print(F("Wh"));
display.println();
break;
case 2:
//Configuration parameters
//Row 1
display.print(F("cmdred min=")); display.print(minimum_constant_cmd_reduce); display.print(F("cmdred min=")); display.print(minimum_constant_cmd_reduce);
display.print(F(" p=")); display.print(brake_cmdreduce_proportional); display.print(F(" p=")); display.print(brake_cmdreduce_proportional);
display.println(); display.println();
//Row 2
display.print(F("brkI=")); display.print(F("brkI="));
dtostrf(startbrakecurrent,1,1,buf); dtostrf(startbrakecurrent,1,1,buf);
@ -254,120 +380,55 @@ void display_standingDisplay(ESCSerialComm& escFront, ESCSerialComm& escRear) {
display.print((String)buf); display.print((String)buf);
display.println(); display.println();
//Row 3
display.print(F("thrmax=")); display.print(throttle_max); display.print(F("thrmax=")); display.print(throttle_max);
display.print(F(" rev=")); display.print(F(" rev="));
dtostrf(reverse_speed,1,2,buf); dtostrf(reverse_speed,1,2,buf);
display.print((String)buf); display.print((String)buf);
display.println(); display.println();
}else{
if (_displayOverall) { //alternate between this trip and overall trip break;
_displaytrip=overallTrip;
//_displaycurrent=overallCurrentConsumed;
_displaywatthours=overallWatthoursConsumed;
}
display.print(F("Vbat:")); display.print(escFront.getFeedback_batVoltage());
display.print(F("/")); display.print(escRear.getFeedback_batVoltage());
display.print(" V");
display.println();
//display.print(F("Temp:")); display.print(escFront.getFeedback_boardTemp());
//display.print(F("/")); display.print(escRear.getFeedback_boardTemp());
display.print(F("T:")); display.print(temp_ESCFront,0);
display.print(F("/")); display.print(temp_ESCRear,0);
display.print(F("/")); display.print(temp_Air,0);
display.print(" C");
display.println();
display.print(F("Trip:"));
dtostrf(_displaytrip,1,0,buf);
display.print((String)buf);
display.print("m ");
//dtostrf(_displaycurrent,1,2,buf);
dtostrf(_displaywatthours,1,2,buf);
display.print((String)buf);
//display.print(" Ah");
display.print("Wh");
display.println();
display.print(F(""));
//dtostrf( _displaytrip/1000/_displaycurrent ,1,2,buf);
dtostrf( _displaywatthours/_displaytrip*100,1,2,buf);
display.print((String)buf);
//display.print(" km/Ah");
display.print(" kWh/100km");
if (_displayOverall){
display.print(" sum");
}
display.println();
} }
} //Put User Inputs in last row
void display_standingDisarmedDisplay(ESCSerialComm& escFront, ESCSerialComm& escRear) {
//Displayed stuff here when escs are powered off / disconnected
char buf[8];
display.setFont();
display.setCursor(0,0);
//Row1
if (getDatalogging()) {
display.print(getLogFilename());
}else{
display.print("LOG DISABLED");
}
display.print(F(" ")); display.print(loopmillis/1000);
display.print(F("s"));
display.println();
//Row2
display.print(F("ESC F="));
display.print(escFront.getControllerConnected());
display.print(F(" R="));
display.print(escRear.getControllerConnected());
display.println();
//Row3
display.print("throttle=");
dtostrf(ads_throttle_A_raw,1,0,buf);
display.print((String)buf);
display.print("/");
dtostrf(ads_throttle_B_raw,1,0,buf);
display.print((String)buf);
display.println();
//Row 4 //Row 4
display.setCursor(0,24);
display.print("brake="); if (button_start_state){
dtostrf(ads_brake_raw,1,0,buf); display.print("S");
display.print((String)buf); }else{
display.print(" ");
/*display.print(" c=");
dtostrf(ads_control_raw,1,0,buf);
display.print((String)buf); */
if (control_buttonA){
display.print(" A");
} }
if (control_buttonB){ if (control_buttonB){
display.print(" B"); display.print("B");
}else{
display.print(" ");
} }
if (button_start_state){ if (control_buttonA){
display.print(" S"); display.print("A");
}else{
display.print(" ");
} }
if (escFront.getControllerConnected()){
display.print("F");
}else{
display.print(" ");
}
if (escRear.getControllerConnected()){
display.print("R");
}else{
display.print(" ");
}
display.setCursor(SCREEN_WIDTH-6*3,24);
display.print(standingDisplayScreen);
display.print("/"); display.print(NUM_STANDINGDISPLAYSCREEN-1);
} }

View File

@ -92,7 +92,7 @@ void loggingLoop(unsigned long loopmillis,ESCSerialComm& escFront, ESCSerialComm
dataFile.print("rpm_FrontL,rpm_FrontR,rpm_RearL,rpm_RearR,"); dataFile.print("rpm_FrontL,rpm_FrontR,rpm_RearL,rpm_RearR,");
dataFile.print("temp_ESCFront,temp_ESCRear,vbat_Front,vbat_Rear,"); dataFile.print("temp_ESCFront,temp_ESCRear,vbat_Front,vbat_Rear,");
dataFile.print("currentAll,throttle,brake,speed,trip_Front,trip_Rear,trip,currentConsumed_Front,currentConsumed_Rear,currentConsumed,watthoursConsumed,"); dataFile.print("currentAll,throttle,brake,speed,trip_Front,trip_Rear,trip,currentConsumed_Front,currentConsumed_Rear,currentConsumed,watthoursConsumed,");
dataFile.println("temp_Front,temp_Rear,temp_Air,looptime_duration"); dataFile.println("temp_Front,temp_Rear,temp_Air,looptime_duration_min,looptime_duration_max");
dataFile.print("#TIMESTAMP:"); dataFile.println(now()); dataFile.print("#TIMESTAMP:"); dataFile.println(now());
logging_headerWritten=true; logging_headerWritten=true;
} }

View File

@ -4,6 +4,8 @@
#include <OneWire.h> #include <OneWire.h>
#include <DallasTemperature.h> #include <DallasTemperature.h>
//#define SEARCH_DEVICES
DeviceAddress thermometerESCFront={0x28,0xFF,0x64,0x0E,0x77,0xB0,0xAB,0x4B}; //IC with one marking 28FF640E77B0AB4B DeviceAddress thermometerESCFront={0x28,0xFF,0x64,0x0E,0x77,0xB0,0xAB,0x4B}; //IC with one marking 28FF640E77B0AB4B
float temp_ESCFront; float temp_ESCFront;
@ -29,20 +31,15 @@ void printAddress(DeviceAddress deviceAddress);
void initTemperature() { void initTemperature() {
sensors.begin(); sensors.begin();
delay(1000);
//Just search for devices. Only needed when connecting a new sensor to find the address
#ifdef SEARCH_DEVICES
Serial.print("Locating 1Wire devices..."); Serial.print("Locating 1Wire devices...");
Serial.print("Found "); Serial.print("Found ");
Serial.print(sensors.getDeviceCount(), DEC); Serial.print(sensors.getDeviceCount(), DEC);
Serial.println(" devices."); Serial.println(" devices.");
delay(1000);
delay(1000);
//Just search for devices. Only needed when connecting a new sensor to find the address
oneWire.reset_search(); oneWire.reset_search();
for (uint8_t i=0;i<sensors.getDeviceCount();i++){ for (uint8_t i=0;i<sensors.getDeviceCount();i++){
@ -58,8 +55,9 @@ void initTemperature() {
} }
delay(1000); delay(1000);
#endif
//sensors.setResolution(thermometerReservoir, TEMPERATURE_PRECISION); //sensors.setResolution(thermometerESCFront, TEMPERATURE_PRECISION);
} }

View File

@ -100,7 +100,6 @@ void setup()
initResult=display_init(); initResult=display_init();
led_simpeProgress(1,initResult); led_simpeProgress(1,initResult);
initResult=initLogging(); initResult=initLogging();
@ -129,7 +128,6 @@ void setup()
// also set ADSREADPERIOD to at least the read interval // also set ADSREADPERIOD to at least the read interval
ADS.requestADC(0); //Start requesting a channel ADS.requestADC(0); //Start requesting a channel
led_simpeProgress(6,true); led_simpeProgress(6,true);
writeLogComment((unsigned long)millis(), "ADS1115 Initialized");
} }
delay(10); delay(10);
for (uint8_t i=0;i<4;i++){ //read all channels once to have adc readings ready in first loop (to prevent premature failsafe) for (uint8_t i=0;i<4;i++){ //read all channels once to have adc readings ready in first loop (to prevent premature failsafe)
@ -141,6 +139,8 @@ void setup()
setSyncProvider(getTeensy3Time); //See https://www.pjrc.com/teensy/td_libs_Time.html#teensy3 setSyncProvider(getTeensy3Time); //See https://www.pjrc.com/teensy/td_libs_Time.html#teensy3
if (timeStatus()!= timeSet) { if (timeStatus()!= timeSet) {
Serial.println("Unable to sync with the RTC"); Serial.println("Unable to sync with the RTC");
writeLogComment((unsigned long)millis(), "Unable to sync with the RTC");
led_simpeProgress(7,false); led_simpeProgress(7,false);
} else { } else {
Serial.println("RTC has set the system time"); Serial.println("RTC has set the system time");
@ -651,10 +651,22 @@ void readADSButtons() {
if (control_buttonA && !last_control_buttonA) { //button A was just pressed if (control_buttonA && !last_control_buttonA) { //button A was just pressed
writeLogComment(loopmillis, "Button A Pressed"); writeLogComment(loopmillis, "Button A Pressed");
if (!armed) { //standing disarmed display is showing
if (standingDisplayScreen<NUM_STANDINGDISPLAYSCREEN-1){
standingDisplayScreen++;
}
}
} }
if (control_buttonB && !last_control_buttonB) { //button B was just pressed if (control_buttonB && !last_control_buttonB) { //button B was just pressed
writeLogComment(loopmillis, "Button B Pressed"); writeLogComment(loopmillis, "Button B Pressed");
if (!armed) { //standing disarmed display is showing
if (standingDisplayScreen>0){
standingDisplayScreen--;
}
}
} }
} }