Skip to content

Commit

Permalink
Add support for enabling/disabling RPi ACT & PWR LEDs
Browse files Browse the repository at this point in the history
  • Loading branch information
agrez committed Dec 16, 2017
1 parent ba2446e commit d381e10
Show file tree
Hide file tree
Showing 3 changed files with 93 additions and 10 deletions.
80 changes: 72 additions & 8 deletions fedberry-config
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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"
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
8 changes: 6 additions & 2 deletions fedberry-config.spec
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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 || :

Expand All @@ -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

Expand Down
15 changes: 15 additions & 0 deletions pi3_disable_pwr_led.service
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit d381e10

Please sign in to comment.