hc
2025-02-14 bbb9540dc49f70f6b703d1c8d1b85fa5f602d86e
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
/*
 * Copyright (c) 2017 Rockchip Electronics Co. Ltd.
 *
 * SPDX-License-Identifier:    GPL-2.0+
 */
 
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <errno.h>
#include <fcntl.h>
#include <linux/input.h>
#include <signal.h>
 
#define LOG_TAG "echo_touchpad_test"
#include "common.h"
 
#define TOUCHPAD_NODE "sys/devices/11050000.i2c/i2c-0/0-0020/cy8ctouchread"
 
int char_to_value(char *ch)
{
   if ((*ch >= 'A') && (*ch <= 'F'))
       return 10 + *ch - 'A';
   else if ((*ch >= 'a') && (*ch <= 'f'))
       return 10 + *ch - 'a';
   else if ((*ch >= '0') && (*ch <= '9'))
       return *ch - '0';
   else
       return 0;
}
 
int main()
{
   int delay_t = 0,err_code = 0;
   struct timeval t1, t2;
   char buf[COMMAND_VALUESIZE] = "touchpad_test";
    char result[COMMAND_VALUESIZE] = RESULT_VERIFY;
   int fd = 0, ret = 0, key = 0;
   char buff[40], *start = NULL;
   int flag_pre = 0, flag_play = 0, flag_nxt = 0;
 
   fd = open(TOUCHPAD_NODE, O_RDONLY);
   if (fd <= 0) {
       log_err("open touchpad node file failed(%s).\n",
               strerror(errno));
       err_code = -ENODEV;
       goto OUT;
   }
 
   gettimeofday(&t1, NULL);
    while(1) {
       lseek(fd, 0, SEEK_SET);
       ret = read(fd, buff, sizeof(buff));
       if (ret < 0) {
           log_err("read touchpad node file failed(%s).\n",
                   strerror(errno));
           err_code = -ENODEV;
           break;
       }
       start = strstr(buff, "0x");
       key = char_to_value(start + 2)*16 + char_to_value(start + 3);
 
       if ((key >= 0x40) && (key <= 0x44)) {
           log_info("--> <pause/play> key pressed!\n");
           flag_play = 1;
       } else if ((key >= 0x59) && (key <= 0x5d)) {
           log_info("--> <previous> key pressed!\n");
           flag_pre = 1;
       } else if ((key >= 0x28) && (key <= 0x2c)) {
           log_info("--> <next> key pressed!\n");
           flag_nxt = 1;
       }
 
       if (flag_nxt && flag_play && flag_pre)
           break;
 
        gettimeofday(&t2, NULL);
       delay_t = (t2.tv_sec - t1.tv_sec) * 1000000 + (t2.tv_usec - t1.tv_usec);
       if (delay_t > MANUAL_TEST_TIMEOUT) {
           log_warn("timeout(60s)\n");
           err_code = -ETIME;
           break;
       }
 
       usleep(2000);
    }
 
OUT:
    if (err_code)
       strcpy(result, RESULT_FAIL);
    send_msg_to_server(buf, result, err_code);
 
    return 0;
}