Jump to content
Electronics-Lab.com Community

Implementation of Forlinx RK3568 SoM Automatic Screen-off Configuration Program


Recommended Posts

Software version: Linux 4.19

Design Idea: Detect screen touch events to determine whether the screen is being used or not in an auto-break application. If the screen detects input events, it will remain on. If no touch events are received for a period of time, the screen will transition from on to a dimmed state, reminding the user that it is about to enter the screen-off mode. If no touch events occur after dimming, the screen will enter the screen-off mode. When a touch event occurs again, the screen will transition from screen-off mode to the on state.

Currently, the approach to implement automatic screen-off is to treat touch events as a fixed path that can be applied to familiar boards. To enhance convenience in application, two additional alternative approaches are provided below:

▊ The first implementation method

You can apply the evtest command to get the path to/dev/input/event1 (event1 is the name of the touch event on my board). You can then pass the path to your program as a parameter.

For example, you can modify your program to accept command-line arguments to specify the path of the device file to open

int argc, char *argv[];

Opens a file with the passed in parameters as the device file path

int fd = open(argv[1], O_RDONLY);

You can compile and run the program, passing it/dev/input/event1 as a command-line argument, like this:

./your_program /dev/input/event1

▊ The second implementation method is to fix the screen touch node in the device tree.

Look for the screen touch node in the device tree and note its address.

f_ff2fd910323354b8725f30edde95c85c&t=png

On the I2C bus, the address of the touch node is simply 2-0038

f_e04ba925b8b4f8919325930f3d9359d0&t=png

So we can use grep to filter out touch nodes based on their addresses.

ls -l /sys/class/input | grep "0038" | awk -F ' ' '{print $9}' | grep "event"

f_f5774a559061649abd736afb742d85e6&t=png

The following command is used in the application to find the touch event based on the touch address.

char *command_output = exec("ls -l /sys/class/input | grep '0038' | awk -F ' ' '{print $9}' | grep 'event'");
Use the sprintf function to splice the path containing the event, and then read the event. 
                        Examples of using Sprintf: int main() {
    char str[100];
    int num = 123;
float f = 3.14;
    //Write the formatted data to the string
    sprintf(str, "%d%.2f", num, f);
    //print the generated string
    printf("The output is. %s\n", str);
    return 0;
}

 

f_7f7567e4c7ff836b2445d35c56c4a574&t=png

Link to comment
Share on other sites


Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
×
  • Create New...