Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Flash LEDs on Button Click ? #97

Open
idowens opened this issue Jun 9, 2023 · 0 comments
Open

Flash LEDs on Button Click ? #97

idowens opened this issue Jun 9, 2023 · 0 comments
Assignees
Labels
enhancement New feature or request

Comments

@idowens
Copy link

idowens commented Jun 9, 2023

Is your feature request related to a problem? Please describe.
I'm trying to script a .sh or .py script that will flash the PiSugar 2 Pro LED based on the current batter life (0-19% 1 flash, 20-39% 2 flash, ... , 79-100% OR charging=true is 5 flashes.

Shown below is the code I'm trying to execute on "single button click" but it's not getting me very far. I'm almost positive it's because it has no idea what to do with "flash_led" command--I'm just using it as a placeholder at the moment.

Best I can tell from reverse-engineering a little bit, I'm going to have to send signals or breaks to the GPIO that controls the LED? Any input would be appreciated.

#!/bin/bash

flash_led() {
    for ((i=0; i<$1; i++)); do
        sudo python3 /path/to/flash_led.sh
    done
}

check_battery_status() {
    battery_output=$(echo "get battery" | nc -U /tmp/pisugar-server.sock)
    charging_output=$(echo "get battery_charging" | nc -U /tmp/pisugar-server.sock)

    battery_percentage=$(echo "$battery_output" | tr -d '\r' | awk '{print $1}')
    is_charging=$(echo "$charging_output" | tr -d '\r' | awk '{print tolower($1)}')

    if [[ $battery_percentage -ge 0 && $battery_percentage -le 19 ]]; then
        flash_led 1
    elif [[ $battery_percentage -ge 21 && $battery_percentage -le 39 ]]; then
        flash_led 2
    elif [[ $battery_percentage -ge 40 && $battery_percentage -le 59 ]]; then
        flash_led 3
    elif [[ $battery_percentage -ge 60 && $battery_percentage -le 79 ]]; then
        flash_led 4
    elif [[ $battery_percentage -ge 80 || $is_charging == "true" ]]; then
        flash_led 5
    fi
}

check_battery_status
@idowens idowens added the enhancement New feature or request label Jun 9, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants