show statistics on second screen
This commit is contained in:
parent
3807e2fa9f
commit
206e371d48
@ -15,26 +15,17 @@
|
||||
* Adapted from Arduino to STM32 HAL by wollud1969
|
||||
*/
|
||||
|
||||
|
||||
|
||||
typedef enum {
|
||||
OLED_SCREEN0 = 0,
|
||||
OLED_SCREEN1
|
||||
} oledScreen_t;
|
||||
|
||||
void oledInit(void);
|
||||
|
||||
/*
|
||||
* Will be used only internal
|
||||
void oled_CLS(void);
|
||||
void oled_Set_Pos(unsigned char x,unsigned char y);//Set the coordinate
|
||||
void oled_WrDat(unsigned char data); //Write Data
|
||||
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_P8x16Str(unsigned char x,unsigned char y,char ch[]);
|
||||
|
||||
void oled_PrintBMP(unsigned char x0,unsigned char y0,unsigned char x1,unsigned char y1,unsigned char bmp[]);
|
||||
void oled_Fill(unsigned char dat);
|
||||
void oled_PrintEdge(void);
|
||||
void oled_Cursor(unsigned char cursor_column, unsigned char cursor_row);
|
||||
void oled_PrintLine(void);
|
||||
*/
|
||||
|
||||
void oledClear();
|
||||
void oledPrint(char msg[]);
|
||||
void oledPrintf(const char *format, ...);
|
||||
void oledPrint(oledScreen_t screen, char msg[]);
|
||||
void oledPrintf(oledScreen_t screen, const char *format, ...);
|
||||
void oledSetActiveScreen(oledScreen_t screen);
|
||||
|
||||
#endif /* OLED_H_ */
|
||||
|
@ -2,9 +2,11 @@
|
||||
#define _WIZHELPER_H_
|
||||
|
||||
#include <stdbool.h>
|
||||
#include <stdint.h>
|
||||
|
||||
int wizInit();
|
||||
bool isNetworkAvailable();
|
||||
uint8_t* wizGetIPAddress();
|
||||
|
||||
|
||||
#endif // _WIZHELPER_H_
|
@ -11,7 +11,7 @@ void loopEnable() {
|
||||
HAL_GPIO_WritePin(Loop_Enable_GPIO_Port, Loop_Enable_Pin, GPIO_PIN_SET);
|
||||
HAL_GPIO_WritePin(Loop_Enable_GPIO_Port, Loop_Enable_Pin, GPIO_PIN_RESET);
|
||||
coloredMsg(LOG_HIGH, true, "lc le loop is enabled");
|
||||
oledPrint("loop enabled");
|
||||
oledPrint(OLED_SCREEN0, "loop enabled");
|
||||
}
|
||||
|
||||
void loopDisable() {
|
||||
@ -19,7 +19,7 @@ void loopDisable() {
|
||||
HAL_GPIO_WritePin(Loop_Disable_GPIO_Port, Loop_Disable_Pin, GPIO_PIN_RESET);
|
||||
loopActive = false;
|
||||
coloredMsg(LOG_HIGH, true, "lc ld loop is disabled");
|
||||
oledPrint("loop disabled");
|
||||
oledPrint(OLED_SCREEN0, "loop disabled");
|
||||
}
|
||||
|
||||
void loopStatusCallback() {
|
||||
|
@ -40,26 +40,27 @@ void my_setup_2() {
|
||||
|
||||
oledInit();
|
||||
oledClear();
|
||||
oledPrint("App starting");
|
||||
oledSetActiveScreen(OLED_SCREEN0);
|
||||
oledPrint(OLED_SCREEN0, "App starting");
|
||||
|
||||
eepromInit();
|
||||
oledPrint("eeprom init");
|
||||
oledPrint(OLED_SCREEN0, "eeprom init");
|
||||
|
||||
wizInit();
|
||||
oledPrint("network init");
|
||||
oledPrint(OLED_SCREEN0, "network init");
|
||||
|
||||
mqttCommInit();
|
||||
oledPrint("mqtt init");
|
||||
oledPrint(OLED_SCREEN0, "mqtt init");
|
||||
cmdHandlerInit();
|
||||
oledPrint("cmdhandler init");
|
||||
oledPrint(OLED_SCREEN0, "cmdhandler init");
|
||||
|
||||
frontendInit();
|
||||
frontendSetThreshold(240);
|
||||
oledPrint("frontend init");
|
||||
oledPrint(OLED_SCREEN0, "frontend init");
|
||||
|
||||
mbusCommInit();
|
||||
oledPrint("Meterbus init");
|
||||
oledPrint("App running");
|
||||
oledPrint(OLED_SCREEN0, "Meterbus init");
|
||||
oledPrint(OLED_SCREEN0, "App running");
|
||||
}
|
||||
|
||||
void my_loop() {
|
||||
|
@ -116,7 +116,7 @@ static void printError(t_mbusCommHandle *localMbusCommHandle) {
|
||||
mqttPublishf(MBUS_TOPIC, "{\"Status\":\"Error\", \"RequestId\":\"%d\", \"Device\":\"%s\", \"Errors\":\"%d\", \"Requests\":\"%d\", \"ErrorRatio\":\"%.2f\"}",
|
||||
localMbusCommHandle->requestId, localMbusCommHandle->device->deviceName,
|
||||
localMbusCommHandle->device->failures, localMbusCommHandle->device->requests, errorRatio);
|
||||
oledPrintf("Err:%d/%d", localMbusCommHandle->device->failures, localMbusCommHandle->device->requests);
|
||||
oledPrintf(OLED_SCREEN0, "Err:%d/%d", localMbusCommHandle->device->failures, localMbusCommHandle->device->requests);
|
||||
}
|
||||
|
||||
|
||||
@ -236,7 +236,7 @@ static void parseAndPrintFrame(t_mbusCommHandle *localMbusCommHandle) {
|
||||
localMbusCommHandle->device->failures, localMbusCommHandle->device->requests, errorRatio,
|
||||
keys[0], values[0], keys[1], values[1], keys[2], values[2], keys[3], values[3]);
|
||||
}
|
||||
oledPrintf("Ok:%d/%d", localMbusCommHandle->device->failures, localMbusCommHandle->device->requests);
|
||||
oledPrintf(OLED_SCREEN0, "Ok:%d/%d", localMbusCommHandle->device->failures, localMbusCommHandle->device->requests);
|
||||
mbus_data_record_free(data_var->record);
|
||||
} else {
|
||||
coloredMsg(LOG_RED, true, "mbc papf [%d] err: unable to parse frame", localMbusCommHandle->requestId);
|
||||
@ -522,7 +522,7 @@ static e_mbusCommRequestResult mbusCommRequest(t_mbusDevice *mbusDevice) {
|
||||
mbusCommStats.requestCnt,
|
||||
mbusCommStats.errorCnt);
|
||||
|
||||
oledPrint(mbusDevice->deviceName);
|
||||
oledPrint(OLED_SCREEN0, mbusDevice->deviceName);
|
||||
schAdd(handleRequestEngine, (void*) &mbusCommHandle, 0, 0);
|
||||
res = MBCRR_TRIGGERED;
|
||||
|
||||
|
@ -7,6 +7,7 @@
|
||||
#include <PontCoopScheduler.h>
|
||||
#include <wizHelper.h>
|
||||
#include <mbusComm.h>
|
||||
#include <oled.h>
|
||||
|
||||
#include <stdint.h>
|
||||
#include <stdlib.h>
|
||||
@ -53,11 +54,20 @@ static void mqttStatusPublisher(void *handle) {
|
||||
coloredMsg(LOG_GREEN, false, "mqsp: publishing status");
|
||||
t_mbusCommStats *mbusCommStats = mbusCommGetStats();
|
||||
char buf[64];
|
||||
uint32_t uptime = HAL_GetTick() / 1000;
|
||||
snprintf(buf, 128, "{\"uptime\":\"%ld\", \"tasks\":\"%d\", \"requests\":\"%ld\", \"errors\":\"%ld\"}",
|
||||
HAL_GetTick()/1000, schTaskCnt(), mbusCommStats->requestCnt, mbusCommStats->errorCnt);
|
||||
uptime, schTaskCnt(), mbusCommStats->requestCnt, mbusCommStats->errorCnt);
|
||||
bool res = publish(&mqttClient, StatusTopic, (const uint8_t*)buf, strlen(buf), false);
|
||||
coloredMsg(LOG_GREEN, false, "mqch, publish returned %d", res);
|
||||
|
||||
oledClear();
|
||||
oledSetActiveScreen(OLED_SCREEN1);
|
||||
uint8_t *addr = wizGetIPAddress();
|
||||
oledPrintf(OLED_SCREEN1, "Addr:%d.%d.%d.%d", addr[0], addr[1], addr[2], addr[3]);
|
||||
oledPrintf(OLED_SCREEN1, "Network available:%d", isNetworkAvailable());
|
||||
oledPrintf(OLED_SCREEN1, "Uptime:%ld", uptime);
|
||||
oledPrintf(OLED_SCREEN1, "Req:%ld", mbusCommStats->requestCnt);
|
||||
oledPrintf(OLED_SCREEN1, "Err:%ld", mbusCommStats->errorCnt);
|
||||
}
|
||||
|
||||
void mqttCommHandler(void *handle) {
|
||||
|
@ -17,13 +17,12 @@
|
||||
#include <stm32f1xx_hal.h>
|
||||
|
||||
#include <logger.h>
|
||||
#include <PontCoopScheduler.h>
|
||||
|
||||
|
||||
#define HIGH GPIO_PIN_SET
|
||||
#define LOW GPIO_PIN_RESET
|
||||
|
||||
|
||||
|
||||
static void __LEDPIN_RST(GPIO_PinState v) {
|
||||
HAL_GPIO_WritePin(Display_RES_GPIO_Port, Display_RES_Pin, v);
|
||||
}
|
||||
@ -312,7 +311,7 @@ static void oled_P6x8Char(unsigned char x,unsigned char y,unsigned char ch)
|
||||
|
||||
static void oled_P6x8Str(unsigned char x,unsigned char y,char ch[])
|
||||
{
|
||||
coloredMsg(LOG_BLUE, false, "OLED: %d %d %s", x, y, ch);
|
||||
// coloredMsg(LOG_BLUE, false, "OLED: %d %d %s", x, y, ch);
|
||||
|
||||
unsigned char c=0,i=0,j=0;
|
||||
while (ch[j]!='\0')
|
||||
@ -401,9 +400,11 @@ static void oled_Cursor(unsigned char cursor_column, unsigned char cursor_row)
|
||||
|
||||
#define MAX_LINES 8
|
||||
#define MAX_CHARS 21
|
||||
#define NUM_OF_SCREENS 2
|
||||
|
||||
static uint8_t currentLine = 0;
|
||||
static char lines[MAX_LINES+1][MAX_CHARS+1];
|
||||
static char lines[NUM_OF_SCREENS][MAX_LINES+1][MAX_CHARS+1];
|
||||
static oledScreen_t activeScreen = OLED_SCREEN0;
|
||||
|
||||
void oledClear() {
|
||||
oled_CLS();
|
||||
@ -411,32 +412,42 @@ void oledClear() {
|
||||
currentLine = 0;
|
||||
}
|
||||
|
||||
void oledPrint(char msg[]) {
|
||||
void oledPrint(oledScreen_t screen, char msg[]) {
|
||||
if (currentLine < MAX_LINES) {
|
||||
memset(lines[currentLine], 0, MAX_CHARS);
|
||||
strncpy(lines[currentLine], msg, MAX_CHARS);
|
||||
memset(lines[currentLine] + strlen(msg), ' ', MAX_CHARS - strlen(msg) - 1);
|
||||
lines[currentLine][MAX_CHARS - 1] = 0;
|
||||
oled_P6x8Str(1, currentLine, lines[currentLine]);
|
||||
strncpy(lines[screen][currentLine], msg, MAX_CHARS);
|
||||
memset(lines[screen][currentLine] + strlen(msg), ' ', MAX_CHARS - strlen(msg) - 1);
|
||||
lines[screen][currentLine][MAX_CHARS - 1] = 0;
|
||||
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]);
|
||||
memcpy(lines[screen][i-1], lines[screen][i], MAX_CHARS);
|
||||
}
|
||||
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]);
|
||||
strncpy(lines[screen][MAX_LINES - 1], msg, MAX_CHARS);
|
||||
memset(lines[screen][MAX_LINES - 1] + strlen(msg), ' ', MAX_CHARS - strlen(msg) - 1);
|
||||
lines[screen][MAX_LINES - 1][MAX_CHARS - 1] = 0;
|
||||
}
|
||||
|
||||
for (uint8_t line = 0; line < MAX_LINES; line++) {
|
||||
oled_P6x8Str(1, line, lines[activeScreen][line]);
|
||||
}
|
||||
}
|
||||
|
||||
static void oledSwitchBackToScreen0(void *handle) {
|
||||
oledSetActiveScreen(OLED_SCREEN0);
|
||||
}
|
||||
|
||||
void oledPrintf(const char *format, ...) {
|
||||
void oledSetActiveScreen(oledScreen_t screen) {
|
||||
activeScreen = screen;
|
||||
if (screen == OLED_SCREEN1) {
|
||||
schAdd(oledSwitchBackToScreen0, NULL, 10000, 0);
|
||||
}
|
||||
}
|
||||
|
||||
void oledPrintf(oledScreen_t screen, const char *format, ...) {
|
||||
va_list vl;
|
||||
va_start(vl, format);
|
||||
char buf[MAX_CHARS+1];
|
||||
vsnprintf(buf, MAX_CHARS, format, vl);
|
||||
va_end(vl);
|
||||
oledPrint(buf);
|
||||
oledPrint(screen, buf);
|
||||
}
|
||||
|
@ -28,6 +28,9 @@ bool isNetworkAvailable() {
|
||||
return networkAvailable;
|
||||
}
|
||||
|
||||
uint8_t* wizGetIPAddress() {
|
||||
return netInfo.ip;
|
||||
}
|
||||
static void wiz_cs_select(void) {
|
||||
HAL_GPIO_WritePin(ETHER_CS_GPIO_Port, ETHER_CS_Pin, GPIO_PIN_RESET);
|
||||
}
|
||||
@ -77,7 +80,7 @@ static void wizDHCPAssign() {
|
||||
show(LED_GREEN, ON);
|
||||
coloredMsg(LOG_BLUE, false, "wizda, network is available");
|
||||
|
||||
oledPrintf("Addr:%d.%d.%d.%d", netInfo.ip[0], netInfo.ip[1], netInfo.ip[2], netInfo.ip[3]);
|
||||
oledPrintf(OLED_SCREEN0, "Addr:%d.%d.%d.%d", netInfo.ip[0], netInfo.ip[1], netInfo.ip[2], netInfo.ip[3]);
|
||||
}
|
||||
|
||||
static void wizDHCPUpdate() {
|
||||
@ -117,7 +120,7 @@ static void wizPhyLinkHandler(void *handle) {
|
||||
lastStablePhyLink = phyLink;
|
||||
|
||||
if (phyLink == PHY_LINK_ON) {
|
||||
oledPrint("Link available");
|
||||
oledPrint(OLED_SCREEN0, "Link available");
|
||||
// start DHCP handler
|
||||
memset(dhcpBuffer, 0, DHCP_BUFFER_SIZE);
|
||||
reg_dhcp_cbfunc(wizDHCPAssign, wizDHCPUpdate, NULL);
|
||||
@ -130,7 +133,7 @@ static void wizPhyLinkHandler(void *handle) {
|
||||
|
||||
dhcpInitialized = true;
|
||||
} else {
|
||||
oledPrint("Link lost");
|
||||
oledPrint(OLED_SCREEN0, "Link lost");
|
||||
|
||||
networkAvailable = false;
|
||||
show(LED_GREEN, BLINK);
|
||||
|
Loading…
x
Reference in New Issue
Block a user