Skip to content

Commit

Permalink
remove duplicated code
Browse files Browse the repository at this point in the history
  • Loading branch information
esmil committed Jan 17, 2012
1 parent 07467f5 commit c29fe67
Showing 1 changed file with 6 additions and 42 deletions.
48 changes: 6 additions & 42 deletions drinkomatic.lua
Original file line number Diff line number Diff line change
Expand Up @@ -88,48 +88,6 @@ end

--- declare states ---

IDLE = {
card = login,

barcode = function(code)
print(" Price check..")

local r = assert(db:fetchone(
"SELECT name, price FROM products WHERE barcode = ?", code))
if r == true then
print " Unknown product."
return 'MAIN'
end

product_dump(r)
return 'MAIN'
end,

keyboard = {
['*'] = function()
main_menu()
return 'MAIN'
end,
['1'] = function()
print " Please enter user name (or press enter to abort):"
return 'NEWUSER_NAME'
end,
['2'] = function()
print(" Scan barcode (or press enter to abort):")
return 'PROD_CODE'
end,
[''] = function()
print(" ENTAR!")
return 'MAIN'
end,
function(cmd) --default
print(" Unknown command '%s'.", cmd)
main_menu()
return 'MAIN'
end,
},
}

MAIN = {
wait = timeout,
timeout = idle,
Expand Down Expand Up @@ -175,6 +133,12 @@ MAIN = {
},
}

IDLE = {
card = MAIN.card,
barcode = MAIN.barcode,
keyboard = MAIN.keyboard,
}

NEWUSER_NAME = {
wait = 120, -- allow 2 minutes for typing account name
timeout = function()
Expand Down

0 comments on commit c29fe67

Please sign in to comment.