-assert bcm2835_init else print "Failed to init"
-
-# drop privileges!
-var user_group = opt_ug.value
-if user_group != null then user_group.drop_privileges
-
-# Debug LED
-var out = new RPiPin.p1_11
-out.fsel = new FunctionSelect.outp
-out.write(false)
-
-# Play button
-var inp = new RPiPin.p1_13
-inp.fsel = new FunctionSelect.inpt
-inp.pud = new PUDControl.down
-
-# Vol +
-var vol3 = new RPiPin.p1_03
-vol3.fsel = new FunctionSelect.inpt
-vol3.pud = new PUDControl.up
-
-# Vol -
-var vol5 = new RPiPin.p1_05
-vol5.fsel = new FunctionSelect.inpt
-vol5.pud = new PUDControl.up
-
-var vol = new RotaryEncoder(vol3,vol5)
-var vol_step = 2
-
-# LCD
-var lcd_rs = new RPiPin.p1_23
-var lcd_en = new RPiPin.p1_21
-var lcd_d4 = new RPiPin.p1_19
-var lcd_d5 = new RPiPin.p1_26
-var lcd_d6 = new RPiPin.p1_24
-var lcd_d7 = new RPiPin.p1_22
-var lcd = new HD44780(lcd_rs, lcd_en, lcd_d4, lcd_d5, lcd_d6, lcd_d7)
-lcd.setup
-lcd.clear
-
-var last_in = false
-var led_on = false
-var tick = 0
-loop
- var force_lcd_update = false
-
- # play button
- var lev = inp.lev
- if lev != last_in then
- last_in = lev
- if lev then
- print "hps"
- hit_play_stop
- end
- end
-
- # volume
- var s = vol.update
- if s != null then
- if s == '<' then
- print "vol down"
- mpd.relative_volume = -vol_step
- else # >
- print "vol up"
- mpd.relative_volume = vol_step
- end
- force_lcd_update = true
- end
-
- # update lcd
- if tick % 100 == 0 or force_lcd_update then
- var status = mpd.status
- var song = mpd.current_song
-
- var status_char
- if status == null then
- lcd.text = "Unknown status"
- else if song == null then
- lcd.text = "No song playing"
- else
- if status.playing then
- status_char = ">"
- else status_char = "#"
-
- var tr = status.time_ratio
- var pos = "-"
- if tr != null then pos = (status.time_ratio*10.0).to_i.to_s
-
- lcd.text = "{status_char} {song.artist}\n{pos} {song.title}"
- end
- end
-
- 10.bcm2835_delay
- tick += 1
-end