Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Throwing out the welcome mat #9

Merged
merged 13 commits into from
Nov 18, 2023
79 changes: 2 additions & 77 deletions include/HUDL/HUDL.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -70,87 +70,14 @@ class HUDL {
static constexpr uintptr_t MC_NODE_ID = 0x01;

private:
enum CurrentPage {
PAGE_1,
ERROR_PAGE
};

enum Corner {
TOP_LEFT,
TOP_RIGHT,
BOTTOM_LEFT,
BOTTOM_RIGHT
};

CurrentPage currentHUDLScreen = PAGE_1;
bool setHeaders = false;
char* errorString;

unsigned char evtBitMap[1024] = {
0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xF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FF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF};

uint16_t dummyValue = 0;

Expand All @@ -164,13 +91,11 @@ class HUDL {
/** The torque actual value provided by the MC node over CAN. Found in the first 16 bits of the 4th PDO coming from the MC. */
uint16_t torqueActual = 0;

uint16_t actualPosition = 0;
int16_t actualPosition = 0;

static uint8_t columnForCorner(Corner corner);
static uint8_t pageForCorner(Corner corner);
static uint8_t wrapForCorner(HUDL::Corner corner);

void writeError(const char* text);
void headerForCorner(Corner corner, const char* text);
void dataForCorner(Corner corner, const char* text);

Expand Down Expand Up @@ -274,7 +199,7 @@ class HUDL {
.Data = (uintptr_t) 0xFE,
},
/**
* Motor Controller RPDO 1
* Motor Controller RPDO 1
* 0: RPDO number in index and total number of sub indexes.
* 1: The COB-ID to receive PDOs from.
* 2: transmission trigger
Expand Down
126 changes: 45 additions & 81 deletions src/HUDL/HUDL.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,6 @@ HUDL::HUDL(IO::GPIO& reg_select, IO::GPIO& reset, IO::SPI& spi) : lcd(DEV::LCD(r
void HUDL::initLCD() {
lcd.initLCD();
lcd.clearLCD();
lcd.setEntireScreenBitMap(evtBitMap);
EVT::core::time::wait(2000);
lcd.clearLCD();
// lcd.setDefaultSections(SECTION_TITLES);
// lcd.displaySectionHeaders();
}

CO_OBJ_T* HUDL::getObjectDictionary() {
Expand All @@ -41,62 +36,49 @@ uint16_t HUDL::getObjectDictionarySize() const {
}

void HUDL::updateLCD() {
switch (currentHUDLScreen) {
case PAGE_1: {// Set a new scope for this case
if (!setHeaders) {
lcd.clearLCD();
headerForCorner(TOP_LEFT, "Battery");
headerForCorner(TOP_RIGHT, "HI Temp");
headerForCorner(BOTTOM_LEFT, "RPM");
headerForCorner(BOTTOM_RIGHT, "MC Stat");
setHeaders = true;
}
if (!setHeaders) {
lcd.clearLCD();
headerForCorner(TOP_LEFT, "Bat %");
headerForCorner(TOP_RIGHT, "Temp");
headerForCorner(BOTTOM_LEFT, "RPM");
headerForCorner(BOTTOM_RIGHT, "MC Stat");
setHeaders = true;
}

// Set the battery voltage
char voltage[9];
std::sprintf(voltage, "%hu.%hu v", totalVoltage / 10, totalVoltage % 10);
dataForCorner(TOP_LEFT, voltage);

// Set the highest temp
uint16_t highestTemp = thermTemps[0];
for (uint16_t temp : thermTemps) {
if (temp > highestTemp) {
highestTemp = temp;
}
}
char temp[9];
std::sprintf(temp, "%hu.%hu C", thermTemps[0] / 100, thermTemps[0] % 100);

dataForCorner(TOP_RIGHT, temp);

// Set the rpm
char rpm[8];
std::sprintf(rpm, "%lu", actualPosition);
dataForCorner(BOTTOM_LEFT, rpm);

// Set the status word
char status[8];

if (statusWord == 0x21) {
std::sprintf(status, "STOP");
} else if (statusWord == 0x27) {
std::sprintf(status, "GO");
} else {
std::sprintf(status, "UNKNOWN");
// std::sprintf(errorString, "There was an error with the Motor Controller: Unknown Error %x", statusWord);
// currentHUDLScreen = ERROR_PAGE;
}
// Set the battery voltage
char voltage[9];
std::sprintf(voltage, "%hu.%hu v", totalVoltage / 10, totalVoltage % 10);
dataForCorner(TOP_LEFT, voltage);

dataForCorner(BOTTOM_RIGHT, status);
} break;
case ERROR_PAGE: {// Set a new scope for this page
if (!setHeaders) {
lcd.clearLCD();
// Set the highest temp
uint16_t highestTemp = thermTemps[0];
for (uint16_t temp : thermTemps) {
if (temp > highestTemp) {
highestTemp = temp;
}
writeError(errorString);
break;
}

char temp[9];
std::sprintf(temp, "%hu.%hu C", highestTemp / 10, highestTemp % 10);
dataForCorner(TOP_RIGHT, temp);

// Set the rpm
char rpm[8];
std::sprintf(rpm, "%d", actualPosition);
dataForCorner(BOTTOM_LEFT, rpm);

// Set the motor controller status word
char status[8];

if (statusWord == 0x21) {
std::sprintf(status, "STOP");
} else if (statusWord == 0x27) {
std::sprintf(status, "GO");
} else {
std::sprintf(status, "%x", statusWord);
}

dataForCorner(BOTTOM_RIGHT, status);
}

void HUDL::headerForCorner(HUDL::Corner corner, const char* text) {
Expand All @@ -113,7 +95,7 @@ void HUDL::headerForCorner(HUDL::Corner corner, const char* text) {
sectionColumn += padding;

// Write the text to the screen under the section header.
lcd.writeLargeText(text, sectionPage, sectionColumn, false);
lcd.writeText(text, sectionPage, sectionColumn, EVT::core::DEV::LCD::FontSize::LARGE, false);
mjmagee991 marked this conversation as resolved.
Show resolved Hide resolved
}

void HUDL::dataForCorner(HUDL::Corner corner, const char* text) {
Expand All @@ -130,19 +112,7 @@ void HUDL::dataForCorner(HUDL::Corner corner, const char* text) {
sectionColumn += padding;

// Write the text to the screen under the section header.
lcd.writeLargeText(text, sectionPage, sectionColumn, false);
}

void HUDL::writeError(const char* text) {
// Calculate the padding to center the text in the section
uint8_t length = strlen("!!! Error !!!") * 8;
uint8_t padding = (128 - length) / 2;

// Write the Error header
lcd.writeLargeText("!!! Error !!!", 0, padding, false);

// Write the error message
lcd.writeSmallText(text, 2, 0, true);
lcd.writeText(text, sectionPage, sectionColumn, EVT::core::DEV::LCD::FontSize::LARGE, false);
}

uint8_t HUDL::columnForCorner(HUDL::Corner corner) {
Expand All @@ -153,17 +123,8 @@ uint8_t HUDL::columnForCorner(HUDL::Corner corner) {
case TOP_RIGHT:
case BOTTOM_RIGHT:
return 64;
}
}

uint8_t HUDL::wrapForCorner(HUDL::Corner corner) {
switch (corner) {
case TOP_LEFT:
case BOTTOM_LEFT:
return 64;
case TOP_RIGHT:
case BOTTOM_RIGHT:
return 128;
default:
return -1;
}
}

Expand All @@ -175,6 +136,9 @@ uint8_t HUDL::pageForCorner(HUDL::Corner corner) {
case BOTTOM_LEFT:
case BOTTOM_RIGHT:
return 4;
default:
return -1;
}
}

}// namespace HUDL
Loading
Loading