From d381e10794ce7364d64e7e43c7a4a091629a9160 Mon Sep 17 00:00:00 2001 From: Vaughan Agrez Date: Sat, 16 Dec 2017 22:35:57 +0800 Subject: [PATCH] Add support for enabling/disabling RPi ACT & PWR LEDs --- fedberry-config | 80 +++++++++++++++++++++++++++++++++---- fedberry-config.spec | 8 +++- pi3_disable_pwr_led.service | 15 +++++++ 3 files changed, 93 insertions(+), 10 deletions(-) create mode 100644 pi3_disable_pwr_led.service diff --git a/fedberry-config b/fedberry-config index 0a70612..1445f02 100755 --- a/fedberry-config +++ b/fedberry-config @@ -53,10 +53,15 @@ declare -A DEF_VALS=( [audio_pwm_mode]=2 [disable_audio_dither]=1 [disable_splash]=1 + [act_led_trigger]=none + [act_led_activelow]=off + [pwr_led_trigger]=none + [pwr_led_activelow]=off ) ### Name references for various DTOs, DTPs & config options declare -A REF_NAMES=( + [act_led_activelow]="Activity (Green) LED" [allo-boss-dac-pcm512x-audio]="Allo Boss DAC audio card support" [allo-digione]="Allo Digione audio card support" [audio]="Onboard alsa audio interface" @@ -78,6 +83,7 @@ declare -A REF_NAMES=( [i2s]="I2S interface" [lirc-rpi]="RPi LIRC support" [pi3-disable-wifi]="RPi3 onboard WiFi" + [pwr_led_activelow]="Power (Red) LED" [spi]="SPI interface" [start_x]="RPi Camera" [vc4-fkms-v3d]="VC4 Mesa/Dispmanx" @@ -1032,6 +1038,43 @@ selinux_enable() } +led_ask() +{ + if [[ "$1" = ACT ]]; then + LED=act + LED_SYS=led0 + elif [[ "$1" = PWR ]]; then + LED=pwr + LED_SYS=led1 + fi + + dtp_ask "$LED"_led_activelow --reverse + if [[ $BAILED -ne 1 ]]; then + if [[ $OPT_DISABLED -ne 1 ]]; then + dtp_enable "$LED"_led_activelow + dtp_enable "$LED"_led_trigger + echo 0 >/sys/class/leds/$LED_SYS/brightness + echo none >/sys/class/leds/$LED_SYS/trigger + if echo $RPI_MODEL |grep -c "Pi 3" &>/dev/null && [[ "$1" = PWR ]]; then + systemctl enable pi3_disable_pwr_led.service &>/dev/null + fi + else + dtp_disable "$LED"_led_activelow + dtp_disable "$LED"_led_trigger + echo 1 >/sys/class/leds/$LED_SYS/brightness + if [[ "$1" = ACT ]]; then + echo mmc0 >/sys/class/leds/$LED_SYS/trigger + fi + if echo $RPI_MODEL |grep -c "Pi 3" &>/dev/null && [[ "$1" = PWR ]]; then + systemctl disable pi3_disable_pwr_led.service &>/dev/null + fi + fi + fi + + SGST_REBOOT=0 +} + + menu_rpi2_oc() { rpi_req 2 @@ -1081,6 +1124,25 @@ menu_bootsplash() } +menu_led() +{ + local MENU_TITLES=( + "ACT/PWR LEDs" "Choose LED Options") + + local MENU_BUTTONS=("Select" "Cancel") + + local MENU_ITEMS=( + "1. ACT LED" "Enable/disable green activity (ACT) LED" + "2. ACT LED" "Enable/disable red power (PWR) LED") + + declare -A MENU_ACTIONS=( + [${MENU_ITEMS[0]}]="led_ask ACT ; break" + [${MENU_ITEMS[2]}]="led_ask PWR ; break") + + dialog_menu $MENU_ARGS +} + + menu_selinux() { sys_info # Get SE_MODE @@ -1311,19 +1373,21 @@ menu_system() local MENU_ITEMS=( "1. Set Boot Kernel" "Select kernel to use for booting the system" "2. Bootsplash" "Enable/disable plymouth graphical bootsplash" - "3. SELinux" "Configure SELinux options" - "4. Add Swap File" "Add and enable a swap file" - "5. Expand Root FS" "Expand (grow) root filesystem on SD card" - "6. Overclock RPi2" "Configure overclocking for RPi2" + "3. ACT/PWR LED's" "Enable/disable ACT/PWR LED's" + "4. SELinux" "Configure SELinux options" + "5. Add Swap File" "Add and enable a swap file" + "6. Expand Root FS" "Expand (grow) root filesystem on SD card" + "7. Overclock RPi2" "Configure overclocking for RPi2" ) declare -A MENU_ACTIONS=( [${MENU_ITEMS[0]}]=menu_kernel [${MENU_ITEMS[2]}]=menu_bootsplash - [${MENU_ITEMS[4]}]=menu_selinux - [${MENU_ITEMS[6]}]=menu_swap - [${MENU_ITEMS[8]}]=rootfs_ask - [${MENU_ITEMS[10]}]=menu_rpi2_oc + [${MENU_ITEMS[4]}]=menu_led + [${MENU_ITEMS[6]}]=menu_selinux + [${MENU_ITEMS[8]}]=menu_swap + [${MENU_ITEMS[10]}]=rootfs_ask + [${MENU_ITEMS[12]}]=menu_rpi2_oc ) dialog_menu $MENU_ARGS diff --git a/fedberry-config.spec b/fedberry-config.spec index 6a1fa71..e0ac961 100644 --- a/fedberry-config.spec +++ b/fedberry-config.spec @@ -14,6 +14,7 @@ Source2: https://raw.githubusercontent.com/%{bname}/%{name}/master/README.md Source3: https://raw.githubusercontent.com/%{bname}/%{name}/master/rootfs-grow.service Source4: https://raw.githubusercontent.com/%{bname}/%{name}/master/%{name}.desktop Source5: https://raw.githubusercontent.com/%{bname}/%{name}/master/%{name}.svg +Source6: https://raw.githubusercontent.com/%{bname}/%{name}/master/pi3_disable_pwr_led.service BuildArch: noarch Obsoletes: rootfs-resize Conflicts: rootfs-resize @@ -51,7 +52,7 @@ rm -rf %{buildroot} %{__install} -p %{name} %{buildroot}/%{_sbindir} %{__install} -d %{buildroot}/%{_unitdir} -%{__install} -p rootfs-grow.service %{buildroot}/%{_unitdir} +%{__install} -p *.service %{buildroot}/%{_unitdir} %{__install} -d %{buildroot}/%{_datadir}/applications %{__install} -p %{name}.desktop %{buildroot}/%{_datadir}/applications @@ -67,16 +68,19 @@ rm -rf %{buildroot} %post %systemd_post rootfs-grow.service +%systemd_post pi3_disable_pwr_led.service touch --no-create %{_datadir}/icons/hicolor || : %{_bindir}/gtk-update-icon-cache --quiet %{_datadir}/icons/hicolor || : %preun %systemd_preun rootfs-grow.service +%systemd_preun pi3_disable_pwr_led.service %postun %systemd_postun rootfs-grow.service +%systemd_postun pi3_disable_pwr_led.service touch --no-create %{_datadir}/icons/hicolor || : %{_bindir}/gtk-update-icon-cache --quiet %{_datadir}/icons/hicolor || : @@ -85,7 +89,7 @@ touch --no-create %{_datadir}/icons/hicolor || : %doc README.md README.html %license LICENSE %attr(0755,root,root) %{_sbindir}/%{name} -%attr(0644,root,root) %{_unitdir}/rootfs-grow.service +%attr(0644,root,root) %{_unitdir}/*.service %attr(0755,root,root) %{_datadir}/applications/%{name}.desktop %attr(0755,root,root) %{_datadir}/icons/hicolor/scalable/apps/%{name}.svg diff --git a/pi3_disable_pwr_led.service b/pi3_disable_pwr_led.service new file mode 100644 index 0000000..0a42cbd --- /dev/null +++ b/pi3_disable_pwr_led.service @@ -0,0 +1,15 @@ +[Unit] +Description=Disable Power LED on the RPi3 +DefaultDependencies=no +After=sysinit.target local-fs.target +Before=basic.target + +[Service] +Environment=TERM=linux +Type=simple +ExecStart=/bin/sh -c 'echo 0 >/sys/class/leds/led1/brightness' +StandardError=syslog +RemainAfterExit=no + +[Install] +WantedBy=multi-user.target