<h3 id="code">Code</h3>
<p>The script being discussed in this show is available for download with the previous show: <a href="https://hackerpublicradio.org/eps/hpr2951/cad-menu.py">cad-menu.py</a></p>
<h3 id="functions">Functions</h3>
<ul>
<li><p><code>def button0(event):</code><br />
Play / Pause Button<br />
Print message to lcd and toggle between play and pause for podcasts, then runs <code>init_display</code> to display available options</p></li>
<li><p><code>def button1(event):</code><br />
Track Information button<br />
Print message to lcd then display current moc track information such as moc state, current time, time left, current playlist number of total playlist number &amp; podcast title.<br />
<br />
Example output from command <code>mocp --info</code></p>
<pre><code>State: PAUSE
File: /home/pi/files/mp3/hpr1597.mp3
Title: Steve Smethurst - HPR1597: Extravehicular Activity (Hacker Public Radio)
Artist: Steve Smethurst
SongTitle: HPR1597: Extravehicular Activity
Album: Hacker Public Radio
TotalTime: 14:11
TimeLeft: 02:47
TotalSec: 851
CurrentTime: 11:24
CurrentSec: 684
Bitrate: 64kbps
AvgBitrate: 64kbps
Rate: 44kHz</code></pre></li>
<li><p><code>def button2(event):</code><br />
Previous Track Button<br />
Button is only active if button is pushed twice within 0.3 seconds. This was added to stop moving to a new track by accidental pushing of button. If menu = 0 or 1 and value of variable TimeDiff is less than 0.3 then Print message to lcd and move to previous track in playlist. If menu = 2 and button pressed twice within 0.3 then display number of HPR shows in the queue</p></li>
<li><p><code>def button3(event):</code><br />
Next track Button<br />
Button is only active if button is pushed twice within 0.3 seconds. This was added to stop moving to a new track by accidental pushing of button. If menu = 0 or 1 and value of variable TimeDiff is less than 0.3 then Print message to lcd and move to next track in playlist Button currently has no function if menu = 2</p></li>
<li><p><code>def button4(event):</code><br />
Toggle backlight Button<br />
If 1st time button is pushed then turn off blinkstick and display main menu else Toggle lcd backlight between on and off</p></li>
<li><p><code>def moc_seek():</code><br />
Used to seek backward or forward in track being played in mocp SeekPosition is a global variable used to store the current seek position, its value changes up and down when using button6 and button7</p></li>
<li><code>def button5(event):</code><br />
Jogg switch<br />
This button is selected by momentarily pushing in the left/right toggle button. Button located on the top of unit<br />

<ul>
<li>If menu equals 0 or 1, [PODCASTS or AUDIOBOOKS] menu then<br />

<ul>
<li>if not in seek menu then display seek menu</li>
<li>if in seek menu then jump forward or back in track by the amount currently displayed on the seek menu, uses function <code>moc_seek()</code></li>
</ul></li>
<li>If menu equals 2, [SYSTEM] menu then
<ul>
<li>Get date and time information, Clear screen, turn on LCD backlight print the shutdown message with date and time info to lcd &amp; then issue the shutdown command</li>
</ul></li>
</ul></li>
</ul>
<!-- -->
<ul>
<li><code>def button6(event):</code><br />
Left Jogg switch decrement through menus also used during seek<br />
This button is selected by momentarily pushing the toggle switch to the left. Button located on the top of unit<br />
Button only active if more than 0.3 seconds has passed since it was last pushed, this was added to get around switch bounce causing multiple jumps in menu, think left and right jogg switch is a bit noisy.
<ul>
<li>If in seek menu
<ul>
<li>SeekPosition decrements by one until SeekMin is reached, and then returns to 0</li>
<li>each time the display is updated with the decremented value stored in dictionary SeekDisplay</li>
</ul></li>
<li>If not in seek menu
<ul>
<li>Menu decrements down by one until MenuMin is reached then rolls over to MenuMax</li>
</ul></li>
</ul></li>
<li><p><code>def button7(event):</code><br />
Same as button6 above but instead increments value, i.e. menu or seek value is incremented by 1</p></li>
<li><p><code>def print_ir_code(event):</code><br />
Used during debugging to get remote control working, came from piface examples page, prints IR code <code>print(event.ir_code)</code></p></li>
<li><p><code>def ir_play(event):</code><br />
If the play button is pushed on the remote control twice within 0.5 seconds and if IR is active then toggle backlight and toggle between play and pause</p></li>
<li><p><code>def ir_info(event):</code><br />
If the info button (pause) is pushed on the remote control twice within 0.5 seconds and if IR is active then toggle backlight and display on the LCD information about the current track</p></li>
<li><p><code>def ir_rewind(event):</code><br />
If the rewind button is pushed on the remote control and if IR is active then toggle backlight and go to previous track on playlist</p></li>
<li><p><code>def ir_forward(event):</code><br />
If the forward button is pushed on the remote control and if IR is active then toggle backlight and go to next track on playlist</p></li>
<li><p><code>def ir_stop(event):</code><br />
If the stop button is pushed on the remote control and if IR is active then toggle backlight</p></li>
<li><p><code>def ir_blue(event):</code><br />
Activate and deactivate IR buttons on the remote control, turns blinkstick on red when IR active. When blue button is pushed twice within 0.5 seconds on remote control, toggle backlight and display momentary message on LCD display giving IR status i.e. are the remote control buttons active or deactive.<br />
<br />
All remote buttons bar this one are affected. This feature was added to remotely disable all the buttons while using the TV remote control media buttons these would sometimes falsely trigger things<br />
<br />
The double push of the blue button within 0.5 seconds was added as sometimes a single push of it was required on my TV and this would falsely activate it<br />
<br />
Feature added to check if var FirstPass is set to true, i.e. backlight button4 has not pushed since boot<br />
<br />
button4 normally toggles backlight but turns off hpr queue LED first time it’s pushed after boot.</p></li>
</ul>
