Created
July 8, 2024 22:15
-
-
Save 0xD34D/5a4b8a8715da5e2e9efddc3e7ea78255 to your computer and use it in GitHub Desktop.
Interfacing with the E3V3SE TJC HMI display using TJC instructions ;)
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 <Arduino.h> | |
#define TJC Serial0 | |
#define TX_Pin 6 | |
#define RX_Pin 7 | |
#define FRAME_LENGTH 7 | |
int a; | |
unsigned long nowtime; | |
void setup() | |
{ | |
Serial.begin(115200); | |
Serial.print("Settling"); | |
for (uint8_t i = 0; i < 10; i++) | |
{ | |
Serial.print("."); | |
delay(200); | |
} | |
Serial.println(); | |
TJC.begin(115200, SERIAL_8N1, -1, -1); | |
TJC.print("DRAKJHSUYDGBNCJHGJKSHBDN\xff\xff\xff"); | |
while (TJC.read() >= 0) | |
; | |
TJC.print("page main\xff\xff\xff"); | |
nowtime = millis(); | |
} | |
void loop() | |
{ | |
char str[100]; | |
if (millis() >= nowtime + 500) | |
{ | |
nowtime = millis(); | |
TJC.printf("n0.val=%d\xff\xff\xff", a); | |
TJC.printf("t0.txt=\"count:%d\"\xff\xff\xff", a); | |
TJC.printf("click b0,1\xff\xff\xff"); | |
delay(50); | |
TJC.printf("click b0,0\xff\xff\xff"); | |
a++; | |
} | |
// Serial data format: | |
// Serial data frame length: 7 bytes | |
// Frame header parameter 1 parameter 2 parameter 3 frame end | |
// 0x55 1 byte 1 byte 1 byte 0xffffff | |
// When the parameter is 01 | |
// Frame header parameter 1 parameter 2 parameter 3 frame end | |
// 0x55 01 led number led status 0xffffff | |
// Example 1: Host computer code printh 55 01 01 00 ff ff ff Meaning: No. 1 led is turned off | |
// Example 2: Host computer code printh 55 01 04 01 ff ff ff Meaning: No. 4 led is turned on | |
// Example 3: Host computer code printh 55 01 00 01 ff ff ff Meaning: No. 0 led is turned on | |
// Example 4: Host computer code printh 55 01 04 00 ff ff ff Meaning: LED No. 4 is off | |
// When the parameter is 02 or 03 | |
// Frame header Parameter 1 Parameter 2 Parameter 3 Frame end | |
// 0x55 02/03 Slide value 00 0xffffff | |
// Example 1: Host computer code printh 55 02 64 00 ff ff ff Meaning: h0.val=100 | |
// Example 2: Host computer code printh 55 02 00 00 ff ff ff Meaning: h0.val=0 | |
// Example 3: Host computer code printh 55 03 64 00 ff ff ff Meaning: h1.val=100 | |
// Example 4: Host computer code printh 55 03 00 00 ff ff ff Meaning: h1.val=0 | |
// When the serial port buffer is greater than or equal to 6 while (TJC.available() >= FRAME_LENGTH) | |
{ | |
unsigned char ubuffer[FRAME_LENGTH]; | |
// Read 1 byte from the serial port buffer without deleting it | |
unsigned char frame_header = TJC.peek(); | |
// When the acquired data is a packet header (0x55) | |
if (frame_header == 0x55) | |
{ | |
// Read 7 bytes from the serial port buffer | |
TJC.readBytes(ubuffer, FRAME_LENGTH); | |
if (ubuffer[4] == 0xff && ubuffer[5] == 0xff && ubuffer[6] == 0xff) | |
{ | |
if (ubuffer[1] == 0x01) | |
{ | |
// What is sent is LED information | |
sprintf(str, "msg.txt=\"led %d is %s\"\xff\xff\xff", ubuffer[2], ubuffer[3] ? "on" : "off"); | |
TJC.print(str); | |
} | |
else if (ubuffer[1] == 0x02) | |
{ | |
// What is sent is the information of the slider h0.val | |
sprintf(str, "msg.txt=\"h0.val is %d\"\xff\xff\xff", ubuffer[2]); | |
TJC.print(str); | |
} | |
else if (ubuffer[1] == 0x03) | |
{ | |
// What is sent is the information of the slider h1.val | |
sprintf(str, "msg.txt=\"h1.val is %d\"\xff\xff\xff", ubuffer[2]); | |
TJC.print(str); | |
} | |
} | |
} | |
else | |
{ | |
TJC.read(); // Read 1 byte from the serial buffer and delete | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment