From c3c24556605f92c19d633a5da58abbdb60a1a8da Mon Sep 17 00:00:00 2001 From: MDC Service Date: Thu, 26 May 2022 10:34:22 +0200 Subject: Initial check in HMI driver --- software/drivers/HMI.h | 116 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 116 insertions(+) create mode 100644 software/drivers/HMI.h (limited to 'software/drivers/HMI.h') diff --git a/software/drivers/HMI.h b/software/drivers/HMI.h new file mode 100644 index 0000000..055190a --- /dev/null +++ b/software/drivers/HMI.h @@ -0,0 +1,116 @@ +/* + * LCD.h + * + * Created on: 17.08.2021 + * Author: steffen + * SPDX-FileCopyrightText: 2022 MDC Service + * SPDX-License-Identifier: GPL-3.0-or-later + */ + +#ifndef HMI_H_ +#define HMI_H_ +#include "main.h" + +#define DEBUG +#define ESP32 +#define ProtBufLen 260 + +#define ERR_NOERR 0 +#define ERR_CRC -1 +#define ERR_WRITE -2 +#define ERR_NOANSWER -3 +#define ERR_DECODE -4 + + +#define BAUD_9600 0 +#define BAUD_19200 1 +#define BAUD_38400 2 +#define BAUD_57600 5 +#define BAUD_115200 6 + +#define PIC_WELCOME 0 +#define PIC_OPENDOOR 1 +#define PIC_EMPTY 2 +#define PIC_KAS_OK 3 +#define PIC_KAS_DIS 4 +#define PIC_TRS_OK 5 +#define PIC_TRS_DIS 6 + +#define BUT0 p0 +#define TXT0 t0 +#define BUT1 p1 +#define TXT1 t1 +#define BUT2 p2 +#define TXT2 t2 +#define BUT3 p3 +#define TXT3 t3 +#define BUT4 p4 +#define TXT4 t4 +#define BUT5 p5 +#define TXT5 t5 + +#ifdef ESP32 +#include +#include +#include +#include +#include "freertos/FreeRTOS.h" +#include "freertos/task.h" +#include "esp_event.h" +#include "esp_log.h" +#include "driver/uart.h" +#else +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#endif + +#define ESP32 +#define HMIResultOK 0 +#define HMIResultWriteErr -1 +#define HMIResultReadErr -2 +#define HMIResultProtErr -3 + +typedef struct { + int page; + int id; + int state; +} HMI_t; + +class HMI { +public: + +#ifdef ESP32 + HMI(const int fh); +#else + HMI(const char *dev = "/dev/ttyUSB0", const uint16_t baud = 57600); +#endif + ~HMI(void); + + int iReadProt(int ms); + int iReadValue(char *name, int *res); + int iReadValue(char *name,char *res); + int iWriteValue(char *name,int value); + int iWriteValue(char *name,char *value); + int iSendProt(int len, char *data); // done + int iSendProt(int len, char *data, int wait); // done + +private: + int _devh; + unsigned char SendBuf[ProtBufLen]; + unsigned char RecvBuf[ProtBufLen]; + int serial_read(int fh, char *buf); + int serial_write(int fh, char * buf,int len); + void idumpbuf(void *buf, int len); + +}; +#endif /* HMI_H_ */ -- cgit v1.2.3