Update instructions, turn oled off after idle delay

This commit is contained in:
ABelliqueux 2024-04-08 18:30:16 +02:00
parent 6a049ff665
commit 303d55dc85
2 changed files with 31 additions and 7 deletions

View File

@ -57,6 +57,7 @@ for BTN in BTNS:
GPIO.setup(BTNS[BTN]['GPIO'], GPIO.IN, pull_up_down=GPIO.PUD_UP)
# SSD1306 setup - bouding box is (0, 0, 127, 63), 128x64
# TODO : Set an idle_display timer and run device.hide()/device.show() according to value
# GPIOS 2, 3
serial = i2c(port=1, address=0x3C)
device = ssd1306(serial)
@ -350,6 +351,8 @@ def send_mpd_cmd(client, cmd:str, ui_state:dict):
def main(args):
# Idle timer
ui_idle_for = 0
# Pot_cap
# Connect to Pi.
pi = pigpio.pi()
@ -397,14 +400,14 @@ def main(args):
s, v, r = pc.read()
if s and r < 4:
volume = round(v*vol_mult)
# ~ print("{} {}".format(v_1, v_2))
if (abs(volume - v_1) > 1) and (abs(volume - v_2) > 2):
client.setvol(volume)
# ~ print("Volume: {}".format(volume))
print("Volume: {}".format(volume))
if volume < min_val:
volume = 0
if volume > 100:
volume = 100
client.setvol(100-volume)
ui_idle_for = 0
v_2 = v_1
v_1 = volume
# MPD
@ -412,7 +415,7 @@ def main(args):
if len(mpd_status):
mpd_client_status = mpd_status
mpd_client_currentsong = client.currentsong()
print(mpd_client_status['volume'])
#print(mpd_client_status['volume'])
if 'state' in mpd_client_status:
play_state = mpd_client_status['state']
if 'songid' in mpd_client_status:
@ -447,12 +450,22 @@ def main(args):
if (GPIO.input(BTNS[BTN]['GPIO']) == 0) and (GPIO.input(BTNS[BTN]['GPIO']) != BTNS[BTN]['state']):
ui_state = send_mpd_cmd(client, MODES[current_mode][BTN]['FUNCTION'], ui_state)
print("{} pressed".format(MODES[current_mode][BTN]['FUNCTION']))
# Reset idle timer
ui_idle_for = 0
# Save previous state
BTNS[BTN]['state'] = GPIO.input(BTNS[BTN]['GPIO'])
if (GPIO.input(BTNS[BTN]['GPIO']) == 1) and (GPIO.input(BTNS[BTN]['GPIO']) != BTNS[BTN]['state']):
# Save previous state
BTNS[BTN]['state'] = GPIO.input(BTNS[BTN]['GPIO'])
update_display(device, mpd_client_currentsong, mpd_client_status, current_mode, ui_state['cursor_pos'])
if int(ui_idle_for) < 10:
ui_idle_for += .2
device.show()
update_display(device, mpd_client_currentsong, mpd_client_status, current_mode, ui_state['cursor_pos'])
elif int(ui_idle_for) == 10:
print("Ui idle for 10 seconds, suspending display...")
# Avoid further execution
ui_idle_for = 11
device.hide()
# pot_cap
pc.cancel() # Cancel the reader.
pi.stop() # Disconnect from Pi.

View File

@ -12,7 +12,16 @@ This python script is supposed to run on a rpi and does the following :
### Software
1. Install the latest **light** version of Raspberry Pi OS and run it on the RPI model of your choice.
2. Install the following dependencies
2. Install the following dependencies (these are for mpd, the python script and filesystem handling):
```
sudo apt install --no-install-recommends --no-install-suggests mpd gvfs-fuse gvfs-backends gvfs libglib2.0-bin python3-musicpd python3-luma.oled i2c-tools python3-pil libjpeg-dev zlib1g-dev libfreetype6-dev liblcms2-dev libopenjp2-7 libtiff5-dev exfat-fuse
```
3. Configure '~/.config/mpd/mpd.conf' as you please and enable mpd systemd unit :
```
systemctl --user --full enable mpd
```
4. See [Installing the systemd service](#installing-the-systemd-service) for installing the mpdlistenpy systemd service and start/enable it.
5. See [Automounting Samba shares on startup](#automounting-samba-shares-on-startup) for setting up an automount service and start/enable it.
### Hardware
@ -119,7 +128,9 @@ You can find out more about installing 'pigpio' here :
### Automounting Samba shares on startup
[](gist)
If you want to setup a systemd service that mounts smb shares on startup, follow these instructions :
[Automount SMB shares on startup](gist)
*source :* [https://root.nix.dk/en/utility-scripts/mount-samba-share-as-user](https://root.nix.dk/en/utility-scripts/mount-samba-share-as-user)