Commit 0d93e139 authored by Lucas Drezet's avatar Lucas Drezet
Browse files

new LCD display (change color, clear data, add logos/header/footer) and move 1 lcd function

parent ee04c57d
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
......@@ -32,7 +32,14 @@
#include "debug.h"
//Function declaration
void lcdPutChar(char_t c);
/**
* @brief Write a character to the LCD display
* @param[in] c Character to be written
**/
void lcdPutChar(char_t c) {
return;
}
//Variable declaration
static UART_HandleTypeDef UART_Handle;
......
......@@ -44,6 +44,9 @@
#include "resource_manager.h"
#include "smi_driver.h"
#include "debug.h"
#include "logoUGA.h"
#include "logoGEII.h"
#include "logoPolytech.h"
//LCD frame buffers
#define LCD_FRAME_BUFFER_LAYER0 0xC0400000
......@@ -91,37 +94,98 @@ void HAL_CAN_MspInit(CAN_HandleTypeDef *hcan);
/*============ Functions ============*/
/**
* @brief Set cursor location
* @param[in] line Line number
* @param[in] column Column number
* @brief Display a header
**/
void lcdSetCursor(uint_t line, uint_t column) {
lcdLine = MIN(line, 20);
lcdColumn = MIN(column, 50);
void headerLCD() {
BSP_LCD_SetTextColor(LCD_COLOR_POLYTECH);
BSP_LCD_FillRect(0, 0, OTM8009A_800X480_WIDTH, 26);
BSP_LCD_SetTextColor(LCD_COLOR_WHITE);
BSP_LCD_SetBackColor(LCD_COLOR_POLYTECH);
BSP_LCD_DisplayStringAt(0, 5, "Embedded HTTP (websocket) Server and CAN Sniffer", CENTER_MODE);
BSP_LCD_SetBackColor(LCD_COLOR_WHITE);
}
/**
* @brief Write a character to the LCD display
* @param[in] c Character to be written
* @brief Display a footer
**/
void lcdPutChar(char_t c) {
if (c == '\r') {
lcdColumn = 0;
} else if (c == '\n') {
lcdColumn = 0;
lcdLine++;
} else if (lcdLine < 20 && lcdColumn < 50) {
//Display current character
BSP_LCD_DisplayChar(lcdColumn * 16, lcdLine * 24, c);
//Advance the cursor position
if (++lcdColumn >= 50) {
lcdColumn = 0;
lcdLine++;
}
}
void footerLCD() {
BSP_LCD_SetTextColor(LCD_COLOR_POLYTECH);
BSP_LCD_FillRect(0, 410, OTM8009A_800X480_WIDTH, 75);
BSP_LCD_SetTextColor(LCD_COLOR_WHITE);
BSP_LCD_SetBackColor(LCD_COLOR_POLYTECH);
BSP_LCD_DisplayStringAt(15, 417, "Made by Polytech students: (2020-2021)", LEFT_MODE);
BSP_LCD_DisplayStringAt(0, 437, " - INFO4: Liam ANDRIEUX, Lucas DREZET & Roman REGOUIN", LEFT_MODE);
BSP_LCD_DisplayStringAt(0, 457, " - IESE3: Leo BARBET, Nicolas LYSEE & Yoan MOREAU", LEFT_MODE);
BSP_LCD_SetBackColor(LCD_COLOR_WHITE);
}
/**
* @brief Display UGA, IUT1 & Polytech Grenoble logos
**/
void logoLCD() {
BSP_LCD_DrawBitmap(525, 50, (uint8_t*) logoUGA);
BSP_LCD_DrawBitmap(525, 170, (uint8_t*) logoGEII);
BSP_LCD_DrawBitmap(445, 290, (uint8_t*) logoPolytech);
}
/**
* @brief Display IPv4 address
**/
void addrLCD() {
NetInterface *interface = &netInterface[0];
Ipv4Addr ipv4Addr;
char_t buffer[15];
char_t displayAddr[26] = "IPv4 Address: ";
ipv4GetHostAddr(interface, &ipv4Addr);
ipv4AddrToString(ipv4Addr, buffer);
BSP_LCD_SetTextColor(LCD_COLOR_UGA);
if (strcmp(buffer, "0.0.0.0"))
BSP_LCD_DisplayStringAt(15, 70, strcat(displayAddr, buffer), LEFT_MODE);
else
BSP_LCD_DisplayStringAt(15, 70, strcat(displayAddr, "CONNECTING...."), LEFT_MODE);
}
/**
* @brief Display last message received from CAN bus and sent to client
**/
void lastRecvLCD() {
char_t displayData[13];
BSP_LCD_SetTextColor(LCD_COLOR_WHITE);
BSP_LCD_FillRect(180, 190, 60, 60);
BSP_LCD_SetTextColor(LCD_COLOR_UGA);
BSP_LCD_DisplayStringAt(15, 170, "Last message received:", LEFT_MODE);
osSprintf(displayData, " - STDID: 0x%x", RxHeader.StdId);
BSP_LCD_DisplayStringAt(0, 190, displayData, LEFT_MODE);
osSprintf(displayData, " - BYTE0: 0x%x", RxData[0]);
BSP_LCD_DisplayStringAt(0, 210, displayData, LEFT_MODE);
osSprintf(displayData, " - BYTE1: 0x%x", RxData[1]);
BSP_LCD_DisplayStringAt(0, 230, displayData, LEFT_MODE);
}
/**
* @brief Display the last message received from client and sent to CAN bus
**/
void lastSentLCD() {
char_t displayData[13];
BSP_LCD_SetTextColor(LCD_COLOR_WHITE);
BSP_LCD_FillRect(180, 310, 60, 60);
BSP_LCD_SetTextColor(LCD_COLOR_UGA);
BSP_LCD_DisplayStringAt(15, 290, "Last message sent:", LEFT_MODE);
osSprintf(displayData, " - STDID: 0x%x", TxHeader.StdId);
BSP_LCD_DisplayStringAt(0, 310, displayData, LEFT_MODE);
osSprintf(displayData, " - BYTE0: 0x%x", TxData[0]);
BSP_LCD_DisplayStringAt(0, 330, displayData, LEFT_MODE);
osSprintf(displayData, " - BYTE1: 0x%x", TxData[1]);
BSP_LCD_DisplayStringAt(0, 350, displayData, LEFT_MODE);
}
/**
* @brief System clock configuration
**/
......@@ -357,14 +421,7 @@ error_t httpServerUriNotFoundCallback(HttpConnection *connection,
* @brief send data from CAN bus to client
**/
void sendData() {
lcdSetCursor(8, 0);
printf("Last CAN message received:\r\n");
lcdSetCursor(9, 4);
printf("STDID: %x\r\n", RxHeader.StdId);
lcdSetCursor(10, 4);
printf("BYTE0: %x\r\n", RxData[0]);
lcdSetCursor(11, 4);
printf("BYTE1: %x\r\n", RxData[1]);
lastRecvLCD();
char_t buffer[128];
//Format XML data
......@@ -423,15 +480,6 @@ void parseMessage(char_t *buffer, size_t size, WebSocket *ws) {
c = strtok(NULL, delim);
TxData[1] = (uint8_t) strtol(c, NULL, 10);
lcdSetCursor(14, 0);
printf("Last CAN message sent:\r\n");
lcdSetCursor(15, 4);
printf("STDID: %x\r\n", TxHeader.StdId);
lcdSetCursor(16, 4);
printf("BYTE0: %x\r\n", TxData[0]);
lcdSetCursor(17, 4);
printf("BYTE1: %x\r\n", TxData[1]);
//check if no messages are pending
if (HAL_CAN_IsTxMessagePending(&hcan1, Txmailbox) == 0) {
//send the message to the CAN bus
......@@ -439,6 +487,8 @@ void parseMessage(char_t *buffer, size_t size, WebSocket *ws) {
!= HAL_OK) {
//transmission Error
TRACE_ERROR("CAN transmission error!\r\n");
} else {
lastSentLCD();
}
}
}
......@@ -447,29 +497,13 @@ void parseMessage(char_t *buffer, size_t size, WebSocket *ws) {
/*============ Tasks ============*/
/**
* @brief User task
* @brief LCD task
* @param[in] param Unused parameter
**/
void userTask(void *param) {
char_t buffer[40];
Ipv4Addr ipv4Addr;
//Point to the network interface
NetInterface *interface = &netInterface[0];
//Initialize LCD display
lcdSetCursor(4, 0);
printf("IPv4 Address:\r\n");
void lcdTask(void *param) {
//Endless loop
while (1) {
lcdSetCursor(5, 0);
ipv4GetHostAddr(interface, &ipv4Addr);
ipv4AddrToString(ipv4Addr, buffer);
if (strcmp(buffer, "0.0.0.0"))
printf("%-16s\r\n", buffer);
else
printf("CONNECTING.....\r\n");
addrLCD();
//Loop delay
osDelayTask(10);
......@@ -477,7 +511,7 @@ void userTask(void *param) {
}
/**
* @brief CAN task
* @brief Message received from CAN bus and sent to client task
* @param[in] param Unused parameter
**/
void canTask(void *param) {
......@@ -501,11 +535,10 @@ void canTask(void *param) {
}
/**
* @brief Receive task from client
* @brief Message received from client and sent to CAN bus
* @param[in] param Unused parameter
**/
void recvTask(void *param) {
char_t buffer[128];
error_t error;
WebSocketFrameType *typeFrame = malloc(sizeof(WebSocketFrameType*));
size_t *sizeRead = malloc(sizeof(size_t*));
......@@ -514,6 +547,7 @@ void recvTask(void *param) {
for (int i = 0; i < WEB_SOCKET_MAX_COUNT; i++) {
WebSocket *ws = &webSocketTable[i];
if (ws->state == WS_STATE_OPEN) {
char_t buffer[128];
error = webSocketReceive(ws, buffer, 128, typeFrame, sizeRead);
if (error == ERROR_NOT_CONNECTED) //if (error == ERROR_CONNECTION_RESET)
webSocketClose(ws);
......@@ -580,18 +614,17 @@ int_t main(void) {
BSP_LCD_Init();
BSP_LCD_LayerDefaultInit(0, LCD_FRAME_BUFFER_LAYER0);
BSP_LCD_SelectLayer(0);
BSP_LCD_SetBackColor(LCD_COLOR_DARKGRAY);
BSP_LCD_SetTextColor(LCD_COLOR_WHITE);
BSP_LCD_SetFont(&Font24);
BSP_LCD_DisplayOn();
BSP_LCD_SetBrightness(100);
BSP_LCD_Clear(LCD_COLOR_WHITE);
BSP_LCD_SetFont(&Font20);
//Clear LCD display
BSP_LCD_Clear(LCD_COLOR_DARKGRAY);
//Welcome message
lcdSetCursor(0, 1);
printf("Embedded HTTP (websocket) Server and CAN Sniffer\r\n");
//Initialize display
headerLCD();
footerLCD();
logoLCD();
lastRecvLCD();
lastSentLCD();
//Initialize CAN
MX_GPIO_Init();
......@@ -687,12 +720,12 @@ int_t main(void) {
TRACE_ERROR("Failed to start HTTP server!\r\n");
}
//Create user task
task = osCreateTask("User", userTask, NULL, 500, OS_TASK_PRIORITY_NORMAL);
//Create lcd task
task = osCreateTask("LCD", lcdTask, NULL, 500, OS_TASK_PRIORITY_NORMAL);
//Failed to create the task?
if (task == OS_INVALID_HANDLE) {
//Debug message
TRACE_ERROR("Failed to create task!\r\n");
TRACE_ERROR("Failed to create lcdTask!\r\n");
}
//Create a task to communicate in CAN bus
......
......@@ -242,6 +242,14 @@
*/
#define LCD_COLOR_TRANSPARENT ((uint32_t) 0xFF000000)
/** @brief Polytech value in ARGB8888 format
*/
#define LCD_COLOR_POLYTECH ((uint32_t) 0xFF009DDE)
/** @brief UGA value in ARGB8888 format
*/
#define LCD_COLOR_UGA ((uint32_t) 0xFF2A2F47)
/**
* @brief LCD default font
*/
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment