oled stuff

This commit is contained in:
Wolfgang Hottgenroth 2020-11-19 20:03:37 +01:00
parent 5605a3d1d5
commit 33fcf6c080
No known key found for this signature in database
GPG Key ID: 656C88C7C1734267
6 changed files with 61 additions and 3 deletions

View File

@ -83,7 +83,7 @@ void MX_SPI3_Init(void)
hspi3.Init.CLKPolarity = SPI_POLARITY_HIGH; hspi3.Init.CLKPolarity = SPI_POLARITY_HIGH;
hspi3.Init.CLKPhase = SPI_PHASE_2EDGE; hspi3.Init.CLKPhase = SPI_PHASE_2EDGE;
hspi3.Init.NSS = SPI_NSS_SOFT; hspi3.Init.NSS = SPI_NSS_SOFT;
hspi3.Init.BaudRatePrescaler = SPI_BAUDRATEPRESCALER_16; hspi3.Init.BaudRatePrescaler = SPI_BAUDRATEPRESCALER_2;
hspi3.Init.FirstBit = SPI_FIRSTBIT_MSB; hspi3.Init.FirstBit = SPI_FIRSTBIT_MSB;
hspi3.Init.TIMode = SPI_TIMODE_DISABLE; hspi3.Init.TIMode = SPI_TIMODE_DISABLE;
hspi3.Init.CRCCalculation = SPI_CRCCALCULATION_DISABLE; hspi3.Init.CRCCalculation = SPI_CRCCALCULATION_DISABLE;

View File

@ -33,5 +33,8 @@ void oled_PrintEdge(void);
void oled_Cursor(unsigned char cursor_column, unsigned char cursor_row); void oled_Cursor(unsigned char cursor_column, unsigned char cursor_row);
void oled_PrintLine(void); void oled_PrintLine(void);
void oledClear();
void oledPrint(char msg[]);
#endif /* OLED_H_ */ #endif /* OLED_H_ */

View File

@ -39,20 +39,27 @@ void my_setup_2() {
logMsg("Application starting"); logMsg("Application starting");
oledInit(); oledInit();
oled_P8x16Str(0, 0, "App starting"); oledClear();
oledPrint("App starting");
eepromInit(); eepromInit();
oledPrint("eeprom init");
wizInit(); wizInit();
oledPrint("network init");
mqttCommInit(); mqttCommInit();
oledPrint("mqtt init");
cmdHandlerInit(); cmdHandlerInit();
oledPrint("cmdhandler init");
frontendInit(); frontendInit();
frontendSetThreshold(240); frontendSetThreshold(240);
oledPrint("frontend init");
mbusCommInit(); mbusCommInit();
oledPrint("Meterbus init");
oledPrint("App running");
} }
void my_loop() { void my_loop() {

View File

@ -15,6 +15,7 @@
#include <wizHelper.h> #include <wizHelper.h>
#include <mbusParserExt.h> #include <mbusParserExt.h>
#include <mqttComm.h> #include <mqttComm.h>
#include <oled.h>
#include <mbus/mbus-protocol.h> #include <mbus/mbus-protocol.h>
@ -116,6 +117,7 @@ static void printError(t_mbusCommHandle *localMbusCommHandle) {
mqttPublishf(MBUS_TOPIC, "{\"Status\":\"Error\", \"RequestId\":\"%d\", \"Device\":\"%s\", \"Errors\":\"%d\", \"Requests\":\"%d\", \"ErrorRatio\":\"%.2f\"}", mqttPublishf(MBUS_TOPIC, "{\"Status\":\"Error\", \"RequestId\":\"%d\", \"Device\":\"%s\", \"Errors\":\"%d\", \"Requests\":\"%d\", \"ErrorRatio\":\"%.2f\"}",
localMbusCommHandle->requestId, localMbusCommHandle->device->deviceName, localMbusCommHandle->requestId, localMbusCommHandle->device->deviceName,
localMbusCommHandle->device->failures, localMbusCommHandle->device->requests, errorRatio); localMbusCommHandle->device->failures, localMbusCommHandle->device->requests, errorRatio);
oledPrint("Error");
} }
@ -235,6 +237,7 @@ static void parseAndPrintFrame(t_mbusCommHandle *localMbusCommHandle) {
localMbusCommHandle->device->failures, localMbusCommHandle->device->requests, errorRatio, localMbusCommHandle->device->failures, localMbusCommHandle->device->requests, errorRatio,
keys[0], values[0], keys[1], values[1], keys[2], values[2], keys[3], values[3]); keys[0], values[0], keys[1], values[1], keys[2], values[2], keys[3], values[3]);
} }
oledPrint("Ok");
mbus_data_record_free(data_var->record); mbus_data_record_free(data_var->record);
} else { } else {
coloredMsg(LOG_RED, true, "mbc papf [%d] err: unable to parse frame", localMbusCommHandle->requestId); coloredMsg(LOG_RED, true, "mbc papf [%d] err: unable to parse frame", localMbusCommHandle->requestId);
@ -520,6 +523,7 @@ static e_mbusCommRequestResult mbusCommRequest(t_mbusDevice *mbusDevice) {
mbusCommStats.requestCnt, mbusCommStats.requestCnt,
mbusCommStats.errorCnt); mbusCommStats.errorCnt);
oledPrint(mbusDevice->deviceName);
schAdd(handleRequestEngine, (void*) &mbusCommHandle, 0, 0); schAdd(handleRequestEngine, (void*) &mbusCommHandle, 0, 0);
res = MBCRR_TRIGGERED; res = MBCRR_TRIGGERED;

View File

@ -7,10 +7,14 @@
#include <main.h> #include <main.h>
#include <spi.h> #include <spi.h>
#include <stdint.h>
#include <string.h>
#include <oled.h> #include <oled.h>
#include <oled-fonts.h> #include <oled-fonts.h>
#include <stm32f1xx_hal.h> #include <stm32f1xx_hal.h>
#include <logger.h>
#define HIGH GPIO_PIN_SET #define HIGH GPIO_PIN_SET
@ -296,6 +300,8 @@ void oled_P6x8Char(unsigned char x,unsigned char y,unsigned char ch)
void oled_P6x8Str(unsigned char x,unsigned char y,char ch[]) void oled_P6x8Str(unsigned char x,unsigned char y,char ch[])
{ {
coloredMsg(LOG_BLUE, false, "OLED: %d %d %s", x, y, ch);
unsigned char c=0,i=0,j=0; unsigned char c=0,i=0,j=0;
while (ch[j]!='\0') while (ch[j]!='\0')
{ {
@ -524,3 +530,35 @@ void loop()
oled_P8x16Str(20,4,"Prototyping"); oled_P8x16Str(20,4,"Prototyping");
} }
#endif #endif
#define MAX_LINES 8
#define MAX_CHARS 21
static uint8_t currentLine = 0;
static char lines[MAX_LINES+1][MAX_CHARS+1];
void oledClear() {
oled_CLS();
memset(lines, 0, sizeof(lines));
currentLine = 0;
}
void oledPrint(char msg[]) {
if (currentLine < MAX_LINES) {
memset(lines[currentLine], 0, MAX_CHARS);
strncpy(lines[currentLine], msg, MAX_CHARS);
oled_P6x8Str(1, currentLine, lines[currentLine]);
currentLine++;
} else {
for (uint8_t i = 1; i < MAX_LINES; i++) {
memcpy(lines[i-1], lines[i], MAX_CHARS);
oled_P6x8Str(1, i-1, lines[i-1]);
}
strncpy(lines[MAX_LINES - 1], msg, MAX_CHARS);
memset(lines[MAX_LINES - 1] + strlen(msg), ' ', MAX_CHARS - strlen(msg) - 1);
lines[MAX_LINES - 1][MAX_CHARS - 1] = 0;
oled_P6x8Str(1, MAX_LINES - 1, lines[MAX_LINES - 1]);
}
}

View File

@ -10,6 +10,7 @@
#include <string.h> #include <string.h>
#include <dhcp.h> #include <dhcp.h>
#include <show.h> #include <show.h>
#include <oled.h>
wiz_NetInfo netInfo = { wiz_NetInfo netInfo = {
.mac = { 0x00, 0xA0, 0x57, 0x05, 0x3E, 0x0D }, .mac = { 0x00, 0xA0, 0x57, 0x05, 0x3E, 0x0D },
@ -75,6 +76,8 @@ static void wizDHCPAssign() {
networkAvailable = true; networkAvailable = true;
show(LED_GREEN, ON); show(LED_GREEN, ON);
coloredMsg(LOG_BLUE, false, "wizda, network is available"); coloredMsg(LOG_BLUE, false, "wizda, network is available");
oledPrint("Address available");
} }
static void wizDHCPUpdate() { static void wizDHCPUpdate() {
@ -114,6 +117,7 @@ static void wizPhyLinkHandler(void *handle) {
lastStablePhyLink = phyLink; lastStablePhyLink = phyLink;
if (phyLink == PHY_LINK_ON) { if (phyLink == PHY_LINK_ON) {
oledPrint("Link available");
// start DHCP handler // start DHCP handler
memset(dhcpBuffer, 0, DHCP_BUFFER_SIZE); memset(dhcpBuffer, 0, DHCP_BUFFER_SIZE);
reg_dhcp_cbfunc(wizDHCPAssign, wizDHCPUpdate, NULL); reg_dhcp_cbfunc(wizDHCPAssign, wizDHCPUpdate, NULL);
@ -126,6 +130,8 @@ static void wizPhyLinkHandler(void *handle) {
dhcpInitialized = true; dhcpInitialized = true;
} else { } else {
oledPrint("Link lost");
networkAvailable = false; networkAvailable = false;
show(LED_GREEN, BLINK); show(LED_GREEN, BLINK);
coloredMsg(LOG_BLUE, false, "wizplh, network is unavailable"); coloredMsg(LOG_BLUE, false, "wizplh, network is unavailable");