231 lines
6.1 KiB
C
231 lines
6.1 KiB
C
|
/*
|
|||
|
* led_test.c -- led test application
|
|||
|
*
|
|||
|
* Copyright (c) 2017 Rockchip Electronics Co. Ltd.
|
|||
|
* Author:
|
|||
|
* Panzhenzhuan Wang <randy.wang@rock-chips.com>
|
|||
|
* Bin Yang <yangbin@rock-chips.com>
|
|||
|
*
|
|||
|
*
|
|||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
|||
|
* you may not use this file except in compliance with the License.
|
|||
|
* You may obtain a copy of the License at
|
|||
|
*
|
|||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
|||
|
*
|
|||
|
* Unless required by applicable law or agreed to in writing, software
|
|||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
|||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|||
|
* See the License for the specific language governing permissions and
|
|||
|
* limitations under the License.
|
|||
|
*/
|
|||
|
|
|||
|
#include <stdio.h>
|
|||
|
#include <stdlib.h>
|
|||
|
#include <sys/types.h>
|
|||
|
#include <sys/stat.h>
|
|||
|
#include <fcntl.h>
|
|||
|
#include <sys/time.h>
|
|||
|
#include <signal.h>
|
|||
|
|
|||
|
#include <string.h>
|
|||
|
#include <unistd.h>
|
|||
|
#include "led_test.h"
|
|||
|
|
|||
|
#define LOG_TAG "led_test"
|
|||
|
#include "common.h"
|
|||
|
|
|||
|
#define LED_BRIGHTNESS_FILE "/sys/class/leds/led%d/brightness"
|
|||
|
#define LED_TRIGGER_FILE "/sys/class/leds/led%d/trigger"
|
|||
|
#define LED_SHOT_FILE "/sys/class/leds/led%d/shot"
|
|||
|
#define LED_DELAY_ON_FILE "/sys/class/leds/led%d/delay_on"
|
|||
|
#define LED_DELAY_OFF_FILE "/sys/class/leds/led%d/delay_off"
|
|||
|
|
|||
|
#define LED_NUM 36
|
|||
|
#define COLOR_NUM 3
|
|||
|
//<2F><><EFBFBD><EFBFBD>LED<45><44><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ر<EFBFBD>
|
|||
|
#define LED_ON "128"
|
|||
|
#define LED_OFF "0"
|
|||
|
|
|||
|
#define TRIGGER_NONE 0
|
|||
|
|
|||
|
#define LOG_TAG "led_test"
|
|||
|
#include "common.h"
|
|||
|
|
|||
|
#define LED_TEST_TIMEOUT -51
|
|||
|
#define LED_PROC_ERR -55
|
|||
|
|
|||
|
//<2F><><EFBFBD><EFBFBD>LED<45><44><EFBFBD><EFBFBD>ɫ<EFBFBD>ṹ<EFBFBD><E1B9B9>
|
|||
|
typedef enum
|
|||
|
{
|
|||
|
LED_BLUE = 0,
|
|||
|
LED_GREEN,
|
|||
|
LED_RED,
|
|||
|
} LED_colors;
|
|||
|
|
|||
|
void *led_test(void *argv); //LED<45><44><EFBFBD>Գ<EFBFBD><D4B3><EFBFBD>
|
|||
|
int write_int(char const* path,char const* value); //<2F><>ֵд<D6B5><D0B4><EFBFBD><EFBFBD>Ӧ·<D3A6><C2B7><EFBFBD>ļ<EFBFBD>
|
|||
|
|
|||
|
void *led_test(void *argv)
|
|||
|
{
|
|||
|
char buf[128];
|
|||
|
char cmd[128];
|
|||
|
int led_num,color_num =1;
|
|||
|
LED_colors test_color;
|
|||
|
|
|||
|
|
|||
|
printf("===================LED test start======================\n\n");
|
|||
|
fprintf(stderr,"Start testing LED, order is Red, Green, Blue, White.\n Testing:\n");
|
|||
|
while(color_num < 4)
|
|||
|
{
|
|||
|
switch(color_num%3) //<2F><>һ<EFBFBD><D2BB>RED<45>ơ<EFBFBD><C6A1>ڶ<EFBFBD><DAB6><EFBFBD>GREEN<45>ơ<EFBFBD><C6A1><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>BLUE<55>ơ<EFBFBD><C6A1><EFBFBD><EFBFBD><EFBFBD>һ<EFBFBD><D2BB>RGB<47>ϳɰ<C9B0>
|
|||
|
{
|
|||
|
case 1:
|
|||
|
printf(" The testing color is RED: \n");
|
|||
|
break;
|
|||
|
case 2:
|
|||
|
printf(" The testing color is GREEN: \n");
|
|||
|
break;
|
|||
|
case 0:
|
|||
|
printf(" The testing color is BLUE: \n");
|
|||
|
break;
|
|||
|
default :
|
|||
|
fprintf(stderr,"select color error");
|
|||
|
}
|
|||
|
for(led_num=1;led_num<=LED_NUM;led_num++)
|
|||
|
{
|
|||
|
switch(led_num % 3)
|
|||
|
{
|
|||
|
case LED_RED :
|
|||
|
if(color_num % 3 == 1)
|
|||
|
{
|
|||
|
sprintf(buf,LED_BRIGHTNESS_FILE,led_num);
|
|||
|
if(-1==write_int(buf,LED_ON))
|
|||
|
goto fail;
|
|||
|
}
|
|||
|
else
|
|||
|
{
|
|||
|
sprintf(buf,LED_BRIGHTNESS_FILE,led_num);
|
|||
|
if(-1==write_int(buf,LED_OFF))
|
|||
|
goto fail;
|
|||
|
}
|
|||
|
break;
|
|||
|
case LED_GREEN :
|
|||
|
if(color_num % 3 == 2)
|
|||
|
{
|
|||
|
sprintf(buf,LED_BRIGHTNESS_FILE,led_num);
|
|||
|
if(-1==write_int(buf,LED_ON))
|
|||
|
goto fail;
|
|||
|
}
|
|||
|
else
|
|||
|
{
|
|||
|
sprintf(buf,LED_BRIGHTNESS_FILE,led_num);
|
|||
|
if(-1==write_int(buf,LED_OFF))
|
|||
|
goto fail;
|
|||
|
}
|
|||
|
break;
|
|||
|
case LED_BLUE :
|
|||
|
if(color_num % 3 == 0)
|
|||
|
{
|
|||
|
sprintf(buf,LED_BRIGHTNESS_FILE,led_num);
|
|||
|
if(-1==write_int(buf,LED_ON))
|
|||
|
goto fail;
|
|||
|
}
|
|||
|
else
|
|||
|
{
|
|||
|
sprintf(buf,LED_BRIGHTNESS_FILE,led_num);
|
|||
|
if(-1==write_int(buf,LED_OFF))
|
|||
|
goto fail;
|
|||
|
}
|
|||
|
break;
|
|||
|
default :
|
|||
|
fprintf(stderr,"select color error");
|
|||
|
}
|
|||
|
}
|
|||
|
printf("LED shining 1 seconds:\n");
|
|||
|
sleep(1); //<2F><><EFBFBD><EFBFBD>1<EFBFBD><31>
|
|||
|
color_num++;
|
|||
|
}
|
|||
|
|
|||
|
//RGB<47><42><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ɫ<EFBFBD><C9AB><EFBFBD><EFBFBD>һ<EFBFBD><D2BB><EFBFBD>γɰ<C9B0>
|
|||
|
for(led_num=1;led_num<=LED_NUM;led_num++)
|
|||
|
{
|
|||
|
sprintf(buf,LED_BRIGHTNESS_FILE,led_num);
|
|||
|
if(-1==write_int(buf,LED_ON))
|
|||
|
goto fail;
|
|||
|
}
|
|||
|
|
|||
|
sleep(1); //<2F><>ͣ1<CDA3><31>
|
|||
|
|
|||
|
for(led_num=1;led_num<=LED_NUM;led_num++)
|
|||
|
{
|
|||
|
sprintf(buf,LED_BRIGHTNESS_FILE,led_num);
|
|||
|
if(-1==write_int(buf,LED_OFF))
|
|||
|
goto fail;
|
|||
|
}
|
|||
|
fprintf(stderr, "===========LED Test finished=============\n");
|
|||
|
|
|||
|
return (void*)0;
|
|||
|
fail:
|
|||
|
|
|||
|
return (void*)-1;
|
|||
|
}
|
|||
|
|
|||
|
//* <20>źŴ<C5BA><C5B4><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ڽ<EFBFBD><DABD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ǰ<EFBFBD><C7B0><EFBFBD>ر<EFBFBD><D8B1><EFBFBD><EFBFBD>е<EFBFBD>
|
|||
|
static int leds_all_off(int sign_no)
|
|||
|
{
|
|||
|
char buf[128];
|
|||
|
int led_num;
|
|||
|
|
|||
|
printf("====================function : %s start =================\n",__func__);
|
|||
|
for(led_num=1; led_num<=LED_NUM; led_num++)
|
|||
|
{
|
|||
|
sprintf(buf,LED_BRIGHTNESS_FILE,led_num);
|
|||
|
if(-1==write_int(buf,LED_OFF))
|
|||
|
goto fail;
|
|||
|
}
|
|||
|
|
|||
|
printf("====================function : %s finished =================\n",__func__);
|
|||
|
exit(0);
|
|||
|
fail:
|
|||
|
exit(-1);
|
|||
|
}
|
|||
|
|
|||
|
/*<2A><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>*/
|
|||
|
int main(int argc, char *argv[])
|
|||
|
{
|
|||
|
int test_flag = 0,err_code = 0;
|
|||
|
char buf[COMMAND_VALUESIZE] = "led_test";
|
|||
|
char result[COMMAND_VALUESIZE] = RESULT_PASS;
|
|||
|
int delay_t = 0;
|
|||
|
struct timeval t1, t2;
|
|||
|
|
|||
|
log_info("led test start...\n");
|
|||
|
|
|||
|
//* ע<><D7A2><EFBFBD>źŴ<C5BA><C5B4><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|||
|
signal(SIGTERM,(__sighandler_t)leds_all_off);
|
|||
|
|
|||
|
gettimeofday(&t1, NULL);
|
|||
|
while(1)
|
|||
|
{
|
|||
|
test_flag = (int)led_test(argv[0]);
|
|||
|
if(test_flag < 0)
|
|||
|
{
|
|||
|
err_code = LED_PROC_ERR;
|
|||
|
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("led test end, timeout 60s\n");
|
|||
|
err_code = LED_TEST_TIMEOUT;
|
|||
|
break;
|
|||
|
}
|
|||
|
}
|
|||
|
if (err_code)
|
|||
|
strcpy(result, RESULT_FAIL);
|
|||
|
send_msg_to_server(buf, result, err_code);
|
|||
|
return 0;
|
|||
|
}
|