Skip to content

Instantly share code, notes, and snippets.

@aenniw
Last active September 4, 2018 18:08
Show Gist options
  • Save aenniw/c74958f8e9ed7f8642c15de98bf57881 to your computer and use it in GitHub Desktop.
Save aenniw/c74958f8e9ed7f8642c15de98bf57881 to your computer and use it in GitHub Desktop.
Volumio for OrangePiZero
verbosity=1
logo=disabled
console=both
disp_mode=1920x1080p60
overlay_prefix=sun8i-h3
overlays=i2c0 usbhost2 usbhost3 spi-spidev
param_spidev_spi_bus=1
rootdev=/dev/mmcblk0p2
rootfstype=ext4
user_overlays=sun8i-h3-i2s0
usbstoragequirks=0x2537:0x1066:u,0x2537:0x1068:u
extraargs=imgpart=/dev/mmcblk0p2 imgfile=/volumio_current.sqsh
#include <stdio.h>
#include <wiringPi.h>
int button_pins[] = {6, 7, 8, 9};
int button_states[] = {LOW, LOW, LOW, LOW};
const char *button_cmds[] = {
"volumio previous",
"curl -m 1 localhost:3000/api/v1/commands/?cmd=pause",
"volumio next",
"if volumio status | grep status | grep -q play; then curl -m 1 localhost:3000/api/v1/commands/?cmd=pause; else volumio play; fi"};
void scanButton(int i)
{
int state = digitalRead(button_pins[i]);
if (state == HIGH)
{
button_states[i] = HIGH;
return;
}
if (button_states[i] == LOW)
return;
button_states[i] = state;
printf("Pressed %d %d\n", button_pins[i], button_states[i]);
system(button_cmds[i]);
}
int main(void)
{
wiringPiSetup();
for (int i = 0; i < 4; ++i)
{
pinMode(button_pins[i], INPUT);
pullUpDnControl(button_pins[i], PUD_UP);
}
for (;;)
{
for (int i = 0; i < 4; ++i)
{
scanButton(i);
}
delayMicroseconds(1000);
}
}
#!/bin/bash
# DEPENDENCIES
# apt-get -y install fbi curl
# PINOUT: Display -> Raspberry Pi Zero
# BL -> pin 12 (GPIO 18)
# SCK -> pin 23 (GPIO 11)
# MISO -> pin 21 (GPIO 9)
# MOSI -> pin 19 (GPIO 10)
# CS -> pin 24 (GPIO 8)
# RST -> pin 22 (GPIO 25)
# D/C -> pin 18 (GPIO 24)
# VIN -> pin 17 (3.3v)
# GND -> pin 20 (GND)
# PINOUT: Display -> Orange Pi Zero
# BL -> pin 15 (GPIO 3)
# SCK -> pin 23 (GPIO 14)
# MOSI -> pin 19 (GPIO 15)
# CS -> pin 24 (GPIO 13)
# RST -> pin 11 (GPIO 1)
# D/C -> pin 13 (GPIO 0)
# VIN -> pin 2 (3.3v)
# GND -> pin 20 (GND)
VERBOSE=${VERBOSE:-false}
VOLUMIO_HOST="http://localhost:3000"
ALBUM_ART_FILE="/tmp/albumart.image"
DEFAULT_ALBUM_ART_FILE="${ALBUM_ART_FILE}.default"
FB=/dev/fb0
function hasBinary() {
for arg in $@; do
hash ${1} || ( echo "Missing binary ${1}"; exit 1);
done
}
function restApiGet() {
curl "${VOLUMIO_HOST}/api/v1/getstate" 2> /dev/null | jq -r "${1}"
}
function downloadAlbumArt() {
curl ${1} > ${2} 2> /dev/null
}
hasBinary fbi curl
lsmod | grep -q fbtft_device || \
modprobe fbtft_device custom name=fb_ili9341 gpios=reset:1,dc:0,led:3 speed=16000000 fps=25 rotate=90 busnum=1
# opi-zero modprobe fbtft_device custom name=fb_ili9341 gpios=reset:1,dc:0,led:3 speed=16000000 fps=25 rotate=90 busnum=1
# rpi-zero modprobe fbtft_device custom name=fb_ili9341 gpios=reset:25,dc:24,led:7 speed=16000000 bgr=1 rotate=90
LAST_TRACK='none'
test -f ${DEFAULT_ALBUM_ART_FILE} || \
downloadAlbumArt "${VOLUMIO_HOST}/albumart" ${DEFAULT_ALBUM_ART_FILE}
fbi -d ${FB} -T 1 -noverbose -a ${DEFAULT_ALBUM_ART_FILE} 2> /dev/null
while [[ true ]]; do
sleep 1
CUR_TRACK=`restApiGet '.title,.artist,.album'`
if [[ "${LAST_TRACK}" == "${CUR_TRACK}" ]]; then
[ "${VERBOSE}" == "true" ] && echo -e "$(date)\tSkipping no change."
continue
else
LAST_TRACK=${CUR_TRACK}
fi
STATUS=`restApiGet '.status'`
if [[ "${STATUS}" == "play" ]] || [[ "${STATUS}" == "pause" ]]; then
[ "${VERBOSE}" == "true" ] && echo -e "$(date)\tDownloading current albumart."
ALBUM_ART_URI=`restApiGet '.albumart'`
echo ${ALBUM_ART_URI} | grep "^/albumart?" && ALBUM_ART_URI="${VOLUMIO_HOST}${ALBUM_ART_URI}"
downloadAlbumArt ${ALBUM_ART_URI} ${ALBUM_ART_FILE}
fbi -d ${FB} -T 1 -noverbose -a ${ALBUM_ART_FILE} 2> /dev/null || LAST_TRACK=''
else
[ "${VERBOSE}" == "true" ] && echo -e "$(date)\tChanging to stock albumart."
fbi -d ${FB} -T 1 -noverbose -a ${DEFAULT_ALBUM_ART_FILE} 2> /dev/null
fi
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment