Skip to content

Commit

Permalink
Added controls for hall light to index view.
Browse files Browse the repository at this point in the history
  • Loading branch information
ndbroadbent committed Dec 27, 2010
1 parent 9bb0a23 commit 2ab5a77
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 36 deletions.
62 changes: 28 additions & 34 deletions octopus_sinatra.rb
Original file line number Diff line number Diff line change
Expand Up @@ -171,56 +171,50 @@ def hall_light_trigger
return ""
end

post '/unlock' do
post '/action' do
# If user can authenticate
user = $users[params[:user]]
if user && user['http_pwd'] && user['http_pwd'] == params[:password]
name = params[:user]
unlock_door_action
lcd_message " HTTP - #{ @env['REMOTE_ADDR'] } ", 1, 20, false
message = "Welcome, #{name.split.first}!"
lcd_message message, 21, 40, true

# Post unlock actions
# ------------------------------------------
shellfm_trigger(name)
hall_light_trigger
else
access_denied_action
lcd_message " HTTP - #{ @env['REMOTE_ADDR'] } ", 1, 20, false
message = " Access Denied."
lcd_message message, 21, 40, true
end

return "<html><body><p>HTTP - #{ @env['REMOTE_ADDR'] }</p><h2>#{message}</h2></body></html>"

end

post '/hall_light' do
# If user can authenticate
user = $users[params[:user]]
# Process requested action.

message = "Nothing Changed."
if user && user['http_pwd'] && user['http_pwd'] == params[:password]
# Kill hall light timed thread, if running
$hall_light_thread.kill if $hall_light_thread
$hall_light_thread = nil
if params[:action].include?("Hall Light")
$hall_light_thread.kill if $hall_light_thread
$hall_light_thread = nil
end

if params[:hall_light] = "ON"
case params[:action]
when "Unlock Door"
name = params[:user]
unlock_door_action
message = "Welcome, #{name.split.first}!"

# Post unlock actions
# ------------------------------------------
shellfm_trigger(name)
hall_light_trigger
when "Turn on Hall Light"
unless $hall_light_on
$k8055.set_digital HallLightChannel, false
$hall_light_on = true
message = "Hall light is now on."
message = "Hall light is on."
end
else
when "Turn off Hall Light"
if $hall_light_on
$k8055.set_digital HallLightChannel, false
$hall_light_on = false
message = "Hall light is now off."
message = "Hall light is off."
end
end

# Display LCD message for action
lcd_message " HTTP - #{ @env['REMOTE_ADDR'] } ", 1, 20, false
lcd_message message, 21, 40, true
else
message = "Access Denied."
access_denied_action
lcd_message " HTTP - #{ @env['REMOTE_ADDR'] } ", 1, 20, false
message = " Access Denied."
lcd_message message, 21, 40, true
end

return "<html><body><p>HTTP - #{ @env['REMOTE_ADDR'] }</p><h2>#{message}</h2></body></html>"
Expand Down
7 changes: 5 additions & 2 deletions views/index.erb
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,16 @@
<p>The time is <%= hk_time_fmt %> - <a href="/gettime">(Update)</a></p>
<p>Please select your name, and enter your password to unlock Flat 10C</p>

<form name="input" action="unlock" method="post">
<form name="input" action="/action" method="post">
User: <select name="user">
<option></option>
<%= user_select_options %>
</select></br>
Password: <input type="password" name="password" />
<input type="submit" value="Unlock" />
<br/>
<input type="submit" name="action" value="Unlock Door" /><br/>
<input type="submit" name="action" value="Turn on Hall Light" /><br/>
<input type="submit" name="action" value="Turn off Hall Light" /><br/>
</form>

</body>
Expand Down

0 comments on commit 2ab5a77

Please sign in to comment.