恢复出厂设置 LED灯闪烁

这篇博客讨论了如何在Android设备的恢复模式下控制LED灯的状态,并展示了相关代码实现。通过修改`recovery_main.cpp`文件添加了一个LED_thread函数,周期性地切换LED灯状态。同时,在`init.recovery.common.rc`文件中设置了相关权限,允许读写LED亮度。这涉及到了设备驱动、Linux内核接口和系统初始化脚本的知识。
摘要由CSDN通过智能技术生成
恢复出厂设置 LED灯闪烁
diff --git a/bootable/recovery/recovery_main.cpp b/bootable/recovery/recovery_main.cpp
old mode 100644
new mode 100755
index de8ac1f..e481678
--- a/bootable/recovery/recovery_main.cpp
+++ b/bootable/recovery/recovery_main.cpp
@@ -310,6 +310,39 @@ static void redirect_stdio(const char* filename) {
   }
 }
 
+static char on[] = "1";
+static char off[] = "0";
+
+
+int set_led_status(int status){
+       int pcb_fd;
+       int count;
+       pcb_fd=open("/sys/class/leds/red_led/brightness", O_RDWR); /*open*/
+       if(status)
+               //system(" echo 0>  /sys/class/leds/red_led/brightness");
+               count=write(pcb_fd, on, sizeof(on)) ;
+       else
+               count=write(pcb_fd, off, sizeof(off)) ;
+ 		close(pcb_fd);
+       LOG(INFO) << "set_led_status status =" << status <<"  pcb_fd=" << pcb_fd << "  count=" << count;
+       return 0;
+}
+
+void LED_thread(){
+    int flag = 0;
+    for(;;){
+        if(flag == 0) {
+            set_led_status(1);
+            flag = 1;
+        } else {
+            set_led_status(0);
+            flag = 0;
+        }
+        usleep(10000);
+    }
+}
+
+
+
 int main(int argc, char** argv) {
   // We don't have logcat yet under recovery; so we'll print error on screen and log to stdout
   // (which is redirected to recovery.log) as we used to do.
@@ -441,8 +474,10 @@ int main(int argc, char** argv) {
     ui->Print("Warning: No file_contexts\n");
   }
 
-  SetLoggingSehandle(sehandle);
+  std::thread led_t(LED_thread);
+  led_t.detach();
 
+  SetLoggingSehandle(sehandle);
   std::atomic<Device::BuiltinAction> action;
   std::thread listener_thread(ListenRecoverySocket, ui, std::ref(action));
   listener_thread.detach();
diff --git a/device/sprd/sharkle/common/recovery/init.recovery.common.rc b/device/sprd/sharkle/common/recovery/init.recovery.common.rc
index 1ca766d..b172756 100755
--- a/device/sprd/sharkle/common/recovery/init.recovery.common.rc
+++ b/device/sprd/sharkle/common/recovery/init.recovery.common.rc
@@ -187,6 +187,10 @@ on boot
     chmod 660 /sys/class/power_supply/battery/charger.0/stop_charge
     chmod 660 /sys/class/power_supply/battery/charger.0/jeita_control
 
+       chmod   777     /sys/class/leds/blue_led/brightness
+       chmod   777     /sys/class/leds/red_led/brightness
+       chmod   777     /sys/class/leds/green_led/brightness
+
 on fs
     mkdir /data/misc/bluedroid 0770 bluetooth net_bt_stack
     mkdir /data/misc/bluetooth 0770 system system
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值