The trouble I am finding is when doing all three simultaneously the response time to the touch command is very poor. My thought is if the current screen is (1) then read CAN Information, if (2) read the sensors and if (3) then read the buffer for the touch variable.
In order to do this I was thinking something like (and this is psuedo code)
loop (){
currentscreen = checkcurrent();
switch current screen {
case 1 :
UpdateCanValues(); //currently works
case 2 :
UpdateSensorValues(); //currently works
case 3 :
SwitchLedColor(); //currently works
default : }
}
My question is how do i write the code to check the current screen on the DWIN
Thanks. Doesnt solve the problem in this case as I dont believe the change screen function in DWIN generates an event and even if it does this is the same problem I have now as the same buffer is used to read for events (like the current buttons for Red, Blue, White etc) is also used for the canbus updates to the display variables.
Like the Canbus where I 'ask' it to return a PID value I want to check the screen and then choose the action - reading the buffer or writing to it rather than both.
Screen navigation is controlled by the DWIN OS itself. A basic touch control (which doesnt seem to have a virtual address but I dont want to be waiting for it anyway) does a Page Switch function between the Pages. Nothing is done by the sketch - it can just read or write to the serial buffer which is why there is a conflict as there is only one buffer for both read and write.
Managed to find the solution. Sending a query to 5A A5 04 83 0014 01 returns the current displayed screen in address location 7.
This code prints out the current Page ID to the Serial Port - will now use a case statement on the id for the relevant function - CAN Update, Sensor check etc
#include <SoftwareSerial.h>
unsigned char Buffer[9];
SoftwareSerial dwin(11, 10); // RX, TX
unsigned char CurrentScreen[8] = {0x5a, 0xa5, 0x04, 0x83, 0x00 , 0x14, 0x01, 0x00};
void setup() {
Serial.begin(115200); // To Computer
dwin.begin(115200); // To Display
}
void loop() {
dwin.write(CurrentScreen,8);
delay (100);
if (dwin.available())
{
for (int i = 0; i <= 8; i++) //this loop will store whole frame in buffer array.
{
Buffer[i] = dwin.read();
}
Serial.println(Buffer[7]);
}
}
Note I am using SoftwareSerial as the CANModule also uses Serial on Serial 1