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_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

View File

@ -15,6 +15,8 @@
#define SCREEN_ADDRESS 0x3C ///< See datasheet for Address; 0x3D for 128x64, 0x3C for 128x32
Adafruit_SSD1306 display(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, OLED_RESET);
uint8_t standingDisplayScreen=0;
#define NUM_STANDINGDISPLAYSCREEN 3
bool display_init();
@ -29,6 +31,7 @@ void display_debugDisplay(ESCSerialComm& escFront, ESCSerialComm& escRear);
bool display_init(){
if(!display.begin(SSD1306_SWITCHCAPVCC, SCREEN_ADDRESS)) {
Serial.println(F("SSD1306 allocation failed"));
writeLogComment((unsigned long)millis(), "SSD1306 allocation failed");
return false;
}
display.clearDisplay();
@ -81,17 +84,14 @@ void display_update(ESCSerialComm& escFront, ESCSerialComm& escRear){
display.print(errorstring);
}else{
//Normal Display Routinges here
//Normal Display Routines here
if (armed) {
if (loopmillis-last_notidle>5000) {
display_standingDisplay(escFront,escRear);
}else{
if (!control_buttonA) {
display_drivingDisplay(escFront,escRear);
}else{
display_debugDisplay(escFront,escRear);
}
//display_debugDisplay(escFront,escRear);
}
}else{
@ -108,6 +108,8 @@ void display_update(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
display.setFont(&FreeMonoBold18pt7b);
@ -115,6 +117,7 @@ void display_drivingDisplay(ESCSerialComm& escFront, ESCSerialComm& escRear) {
display.setTextColor(SSD1306_WHITE); // Draw white text
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=minSpeedms*3.6;
@ -152,15 +155,7 @@ void display_drivingDisplay(ESCSerialComm& escFront, ESCSerialComm& escRear) {
//## Trip / Current Consumed Display
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
//## Current
/*
dtostrf(min_filtered_currentAll,1,1,buf);
display.print("min:");
@ -171,20 +166,24 @@ void display_drivingDisplay(ESCSerialComm& escFront, ESCSerialComm& escRear) {
display.print((String)buf);
display.print("A");
*/
//## Watt Hours Consumed
//## Watt
dtostrf(min_filtered_wattAll,1,0,buf);
display.print("min:");
display.print((String)buf);
display.print("W max:");
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) {
//Debug
display.setTextSize(2); // Normal 1:1 pixel scale
@ -220,47 +219,25 @@ void display_debugDisplay(ESCSerialComm& escFront, ESCSerialComm& escRear) {
display.print(" thrpos=");
display.print(throttle_pos);
*/
}
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 _displaycurrent=currentConsumed;
double _displaywatthours=watthoursConsumed;
//bool _displayOverall= ((millis()/3000)%2==0); //switch based on time
bool _displayOverall=control_buttonB; //switch with button
bool _displayParameters=control_buttonA;
bool _displayOverall= ((millis()/2500)%2==0); //switch based on time
char buf[8];
display.setFont();
display.setCursor(0,0);
if (_displayParameters) {
display.print(F("cmdred min=")); display.print(minimum_constant_cmd_reduce);
display.print(F(" p=")); display.print(brake_cmdreduce_proportional);
display.println();
display.print(F("brkI="));
dtostrf(startbrakecurrent,1,1,buf);
display.print((String)buf);
display.print("A");
display.print(F(" free="));
dtostrf(freewheel_break_factor,1,1,buf);
display.print((String)buf);
display.println();
display.print(F("thrmax=")); display.print(throttle_max);
display.print(F(" rev="));
dtostrf(reverse_speed,1,2,buf);
display.print((String)buf);
display.println();
}else{
if (_displayOverall) { //alternate between this trip and overall trip
@ -269,11 +246,15 @@ void display_standingDisplay(ESCSerialComm& escFront, ESCSerialComm& escRear) {
_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);
@ -282,6 +263,7 @@ void display_standingDisplay(ESCSerialComm& escFront, ESCSerialComm& escRear) {
display.print(" C");
display.println();
//Row 3
display.print(F("Trip:"));
dtostrf(_displaytrip,1,0,buf);
display.print((String)buf);
@ -293,6 +275,8 @@ void display_standingDisplay(ESCSerialComm& escFront, ESCSerialComm& escRear) {
display.print("Wh");
display.println();
//Row 4
display.print(F(""));
//dtostrf( _displaytrip/1000/_displaycurrent ,1,2,buf);
dtostrf( _displaywatthours/_displaytrip*100,1,2,buf);
@ -307,19 +291,25 @@ void display_standingDisplay(ESCSerialComm& escFront, ESCSerialComm& escRear) {
display.println();
}
}
void display_standingDisarmedDisplay(ESCSerialComm& escFront, ESCSerialComm& escRear) {
//Displayed stuff here when escs are powered off / disconnected
//Displayed stuff here when escs are powered off / disconnected or bobbycar is not armed
char buf[8];
display.setFont();
display.setCursor(0,0);
//Row1
switch(standingDisplayScreen)
{
case 0:
//Quick overview of inputs and status
//Row1
if (getDatalogging()) {
display.print(getLogFilename());
}else{
@ -332,15 +322,7 @@ void display_standingDisarmedDisplay(ESCSerialComm& escFront, ESCSerialComm& esc
//Row2
display.print(F("ESC F="));
display.print(escFront.getControllerConnected());
display.print(F(" R="));
display.print(escRear.getControllerConnected());
display.println();
//Row3
display.print("throttle=");
display.print("Throttle ");
dtostrf(ads_throttle_A_raw,1,0,buf);
display.print((String)buf);
display.print("/");
@ -348,26 +330,105 @@ void display_standingDisarmedDisplay(ESCSerialComm& escFront, ESCSerialComm& esc
display.print((String)buf);
display.println();
//Row 4
//Row3
display.print("brake=");
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); */
if (control_buttonA){
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(" p=")); display.print(brake_cmdreduce_proportional);
display.println();
//Row 2
display.print(F("brkI="));
dtostrf(startbrakecurrent,1,1,buf);
display.print((String)buf);
display.print("A");
display.print(F(" free="));
dtostrf(freewheel_break_factor,1,1,buf);
display.print((String)buf);
display.println();
//Row 3
display.print(F("thrmax=")); display.print(throttle_max);
display.print(F(" rev="));
dtostrf(reverse_speed,1,2,buf);
display.print((String)buf);
display.println();
break;
}
//Put User Inputs in last row
//Row 4
display.setCursor(0,24);
if (button_start_state){
display.print("S");
}else{
display.print(" ");
}
if (control_buttonB){
display.print("B");
}else{
display.print(" ");
}
if (button_start_state){
display.print(" S");
if (control_buttonA){
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("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.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());
logging_headerWritten=true;
}

View File

@ -4,6 +4,8 @@
#include <OneWire.h>
#include <DallasTemperature.h>
//#define SEARCH_DEVICES
DeviceAddress thermometerESCFront={0x28,0xFF,0x64,0x0E,0x77,0xB0,0xAB,0x4B}; //IC with one marking 28FF640E77B0AB4B
float temp_ESCFront;
@ -29,20 +31,15 @@ void printAddress(DeviceAddress deviceAddress);
void initTemperature() {
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("Found ");
Serial.print(sensors.getDeviceCount(), DEC);
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();
for (uint8_t i=0;i<sensors.getDeviceCount();i++){
@ -58,8 +55,9 @@ void initTemperature() {
}
delay(1000);
#endif
//sensors.setResolution(thermometerReservoir, TEMPERATURE_PRECISION);
//sensors.setResolution(thermometerESCFront, TEMPERATURE_PRECISION);
}

View File

@ -102,7 +102,6 @@ void setup()
led_simpeProgress(1,initResult);
initResult=initLogging();
led_simpeProgress(2,(initResult ? (datalogging ? 1:2):0)); //0=sd card fail, 1=sd ok and logging, 2(warn)=sd ok and logging off
@ -129,7 +128,6 @@ void setup()
// also set ADSREADPERIOD to at least the read interval
ADS.requestADC(0); //Start requesting a channel
led_simpeProgress(6,true);
writeLogComment((unsigned long)millis(), "ADS1115 Initialized");
}
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)
@ -141,6 +139,8 @@ void setup()
setSyncProvider(getTeensy3Time); //See https://www.pjrc.com/teensy/td_libs_Time.html#teensy3
if (timeStatus()!= timeSet) {
Serial.println("Unable to sync with the RTC");
writeLogComment((unsigned long)millis(), "Unable to sync with the RTC");
led_simpeProgress(7,false);
} else {
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
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
writeLogComment(loopmillis, "Button B Pressed");
if (!armed) { //standing disarmed display is showing
if (standingDisplayScreen>0){
standingDisplayScreen--;
}
}
}
}