-
Notifications
You must be signed in to change notification settings - Fork 0
/
menu.sh
executable file
·235 lines (182 loc) · 5.14 KB
/
menu.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
#!/bin/bash
# Written by Vince Loschiavo
# March 1st, 2017
# Caution - beta: work in progress....
# This is a menu handler for vloradio (Raspberry Pi based Pandora Player with LCD, Rotary Encoder, push buttons, and infrared remote)
# When the Menu is called initially, Draw the first two lines of the menu
# Keep track of menu position via environment variables to survive subsequent calls and redraw the screen with the current menu item
# on the first line of the LCD and the next item on the second line.
##################################################################
# Import config
if [ -z $SCRIPTSBASEDIR ]
then
export SCRIPTSBASEDIR="/home/vloschiavo/src/vloradio"
fi
# Import configs
. ${SCRIPTSBASEDIR}/config.sh
MENUCTL=${EPHEMERAL}/menuctl
. ${MENUCTL}
##################################################################
##################################################################
# Define Variables
# Button timeout interval
INTERVAL=6
# Menus
Menus=("MainMenu" "TemperatureMenu" "SystemMenu")
# Menu items:
MainMenu=("Change Station" "Temperature Data" "System Control" "Test Message")
# Temperature Sub Menu of Main Menu:
TemperatureMenu=("Room Temp/Humid" "CPU Temp")
# System Sub Menu of Main Menu:
SystemMenu=("Shutdown" "")
# Button Pressed on remote (passed in from irexec)
BUTTON=$1
##################################################################
##################################################################
# Functions:
##################################################################
# Display current menu item and next menu item
DISPLAYMENU(){
# Displays menu and keeps track of where in the menu we are
# Get the name of the current Menu
menuName=${Menus[$selectedMenu]}
# Copy the array into a temporary array - elements to be dereferenced later
currentMenu=("${MainMenu[@]}")
# Display the selected item and the next item
# Make sure we're inbounds (compare against the size of the array and 0)
if [ "$selectedItem" -ge "${#currentMenu[@]}" ] || [ "$selectedItem" -lt 0 ]; then
export selectedItem=0
nextItem=$selectedItem+1;
echo "ge set si=0"
elif [ "$selectedItem" -eq "${#currentMenu[@]}" ]; then
nextItem=0
echo "eq, set ni=0"
else
nextItem=$selectedItem+1;
echo "ni=si+1"
fi
echo $selectedItem
./DisplayLCDMessage.py ">${currentMenu[$selectedItem]}" "-${currentMenu[$nextItem]}";
# Update the button push time
SETBUTTONPUSHTIME
}
# Stores list of stations in array
READSTATIONS(){
# This function stores the stations and it's associated number to be called later
# i.e. ${StationNumber[2]} is pianobar's number for Station Name: ${StationName[2]}
# Sets IFS to the default and reads the Station Numbers
IFS=$' \t\n'
StationNumber=($(cut -d: -f1 ${EPHEMERAL}/stationList))
# Put station names into array (including spaces in station names)
IFS=$'\n'
StationName=($(cut -d':' -f2 ${EPHEMERAL}/stationList))
# Reset the Internal Field Separator
IFS=$' \t\n'
}
SETBUTTONPUSHTIME(){
# Store the button pushed time in seconds since Epoch
export BUTTONPUSHTIME=`date +%s`
}
#Check to see if the timeout has expired.
CHECKTIMEOUT(){
# Get the current time in seconds since Epoch
CURRENTTIME=`date +%s`
# If current time minus previous time less then the interval then do the thing
if (("$CURRENTSECONDS" - "$PREVIOUSSECONDS" <= "$INTERVAL"))
then
INMENU=1
# Timeout expired - it's been too long since user pressed a remote button
else
INMENU=0
# Redraw Now Playing:
fi
}
##################################################################
# Begin Main
##################################################################
#
#
# goes into case statement
# Press Menu
# Call Display Menu function
#
# Press KEY_CHANNELDOWN
# increment menu item counter
# DISPLAYMENU
#
# Press KEY_CHANNELUP
# decrement menu item counter
# DISPLAYMENU
#
# Press Enter Key within timelimit (5 sec?)
# activate current menu item
# DISPLAYMENU if it's a new menu/sub-menu
#
#
##################################################################
case "$BUTTON" in
MENU)
DISPLAYMENU
;;
CH+)
echo $selectedItem
((selectedItem+=1))
echo $selectedItem
export selectedItem
DISPLAYMENU
;;
esac
# ((selectedItem++)) / ((selectedItem--))
#case "$BUTTON" in
# If BUTTONPUSHTIME is null (never set)
#if [ -z "$BUTTONPUSHTIME" ]; then
# Menu was never called so user pressed wrong button on remote
# exit;
#fi
# MENU)
# CH+)
# # Increment
# if [ "$selectedMenu" -lt ${#MainMenu[@]} -a -ge 0 ]; then
# # show the menu
# else
# $selectedMenu=0
# fi
# ;;
#
# CH-)
# # Stuff
#
# ;;
#
# ENTER)
# # Stuff
#
# ;;
#
# RETURN)
# # Stuff
#
# ;;
# esac
# Check if we're in the menu and within the timeout
#CHECKTIMEOUT
##################################################################
##########################
##!/bin/bash
#
#configFile=./crap.sh
#
#. $configFile
#
#writeConfig() {
# key=$1
# [ -z "$key" ] && return
# value=$2
# sed -i "/$key=/c\\$key=$value" $configFile
# Remove in favor of creating the file on boot # [ -z "$( grep $key= $configFile )" ] && echo "$key=$value" > $configFile
#}
#
#
#[ -n "$1" ] && {
# writeConfig $@
#}