DWIN Determine Current Screen

I have a project with three screens

  1. Voltage, Temp and Turbo Boost via CAN BUS
  2. Distance reading from four ultrasonic sensors
  3. LED Lighting control

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) :slight_smile:

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 !

  • Have a variable that holds the current screen number (1,2 or 3).
  • Every time that you change screens update the variable with the current screen number.
  • To determine the current screen, test the value of the variable

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.

Appreciate the help.

What action in your sketch causes the screen to change from one to another ?

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.

Thanks !

I am not familiar with DWIN but what determines the data that is shown on the screen and where it is positioned on the screen ?

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

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.