Android->recovery:control led
This commit is contained in:
@ -204,11 +204,19 @@ static RKSdBootCfgItem SdBootConfigs[] =
|
||||
},
|
||||
};
|
||||
|
||||
#define YELLOW 1
|
||||
#define BLUE 2
|
||||
void *thrd_led_func(void *arg);
|
||||
pthread_t tid_yellow_led;
|
||||
pthread_t tid_blue_led;
|
||||
pthread_t tid;
|
||||
bool isLedFlash = false;
|
||||
bool bSDMounted = false;
|
||||
bool bUsbMounted = false;
|
||||
void startLedBlink(int led);
|
||||
void stopLed(int led);
|
||||
void startLed(int led);
|
||||
void stopLedBlink(int led);
|
||||
|
||||
/*
|
||||
* The recovery tool communicates with the main system through /cache files.
|
||||
@ -1773,6 +1781,8 @@ int do_sd_mode_update(char *pFile)
|
||||
ui->SetBackground(RecoveryUI::INSTALLING_UPDATE);
|
||||
ui->SetProgressType(RecoveryUI::DETERMINATE);
|
||||
printf("start sd upgrade...\n");
|
||||
startLedBlink(YELLOW);
|
||||
stopLed(BLUE);
|
||||
|
||||
#ifdef USE_BOARD_ID
|
||||
ensure_path_mounted("/cust");
|
||||
@ -1783,11 +1793,29 @@ int do_sd_mode_update(char *pFile)
|
||||
bRet= do_rk_firmware_upgrade(pFwPath,(void *)handle_upgrade_callback,(void *)handle_upgrade_progress_callback);
|
||||
else
|
||||
bRet = do_rk_partition_upgrade(pFwPath,(void *)handle_upgrade_callback,(void *)handle_upgrade_progress_callback);
|
||||
|
||||
// check firefly recovery script
|
||||
const char firefly_recovery_script[256];
|
||||
strcpy(firefly_recovery_script, EX_SDCARD_ROOT);
|
||||
strcat(firefly_recovery_script, "/firefly-recovery.sh");
|
||||
printf("Check %s", firefly_recovery_script);
|
||||
if(bRet && !access(firefly_recovery_script, 0)) { //run firefly scripts
|
||||
ui->Print("Runing firefly-recovery.sh...\n");
|
||||
printf("Running %s", firefly_recovery_script);
|
||||
char *cmd[4];
|
||||
cmd[0] = strdup("/sbin/busybox");
|
||||
cmd[1] = strdup("ash");
|
||||
cmd[2] = strdup(firefly_recovery_script);
|
||||
cmd[3] = NULL;
|
||||
bRet = exec_cmd(cmd[0], cmd) == 0;
|
||||
}
|
||||
|
||||
ui->SetProgressType(RecoveryUI::EMPTY);
|
||||
if (!bRet)
|
||||
{
|
||||
status = INSTALL_ERROR;
|
||||
printf("SD upgrade failed!\n");
|
||||
startLedBlink(BLUE);
|
||||
}
|
||||
else
|
||||
{
|
||||
@ -1803,6 +1831,8 @@ int do_sd_mode_update(char *pFile)
|
||||
// }
|
||||
bAutoUpdateComplete=true;
|
||||
printf("SD upgrade ok.\n");
|
||||
stopLedBlink(YELLOW);
|
||||
startLed(YELLOW);
|
||||
}
|
||||
|
||||
return status;
|
||||
@ -2037,12 +2067,12 @@ int do_usb_demo_copy(char *demoPath)
|
||||
}
|
||||
|
||||
|
||||
void *thrd_led_func(void *arg) {
|
||||
void *thrd_yellow_led_func(void *arg) {
|
||||
FILE * ledFd = NULL;
|
||||
bool onoff = false;
|
||||
|
||||
while(isLedFlash) {
|
||||
ledFd = fopen("/sys/class/led_gpio/net_led", "w");
|
||||
ledFd = fopen("/sys/class/leds/firefly:yellow:user/brightness", "w");
|
||||
if(onoff) {
|
||||
fprintf(ledFd, "%d", 0);
|
||||
onoff = false;
|
||||
@ -2056,31 +2086,97 @@ void *thrd_led_func(void *arg) {
|
||||
}
|
||||
|
||||
printf("stopping led thread, close led and exit\n");
|
||||
ledFd = fopen("/sys/class/led_gpio/net_led", "w");
|
||||
ledFd = fopen("/sys/class/leds/firefly:yellow:user/brightness", "w");
|
||||
fprintf(ledFd, "%d", 0);
|
||||
fclose(ledFd);
|
||||
pthread_exit(NULL);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
void startLed() {
|
||||
isLedFlash = true;
|
||||
if (pthread_create(&tid,NULL,thrd_led_func,NULL)!=0) {
|
||||
printf("Create led thread error!\n");
|
||||
void *thrd_blue_led_func(void *arg) {
|
||||
FILE * ledFd = NULL;
|
||||
bool onoff = false;
|
||||
|
||||
while(isLedFlash) {
|
||||
ledFd = fopen("/sys/class/leds/firefly:blue:power/brightness", "w");
|
||||
if(onoff) {
|
||||
fprintf(ledFd, "%d", 0);
|
||||
onoff = false;
|
||||
}else {
|
||||
fprintf(ledFd, "%d", 1);
|
||||
onoff = true;
|
||||
}
|
||||
|
||||
fclose(ledFd);
|
||||
usleep(500 * 1000);
|
||||
}
|
||||
|
||||
printf("tid in led pthread: %ld.\n",tid);
|
||||
|
||||
printf("stopping led thread, close led and exit\n");
|
||||
ledFd = fopen("/sys/class/leds/firefly:blue:power/brightness", "w");
|
||||
fprintf(ledFd, "%d", 0);
|
||||
fclose(ledFd);
|
||||
pthread_exit(NULL);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
void stopLed() {
|
||||
void startLedBlink(int led) {
|
||||
isLedFlash = true;
|
||||
if(led == YELLOW) {
|
||||
if (pthread_create(&tid_yellow_led,NULL,thrd_yellow_led_func,NULL)!=0) {
|
||||
printf("Create led thread error!\n");
|
||||
}
|
||||
printf("tid in led pthread: %u.\n",tid_yellow_led);
|
||||
}
|
||||
else if(led == BLUE) {
|
||||
if (pthread_create(&tid_blue_led,NULL,thrd_blue_led_func,NULL)!=0) {
|
||||
printf("Create led thread error!\n");
|
||||
}
|
||||
printf("tid in led pthread: %u.\n",tid_blue_led);
|
||||
}
|
||||
}
|
||||
|
||||
void startLed(int led) {
|
||||
FILE * ledFd = NULL;
|
||||
if(led == YELLOW) {
|
||||
ledFd = fopen("/sys/class/leds/firefly:yellow:user/brightness", "w");
|
||||
fprintf(ledFd, "%d", 1);
|
||||
fclose(ledFd);
|
||||
}
|
||||
else if (led == BLUE) {
|
||||
ledFd = fopen("/sys/class/leds/firefly:blue:power/brightness", "w");
|
||||
fprintf(ledFd, "%d", 1);
|
||||
fclose(ledFd);
|
||||
}
|
||||
}
|
||||
void stopLed(int led) {
|
||||
FILE * ledFd = NULL;
|
||||
if(led == YELLOW) {
|
||||
ledFd = fopen("/sys/class/leds/firefly:yellow:user/brightness", "w");
|
||||
fprintf(ledFd, "%d", 0);
|
||||
fclose(ledFd);
|
||||
}
|
||||
else if (led == BLUE) {
|
||||
ledFd = fopen("/sys/class/leds/firefly:blue:power/brightness", "w");
|
||||
fprintf(ledFd, "%d", 0);
|
||||
fclose(ledFd);
|
||||
}
|
||||
}
|
||||
void stopLedBlink(int led) {
|
||||
void *tret;
|
||||
isLedFlash = false;
|
||||
|
||||
if (pthread_join(tid, &tret)!=0){
|
||||
printf("Join led thread error!\n");
|
||||
}else {
|
||||
printf("join led thread success!\n");
|
||||
if (led == YELLOW) {
|
||||
if (pthread_join(tid_yellow_led, &tret)!=0){
|
||||
printf("Join led thread error!\n");
|
||||
}else {
|
||||
printf("join led thread success!\n");
|
||||
}
|
||||
} else if (led == BLUE) {
|
||||
if (pthread_join(tid_blue_led, &tret)!=0){
|
||||
printf("Join led thread error!\n");
|
||||
}else {
|
||||
printf("join led thread success!\n");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -51,6 +51,8 @@ int setup_install_mounts();
|
||||
// and 0 if the partition was not wiped.
|
||||
int erase_persistent_partition();
|
||||
|
||||
int exec_cmd(const char* path, char* const argv[]);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
Reference in New Issue
Block a user