Created
November 13, 2019 21:13
-
-
Save v-ivanyshyn/34e8c4a7466c1bf2bcac47dff4cad83f to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <ILI9341_t3.h> // https://github.com/PaulStoffregen/ILI9341_t3 | |
struct CanData { | |
uint32_t id; | |
uint8_t len; | |
uint8_t data[8] __attribute__((aligned(8))); | |
}; | |
int CAN_IDS[] = { | |
0x050, | |
0x0AE, | |
0x0C2, | |
0x0D0, | |
//... | |
} | |
#define CAN_IDS_SIZE (sizeof(CAN_IDS)/sizeof(CAN_IDS[0])) | |
CanData canData[CAN_IDS_SIZE] = {0}; | |
void init() { | |
for (int i = 0; i < CAN_IDS_SIZE; i++) { | |
int y = i * 10; | |
// initial step, display ids: | |
lcdDisplay.setTextSize(1); | |
lcdDisplay.setCursor(0, y); | |
lcdDisplay.print(canData[i].id, HEX); | |
} | |
} | |
void loop() { | |
static __uint8_t canDataCache[CAN_IDS_SIZE][8] = {0}; | |
// read available CAN messages into canData[] array... | |
// display data lines: | |
for (int i = 0; i < CAN_IDS_SIZE; i++) { | |
int y = i * 10; | |
const __uint8_t *data = canData[i].data; | |
if (memcmp(canDataCache[i], data, 8) == 0) | |
continue; | |
for (int d = 0; d < 8; d++) { | |
if (canDataCache[i][d] == data[d]) | |
continue; | |
int dw = data[d] / 2; // line width, range: 0...128 | |
lcdDisplay.drawFastHLine(20, y + d, dw, ILI9341_GREEN); | |
lcdDisplay.drawFastHLine(20 + dw, y + d, 128 - dw, ILI9341_BLACK); | |
} | |
memcpy(canDataCache[i], data, 8); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment