Review line ending handling (#4820)

* New line end handling rules

* Normalize all the line endings
This commit is contained in:
3djc
2017-04-19 10:54:43 +02:00
committed by Bertrand Songis
parent 189b65b724
commit fa951acf40
397 changed files with 252824 additions and 252713 deletions
+340 -340
View File
@@ -1,340 +1,340 @@
local VALUE = 0
local COMBO = 1
local COLUMN_2 = 300
local edit = false
local page = 1
local current = 1
local refreshState = 0
local refreshIndex = 0
local calibrationState = 0
local pageOffset = 0
local calibrationStep = 0
local pages = {}
local fields = {}
local modifications = {}
local wingBitmaps = {}
local mountBitmaps = {}
local calibBitmaps = {}
local configFields = {
{"Wing type:", COMBO, 0x80, nil, { "Normal", "Delta", "VTail" } },
{"Mounting type:", COMBO, 0x81, nil, { "Horz", "Horz rev.", "Vert", "Vert rev." } },
}
local calibrationPositions = { "up", "down", "left", "right", "forward", "back" }
local wingBitmapsFile = {"img/plane_b.png", "img/delta_b.png", "img/planev_b.png"}
local mountBitmapsFile = {"img/up.png", "img/down.png", "img/vert.png", "img/vert-r.png"}
local calibBitmapsFile = {"img/up.png", "img/down.png", "img/left.png", "img/right.png", "img/forward.png", "img/back.png"}
local settingsFields = {
{"S6R functions:", COMBO, 0x9C, nil, { "Disable", "Enable" } },
{"CH5 mode:", COMBO, 0xA8, nil, { "AIL2", "AUX1" } },
{"CH6 mode:", COMBO, 0xA9, nil, { "ELE2", "AUX2" } },
{"AIL direction:", COMBO, 0x82, nil, { "Normal", "Invers" }, { 255, 0 } },
{"ELE direction:", COMBO, 0x83, nil, { "Normal", "Invers" }, { 255, 0 } },
{"RUD direction:", COMBO, 0x84, nil, { "Normal", "Invers" }, { 255, 0 } },
{"AIL2 direction:", COMBO, 0x9A, nil, { "Normal", "Invers" }, { 255, 0 } },
{"ELE2 direction:", COMBO, 0x9B, nil, { "Normal", "Invers" }, { 255, 0 } },
{"AIL stabilize gain:", VALUE, 0x85, nil, 0, 200, "%"},
{"ELE stabilize gain:", VALUE, 0x86, nil, 0, 200, "%"},
{"RUD stabilize gain:", VALUE, 0x87, nil, 0, 200, "%"},
{"AIL auto level gain:", VALUE, 0x88, nil, 0, 200, "%"},
{"ELE auto level gain:", VALUE, 0x89, nil, 0, 200, "%"},
{"ELE upright gain:", VALUE, 0x8C, nil, 0, 200, "%"},
{"RUD upright gain:", VALUE, 0x8D, nil, 0, 200, "%"},
{"AIL crab gain:", VALUE, 0x8E, nil, 0, 200, "%"},
{"RUD crab gain:", VALUE, 0x90, nil, 0, 200, "%"},
{"AIL auto angle offset:", VALUE, 0x91, nil, -20, 20, "%", 0x6C},
{"ELE auto angle offset:", VALUE, 0x92, nil, -20, 20, "%", 0x6C},
{"ELE upright angle offset:", VALUE, 0x95, nil, -20, 20, "%", 0x6C},
{"RUD upright angle offset:", VALUE, 0x96, nil, -20, 20, "%", 0x6C},
{"AIL crab angle offset:", VALUE, 0x97, nil, -20, 20, "%", 0x6C},
{"RUD crab angle offset:", VALUE, 0x99, nil, -20, 20, "%", 0x6C},
}
local calibrationFields = {
{"X:", VALUE, 0x9E, 0, -100, 100, "%"},
{"Y:", VALUE, 0x9F, 0, -100, 100, "%"},
{"Z:", VALUE, 0xA0, 0, -100, 100, "%"}
}
local function drawScreenTitle(title,page, pages)
lcd.drawFilledRectangle(0, 0, LCD_W, 30, TITLE_BGCOLOR)
lcd.drawText(1, 5, title, MENU_TITLE_COLOR)
lcd.drawText(LCD_W-40, 5, page.."/"..pages, MENU_TITLE_COLOR)
end
-- Change display attribute to current field
local function addField(step)
local field = fields[current]
local min, max
if field[2] == VALUE then
min = field[5]
max = field[6]
elseif field[2] == COMBO then
min = 0
max = #(field[5]) - 1
end
if (step < 0 and field[4] > min) or (step > 0 and field[4] < max) then
field[4] = field[4] + step
end
end
-- Select the next or previous page
local function selectPage(step)
page = 1 + ((page + step - 1 + #pages) % #pages)
refreshIndex = 0
calibrationStep = 0
pageOffset = 0
end
-- Select the next or previous editable field
local function selectField(step)
current = 1 + ((current + step - 1 + #fields) % #fields)
if current > 7 + pageOffset then
pageOffset = current - 7
elseif current <= pageOffset then
pageOffset = current - 1
end
end
local function drawProgressBar()
local width = (300 * refreshIndex) / #fields
lcd.drawRectangle(100, 10, 300, 6)
lcd.drawFilledRectangle(102, 13, width, 2);
end
-- Redraw the current page
local function redrawFieldsPage(event)
lcd.clear()
drawScreenTitle("S6R", page, #pages)
if refreshIndex < #fields then
drawProgressBar()
end
for index = 1, 10, 1 do
local field = fields[pageOffset+index]
if field == nil then
break
end
local attr = current == (pageOffset+index) and ((edit == true and BLINK or 0) + INVERS) or 0
attr = attr + TEXT_COLOR
lcd.drawText(1, 30+20*index, field[1], TEXT_COLOR)
if field[4] == nil then
lcd.drawText(COLUMN_2, 30+20*index, "---", attr)
else
if field[2] == VALUE then
lcd.drawNumber(COLUMN_2, 30+20*index, field[4], LEFT + attr)
elseif field[2] == COMBO then
if field[4] >= 0 and field[4] < #(field[5]) then
lcd.drawText(COLUMN_2, 30+20*index, field[5][1+field[4]], attr)
end
end
end
end
end
local function telemetryRead(field)
return sportTelemetryPush(0x17, 0x30, 0x0C30, field)
end
local function telemetryWrite(field, value)
return sportTelemetryPush(0x17, 0x31, 0x0C30, field + value*256)
end
local telemetryPopTimeout = 0
local function refreshNext()
if refreshState == 0 then
if calibrationState == 1 then
if telemetryWrite(0x9D, calibrationStep) == true then
refreshState = 1
calibrationState = 2
telemetryPopTimeout = getTime() + 80 -- normal delay is 500ms
end
elseif #modifications > 0 then
telemetryWrite(modifications[1][1], modifications[1][2])
modifications[1] = nil
elseif refreshIndex < #fields then
local field = fields[refreshIndex + 1]
if telemetryRead(field[3]) == true then
refreshState = 1
telemetryPopTimeout = getTime() + 80 -- normal delay is 500ms
end
end
elseif refreshState == 1 then
local physicalId, primId, dataId, value = sportTelemetryPop()
if physicalId == 0x1A and primId == 0x32 and dataId == 0x0C30 then
local fieldId = value % 256
if calibrationState == 2 then
if fieldId == 0x9D then
refreshState = 0
calibrationState = 0
calibrationStep = (calibrationStep + 1) % 7
end
else
local field = fields[refreshIndex + 1]
if fieldId == field[3] then
local value = math.floor(value / 256)
if field[3] >= 0x9E and field[3] <= 0xA0 then
local b1 = value % 256
local b2 = math.floor(value / 256)
value = b1*256 + b2
value = value - bit32.band(value, 0x8000) * 2
end
if field[2] == COMBO and #field == 6 then
for index = 1, #(field[6]), 1 do
if value == field[6][index] then
value = index - 1
break
end
end
elseif field[2] == VALUE and #field == 8 then
value = value - field[8] + field[5]
end
fields[refreshIndex + 1][4] = value
refreshIndex = refreshIndex + 1
refreshState = 0
end
end
elseif getTime() > telemetryPopTimeout then
refreshState = 0
calibrationState = 0
end
end
end
local function updateField(field)
local value = field[4]
if field[2] == COMBO and #field == 6 then
value = field[6][1+value]
elseif field[2] == VALUE and #field == 8 then
value = value + field[8] - field[5]
end
modifications[#modifications+1] = { field[3], value }
end
-- Main
local function runFieldsPage(event)
if event == EVT_EXIT_BREAK then -- exit script
return 2
elseif event == EVT_ENTER_BREAK or event == EVT_ROT_BREAK then -- toggle editing/selecting current field
if fields[current][4] ~= nil then
edit = not edit
if edit == false then
updateField(fields[current])
end
end
elseif edit then
if event == EVT_PLUS_FIRST or event == EVT_ROT_RIGHT or event == EVT_PLUS_REPT then
addField(1)
elseif event == EVT_MINUS_FIRST or event == EVT_ROT_LEFT or event == EVT_MINUS_REPT then
addField(-1)
end
else
if event == EVT_MINUS_FIRST or event == EVT_ROT_RIGHT then
selectField(1)
elseif event == EVT_PLUS_FIRST or event == EVT_ROT_LEFT then
selectField(-1)
end
end
redrawFieldsPage(event)
return 0
end
local function runConfigPage(event)
fields = configFields
local result = runFieldsPage(event)
if fields[1][4] ~= nil then
if wingBitmaps[1 + fields[1][4]] == nil then
wingBitmaps[1 + fields[1][4]] = Bitmap.open(wingBitmapsFile[1 + fields[1][4]])
end
lcd.drawBitmap(wingBitmaps[1 + fields[1][4]], 10, 90)
end
if fields[2][4] ~= nil then
if mountBitmaps[1 + fields[2][4]] == nil then
mountBitmaps[1 + fields[2][4]] = Bitmap.open(mountBitmapsFile[1 + fields[2][4]])
end
lcd.drawBitmap(mountBitmaps[1 + fields[2][4]], 190, 110)
end
return result
end
local function runSettingsPage(event)
fields = settingsFields
return runFieldsPage(event)
end
local function runCalibrationPage(event)
fields = calibrationFields
if refreshIndex == #fields then
refreshIndex = 0
end
lcd.clear()
drawScreenTitle("S6R", page, #pages)
if(calibrationStep < 6) then
local position = calibrationPositions[1 + calibrationStep]
lcd.drawText(100, 50, "Place the S6R in the following position", TEXT_COLOR)
if calibBitmaps[calibrationStep + 1] == nil then
calibBitmaps[calibrationStep + 1] = Bitmap.open(calibBitmapsFile[calibrationStep + 1])
end
lcd.drawBitmap(calibBitmaps[calibrationStep + 1], 200, 70)
for index = 1, 3, 1 do
local field = fields[index]
lcd.drawText(70, 80+20*index, field[1]..":", TEXT_COLOR)
lcd.drawNumber(90, 80+20*index, field[4]/10, LEFT+PREC2)
end
local attr = calibrationState == 0 and INVERS or 0
lcd.drawText(160, 220, "Press [Enter] when ready", attr)
else
lcd.drawText(160, 50, "Calibration completed", 0)
lcd.drawBitmap(Bitmap.open("img/done.bmp"),200, 100)
lcd.drawText(160, 220, "Press [RTN] when ready", attr)
end
if calibrationStep > 6 and (event == EVT_ENTER_BREAK or event == EVT_EXIT_BREAK) then
return 2
elseif event == EVT_ENTER_BREAK then
calibrationState = 1
elseif event == EVT_EXIT_BREAK then
if calibrationStep > 0 then
calibrationStep = 0
end
end
return 0
end
-- Init
local function init()
current, edit, refreshState, refreshIndex = 1, false, 0, 0
pages = {
runConfigPage,
runSettingsPage,
runCalibrationPage
}
end
-- Main
local function run(event)
if event == nil then
error("Cannot be run as a model script!")
return 2
elseif event == EVT_PAGE_BREAK or event == EVT_PAGEDN_FIRST then
selectPage(1)
elseif event == EVT_PAGE_LONG or event == EVT_PAGEUP_FIRST then
killEvents(event);
selectPage(-1)
end
local result = pages[page](event)
refreshNext()
return result
end
return { init=init, run=run }
local VALUE = 0
local COMBO = 1
local COLUMN_2 = 300
local edit = false
local page = 1
local current = 1
local refreshState = 0
local refreshIndex = 0
local calibrationState = 0
local pageOffset = 0
local calibrationStep = 0
local pages = {}
local fields = {}
local modifications = {}
local wingBitmaps = {}
local mountBitmaps = {}
local calibBitmaps = {}
local configFields = {
{"Wing type:", COMBO, 0x80, nil, { "Normal", "Delta", "VTail" } },
{"Mounting type:", COMBO, 0x81, nil, { "Horz", "Horz rev.", "Vert", "Vert rev." } },
}
local calibrationPositions = { "up", "down", "left", "right", "forward", "back" }
local wingBitmapsFile = {"img/plane_b.png", "img/delta_b.png", "img/planev_b.png"}
local mountBitmapsFile = {"img/up.png", "img/down.png", "img/vert.png", "img/vert-r.png"}
local calibBitmapsFile = {"img/up.png", "img/down.png", "img/left.png", "img/right.png", "img/forward.png", "img/back.png"}
local settingsFields = {
{"S6R functions:", COMBO, 0x9C, nil, { "Disable", "Enable" } },
{"CH5 mode:", COMBO, 0xA8, nil, { "AIL2", "AUX1" } },
{"CH6 mode:", COMBO, 0xA9, nil, { "ELE2", "AUX2" } },
{"AIL direction:", COMBO, 0x82, nil, { "Normal", "Invers" }, { 255, 0 } },
{"ELE direction:", COMBO, 0x83, nil, { "Normal", "Invers" }, { 255, 0 } },
{"RUD direction:", COMBO, 0x84, nil, { "Normal", "Invers" }, { 255, 0 } },
{"AIL2 direction:", COMBO, 0x9A, nil, { "Normal", "Invers" }, { 255, 0 } },
{"ELE2 direction:", COMBO, 0x9B, nil, { "Normal", "Invers" }, { 255, 0 } },
{"AIL stabilize gain:", VALUE, 0x85, nil, 0, 200, "%"},
{"ELE stabilize gain:", VALUE, 0x86, nil, 0, 200, "%"},
{"RUD stabilize gain:", VALUE, 0x87, nil, 0, 200, "%"},
{"AIL auto level gain:", VALUE, 0x88, nil, 0, 200, "%"},
{"ELE auto level gain:", VALUE, 0x89, nil, 0, 200, "%"},
{"ELE upright gain:", VALUE, 0x8C, nil, 0, 200, "%"},
{"RUD upright gain:", VALUE, 0x8D, nil, 0, 200, "%"},
{"AIL crab gain:", VALUE, 0x8E, nil, 0, 200, "%"},
{"RUD crab gain:", VALUE, 0x90, nil, 0, 200, "%"},
{"AIL auto angle offset:", VALUE, 0x91, nil, -20, 20, "%", 0x6C},
{"ELE auto angle offset:", VALUE, 0x92, nil, -20, 20, "%", 0x6C},
{"ELE upright angle offset:", VALUE, 0x95, nil, -20, 20, "%", 0x6C},
{"RUD upright angle offset:", VALUE, 0x96, nil, -20, 20, "%", 0x6C},
{"AIL crab angle offset:", VALUE, 0x97, nil, -20, 20, "%", 0x6C},
{"RUD crab angle offset:", VALUE, 0x99, nil, -20, 20, "%", 0x6C},
}
local calibrationFields = {
{"X:", VALUE, 0x9E, 0, -100, 100, "%"},
{"Y:", VALUE, 0x9F, 0, -100, 100, "%"},
{"Z:", VALUE, 0xA0, 0, -100, 100, "%"}
}
local function drawScreenTitle(title,page, pages)
lcd.drawFilledRectangle(0, 0, LCD_W, 30, TITLE_BGCOLOR)
lcd.drawText(1, 5, title, MENU_TITLE_COLOR)
lcd.drawText(LCD_W-40, 5, page.."/"..pages, MENU_TITLE_COLOR)
end
-- Change display attribute to current field
local function addField(step)
local field = fields[current]
local min, max
if field[2] == VALUE then
min = field[5]
max = field[6]
elseif field[2] == COMBO then
min = 0
max = #(field[5]) - 1
end
if (step < 0 and field[4] > min) or (step > 0 and field[4] < max) then
field[4] = field[4] + step
end
end
-- Select the next or previous page
local function selectPage(step)
page = 1 + ((page + step - 1 + #pages) % #pages)
refreshIndex = 0
calibrationStep = 0
pageOffset = 0
end
-- Select the next or previous editable field
local function selectField(step)
current = 1 + ((current + step - 1 + #fields) % #fields)
if current > 7 + pageOffset then
pageOffset = current - 7
elseif current <= pageOffset then
pageOffset = current - 1
end
end
local function drawProgressBar()
local width = (300 * refreshIndex) / #fields
lcd.drawRectangle(100, 10, 300, 6)
lcd.drawFilledRectangle(102, 13, width, 2);
end
-- Redraw the current page
local function redrawFieldsPage(event)
lcd.clear()
drawScreenTitle("S6R", page, #pages)
if refreshIndex < #fields then
drawProgressBar()
end
for index = 1, 10, 1 do
local field = fields[pageOffset+index]
if field == nil then
break
end
local attr = current == (pageOffset+index) and ((edit == true and BLINK or 0) + INVERS) or 0
attr = attr + TEXT_COLOR
lcd.drawText(1, 30+20*index, field[1], TEXT_COLOR)
if field[4] == nil then
lcd.drawText(COLUMN_2, 30+20*index, "---", attr)
else
if field[2] == VALUE then
lcd.drawNumber(COLUMN_2, 30+20*index, field[4], LEFT + attr)
elseif field[2] == COMBO then
if field[4] >= 0 and field[4] < #(field[5]) then
lcd.drawText(COLUMN_2, 30+20*index, field[5][1+field[4]], attr)
end
end
end
end
end
local function telemetryRead(field)
return sportTelemetryPush(0x17, 0x30, 0x0C30, field)
end
local function telemetryWrite(field, value)
return sportTelemetryPush(0x17, 0x31, 0x0C30, field + value*256)
end
local telemetryPopTimeout = 0
local function refreshNext()
if refreshState == 0 then
if calibrationState == 1 then
if telemetryWrite(0x9D, calibrationStep) == true then
refreshState = 1
calibrationState = 2
telemetryPopTimeout = getTime() + 80 -- normal delay is 500ms
end
elseif #modifications > 0 then
telemetryWrite(modifications[1][1], modifications[1][2])
modifications[1] = nil
elseif refreshIndex < #fields then
local field = fields[refreshIndex + 1]
if telemetryRead(field[3]) == true then
refreshState = 1
telemetryPopTimeout = getTime() + 80 -- normal delay is 500ms
end
end
elseif refreshState == 1 then
local physicalId, primId, dataId, value = sportTelemetryPop()
if physicalId == 0x1A and primId == 0x32 and dataId == 0x0C30 then
local fieldId = value % 256
if calibrationState == 2 then
if fieldId == 0x9D then
refreshState = 0
calibrationState = 0
calibrationStep = (calibrationStep + 1) % 7
end
else
local field = fields[refreshIndex + 1]
if fieldId == field[3] then
local value = math.floor(value / 256)
if field[3] >= 0x9E and field[3] <= 0xA0 then
local b1 = value % 256
local b2 = math.floor(value / 256)
value = b1*256 + b2
value = value - bit32.band(value, 0x8000) * 2
end
if field[2] == COMBO and #field == 6 then
for index = 1, #(field[6]), 1 do
if value == field[6][index] then
value = index - 1
break
end
end
elseif field[2] == VALUE and #field == 8 then
value = value - field[8] + field[5]
end
fields[refreshIndex + 1][4] = value
refreshIndex = refreshIndex + 1
refreshState = 0
end
end
elseif getTime() > telemetryPopTimeout then
refreshState = 0
calibrationState = 0
end
end
end
local function updateField(field)
local value = field[4]
if field[2] == COMBO and #field == 6 then
value = field[6][1+value]
elseif field[2] == VALUE and #field == 8 then
value = value + field[8] - field[5]
end
modifications[#modifications+1] = { field[3], value }
end
-- Main
local function runFieldsPage(event)
if event == EVT_EXIT_BREAK then -- exit script
return 2
elseif event == EVT_ENTER_BREAK or event == EVT_ROT_BREAK then -- toggle editing/selecting current field
if fields[current][4] ~= nil then
edit = not edit
if edit == false then
updateField(fields[current])
end
end
elseif edit then
if event == EVT_PLUS_FIRST or event == EVT_ROT_RIGHT or event == EVT_PLUS_REPT then
addField(1)
elseif event == EVT_MINUS_FIRST or event == EVT_ROT_LEFT or event == EVT_MINUS_REPT then
addField(-1)
end
else
if event == EVT_MINUS_FIRST or event == EVT_ROT_RIGHT then
selectField(1)
elseif event == EVT_PLUS_FIRST or event == EVT_ROT_LEFT then
selectField(-1)
end
end
redrawFieldsPage(event)
return 0
end
local function runConfigPage(event)
fields = configFields
local result = runFieldsPage(event)
if fields[1][4] ~= nil then
if wingBitmaps[1 + fields[1][4]] == nil then
wingBitmaps[1 + fields[1][4]] = Bitmap.open(wingBitmapsFile[1 + fields[1][4]])
end
lcd.drawBitmap(wingBitmaps[1 + fields[1][4]], 10, 90)
end
if fields[2][4] ~= nil then
if mountBitmaps[1 + fields[2][4]] == nil then
mountBitmaps[1 + fields[2][4]] = Bitmap.open(mountBitmapsFile[1 + fields[2][4]])
end
lcd.drawBitmap(mountBitmaps[1 + fields[2][4]], 190, 110)
end
return result
end
local function runSettingsPage(event)
fields = settingsFields
return runFieldsPage(event)
end
local function runCalibrationPage(event)
fields = calibrationFields
if refreshIndex == #fields then
refreshIndex = 0
end
lcd.clear()
drawScreenTitle("S6R", page, #pages)
if(calibrationStep < 6) then
local position = calibrationPositions[1 + calibrationStep]
lcd.drawText(100, 50, "Place the S6R in the following position", TEXT_COLOR)
if calibBitmaps[calibrationStep + 1] == nil then
calibBitmaps[calibrationStep + 1] = Bitmap.open(calibBitmapsFile[calibrationStep + 1])
end
lcd.drawBitmap(calibBitmaps[calibrationStep + 1], 200, 70)
for index = 1, 3, 1 do
local field = fields[index]
lcd.drawText(70, 80+20*index, field[1]..":", TEXT_COLOR)
lcd.drawNumber(90, 80+20*index, field[4]/10, LEFT+PREC2)
end
local attr = calibrationState == 0 and INVERS or 0
lcd.drawText(160, 220, "Press [Enter] when ready", attr)
else
lcd.drawText(160, 50, "Calibration completed", 0)
lcd.drawBitmap(Bitmap.open("img/done.bmp"),200, 100)
lcd.drawText(160, 220, "Press [RTN] when ready", attr)
end
if calibrationStep > 6 and (event == EVT_ENTER_BREAK or event == EVT_EXIT_BREAK) then
return 2
elseif event == EVT_ENTER_BREAK then
calibrationState = 1
elseif event == EVT_EXIT_BREAK then
if calibrationStep > 0 then
calibrationStep = 0
end
end
return 0
end
-- Init
local function init()
current, edit, refreshState, refreshIndex = 1, false, 0, 0
pages = {
runConfigPage,
runSettingsPage,
runCalibrationPage
}
end
-- Main
local function run(event)
if event == nil then
error("Cannot be run as a model script!")
return 2
elseif event == EVT_PAGE_BREAK or event == EVT_PAGEDN_FIRST then
selectPage(1)
elseif event == EVT_PAGE_LONG or event == EVT_PAGEUP_FIRST then
killEvents(event);
selectPage(-1)
end
local result = pages[page](event)
refreshNext()
return result
end
return { init=init, run=run }
+176 -176
View File
@@ -1,176 +1,176 @@
--------------------------------------------------------------
-- Classic snake game
--
-- 2009 Led Lab @PUC-Rio www.eluaproject.net
-- Dado Sutter
-- Ives Negreiros
-- To Benjamin
---------------------------------------------------------------
local xMax = math.floor( LCD_W / 6 ) - 1
local yMax = math.floor( LCD_H / 8 ) - 1
local game_map = {}
local Head = {}
local Tail = {}
local highscore = 0
local size = 3
Tail.x = 1
Tail.y = 1
Head.x = Tail.x + ( size - 1 )
Head.y = Tail.y
local Food = {}
Food.x = false
Food.y = false
Head.dx = 1
Head.dy = 0
Tail.dx = Head.dx
Tail.dy = Head.dy
local direction = "right"
local score = 0
local function create_food()
Food.x, Food.y = math.random( xMax - 1), math.random( yMax - 1)
while game_map[ Food.x ][ Food.y ] do
Food.x, Food.y = math.random( xMax - 1 ), math.random( yMax - 1 )
end
game_map[ Food.x ][ Food.y ] = "food"
lcd.drawText( Food.x * 6, Food.y * 8+2, "@", 0 )
end
local function eat_food()
playFile("/SCRIPTS/snake.wav")
lcd.drawText( Head.x * 6, Head.y * 8, " ", 0 )
game_map[ Head.x ][ Head.y ] = nil
create_food()
score = score + 1
end
local function check_collision()
if Head.x < 0 or Head.x > xMax then
return true
elseif Head.y < 0 or Head.y > yMax then
return true
elseif ( ( game_map[ Head.x ][ Head.y ] ) and ( game_map[ Head.x ][ Head.y ] ~= "food" ) ) then
return true
end
return false
end
local function move()
if game_map[ Tail.x ][ Tail.y ] == "right" then
Tail.dx = 1
Tail.dy = 0
elseif game_map[ Tail.x ][ Tail.y ] == "left" then
Tail.dx = -1
Tail.dy = 0
elseif game_map[ Tail.x ][ Tail.y ] == "up" then
Tail.dx = 0
Tail.dy = -1
elseif game_map[ Tail.x ][ Tail.y ] == "down" then
Tail.dx = 0
Tail.dy = 1
end
game_map[ Head.x ][ Head.y ] = direction
Head.x = Head.x + Head.dx
Head.y = Head.y + Head.dy
if Head.x < 0 or Head.x > xMax or Head.y < 0 or Head.y > yMax then
return
elseif game_map[ Head.x ][ Head.y ] == "food" then
eat_food()
else
lcd.drawText(Tail.x * 6, Tail.y * 8, " ", 16)
game_map[ Tail.x ][ Tail.y ] = nil
Tail.x = Tail.x + Tail.dx
Tail.y = Tail.y + Tail.dy
end
lcd.drawText(Head.x * 6, Head.y * 8, "*", 0)
end
local function init()
food = false
lcd.clear()
size = 3
score = 0
Tail.x = 1
Tail.y = 1
Head.x = Tail.x + ( size - 1 )
Head.y = Tail.y
Head.dx = 1
Head.dy = 0
Tail.dx = Head.dx
Tail.dy = Head.dy
direction = "right"
for i = 0, xMax, 1 do
game_map[ i ] = {}
end
for i = 0, size - 1, 1 do
game_map[ Tail.x + ( i * Tail.dx ) ][ Tail.y + ( i * Tail.dy ) ] = direction
lcd.drawText( ( Tail.x + ( i * Tail.dx ) ) * 6, ( Tail.y + ( i * Tail.dy ) ) * 8, "*", 0 )
end
create_food()
end
local snakeCounter = 0
local function run(event)
if event == nil then
raise("Cannot be run as a model script!")
end
if event == EVT_EXIT_BREAK then
return 2
end
snakeCounter = snakeCounter + 1
if snakeCounter < 30 then
return 0
end
snakeCounter = 0
local dir = direction
if getValue('rud') > 100 and direction ~= "left" then
dir = "right"
Head.dx = 1
Head.dy = 0
end
if getValue('rud') < -100 and direction ~= "right" then
dir = "left"
Head.dx = -1
Head.dy = 0
end
if getValue('ele') > 100 and direction ~= "down" then
dir = "up"
Head.dx = 0
Head.dy = -1
end
if getValue('ele') < -100 and direction ~= "up" then
dir = "down"
Head.dx = 0
Head.dy = 1
end
direction = dir
move()
lcd.refresh()
if check_collision() then
return 1
end
return 0
end
return { init=init, run=run }
--------------------------------------------------------------
-- Classic snake game
--
-- 2009 Led Lab @PUC-Rio www.eluaproject.net
-- Dado Sutter
-- Ives Negreiros
-- To Benjamin
---------------------------------------------------------------
local xMax = math.floor( LCD_W / 6 ) - 1
local yMax = math.floor( LCD_H / 8 ) - 1
local game_map = {}
local Head = {}
local Tail = {}
local highscore = 0
local size = 3
Tail.x = 1
Tail.y = 1
Head.x = Tail.x + ( size - 1 )
Head.y = Tail.y
local Food = {}
Food.x = false
Food.y = false
Head.dx = 1
Head.dy = 0
Tail.dx = Head.dx
Tail.dy = Head.dy
local direction = "right"
local score = 0
local function create_food()
Food.x, Food.y = math.random( xMax - 1), math.random( yMax - 1)
while game_map[ Food.x ][ Food.y ] do
Food.x, Food.y = math.random( xMax - 1 ), math.random( yMax - 1 )
end
game_map[ Food.x ][ Food.y ] = "food"
lcd.drawText( Food.x * 6, Food.y * 8+2, "@", 0 )
end
local function eat_food()
playFile("/SCRIPTS/snake.wav")
lcd.drawText( Head.x * 6, Head.y * 8, " ", 0 )
game_map[ Head.x ][ Head.y ] = nil
create_food()
score = score + 1
end
local function check_collision()
if Head.x < 0 or Head.x > xMax then
return true
elseif Head.y < 0 or Head.y > yMax then
return true
elseif ( ( game_map[ Head.x ][ Head.y ] ) and ( game_map[ Head.x ][ Head.y ] ~= "food" ) ) then
return true
end
return false
end
local function move()
if game_map[ Tail.x ][ Tail.y ] == "right" then
Tail.dx = 1
Tail.dy = 0
elseif game_map[ Tail.x ][ Tail.y ] == "left" then
Tail.dx = -1
Tail.dy = 0
elseif game_map[ Tail.x ][ Tail.y ] == "up" then
Tail.dx = 0
Tail.dy = -1
elseif game_map[ Tail.x ][ Tail.y ] == "down" then
Tail.dx = 0
Tail.dy = 1
end
game_map[ Head.x ][ Head.y ] = direction
Head.x = Head.x + Head.dx
Head.y = Head.y + Head.dy
if Head.x < 0 or Head.x > xMax or Head.y < 0 or Head.y > yMax then
return
elseif game_map[ Head.x ][ Head.y ] == "food" then
eat_food()
else
lcd.drawText(Tail.x * 6, Tail.y * 8, " ", 16)
game_map[ Tail.x ][ Tail.y ] = nil
Tail.x = Tail.x + Tail.dx
Tail.y = Tail.y + Tail.dy
end
lcd.drawText(Head.x * 6, Head.y * 8, "*", 0)
end
local function init()
food = false
lcd.clear()
size = 3
score = 0
Tail.x = 1
Tail.y = 1
Head.x = Tail.x + ( size - 1 )
Head.y = Tail.y
Head.dx = 1
Head.dy = 0
Tail.dx = Head.dx
Tail.dy = Head.dy
direction = "right"
for i = 0, xMax, 1 do
game_map[ i ] = {}
end
for i = 0, size - 1, 1 do
game_map[ Tail.x + ( i * Tail.dx ) ][ Tail.y + ( i * Tail.dy ) ] = direction
lcd.drawText( ( Tail.x + ( i * Tail.dx ) ) * 6, ( Tail.y + ( i * Tail.dy ) ) * 8, "*", 0 )
end
create_food()
end
local snakeCounter = 0
local function run(event)
if event == nil then
raise("Cannot be run as a model script!")
end
if event == EVT_EXIT_BREAK then
return 2
end
snakeCounter = snakeCounter + 1
if snakeCounter < 30 then
return 0
end
snakeCounter = 0
local dir = direction
if getValue('rud') > 100 and direction ~= "left" then
dir = "right"
Head.dx = 1
Head.dy = 0
end
if getValue('rud') < -100 and direction ~= "right" then
dir = "left"
Head.dx = -1
Head.dy = 0
end
if getValue('ele') > 100 and direction ~= "down" then
dir = "up"
Head.dx = 0
Head.dy = -1
end
if getValue('ele') < -100 and direction ~= "up" then
dir = "down"
Head.dx = 0
Head.dy = 1
end
direction = dir
move()
lcd.refresh()
if check_collision() then
return 1
end
return 0
end
return { init=init, run=run }
+375 -375
View File
@@ -1,375 +1,375 @@
-- Delta Wizard pages
local ENGINE_PAGE = 0
local ELEVONS_PAGE = 1
local RUDDER_PAGE = 2
local CONFIRMATION_PAGE = 3
-- Navigation variables
local page = ENGINE_PAGE
local dirty = true
local edit = false
local field = 0
local fieldsMax = 0
-- Model settings
local engineMode = 1
local thrCH1 = 0
local elevCH1 = 0
local elevCH2 = 0
local elevonsMode = 0
local rudderMode = 0
local rudCH1 = 0
local servoPage = nil
-- Common functions
local lastBlink = 0
local function blinkChanged()
local time = getTime() % 128
local blink = (time - time % 64) / 64
if blink ~= lastBlink then
lastBlink = blink
return true
else
return false
end
end
local function fieldIncDec(event, value, max, force)
if edit or force==true then
if event == EVT_PLUS_BREAK or event == EVT_ROT_LEFT then
value = (value + max)
dirty = true
elseif event == EVT_MINUS_BREAK or event == EVT_ROT_RIGHT then
value = (value + max + 2)
dirty = true
end
value = (value % (max+1))
end
return value
end
local function valueIncDec(event, value, min, max)
if edit then
if event == EVT_PLUS_FIRST or event == EVT_PLUS_REPT or event == EVT_ROT_RIGHT then
if value < max then
value = (value + 1)
dirty = true
end
elseif event == EVT_MINUS_FIRST or event == EVT_MINUS_REPT or event == EVT_ROT_LEFT then
if value > min then
value = (value - 1)
dirty = true
end
end
end
return value
end
local function navigate(event, fieldMax, prevPage, nextPage)
if event == EVT_ENTER_BREAK then
edit = not edit
dirty = true
elseif edit then
if event == EVT_EXIT_BREAK then
edit = false
dirty = true
elseif not dirty then
dirty = blinkChanged()
end
else
if event == EVT_PAGE_BREAK then
page = nextPage
field = 0
dirty = true
elseif event == EVT_PAGE_LONG then
page = prevPage
field = 0
killEvents(event);
dirty = true
else
field = fieldIncDec(event, field, fieldMax, true)
end
end
end
local function getFieldFlags(position)
flags = 0
if field == position then
flags = INVERS
if edit then
flags = INVERS + BLINK
end
end
return flags
end
local function channelIncDec(event, value)
if not edit and event==EVT_MENU_BREAK then
servoPage = value
dirty = true
else
value = valueIncDec(event, value, 0, 15)
end
return value
end
-- Init function
local function init()
rudCH1 = defaultChannel(0)
thrCH1 = defaultChannel(2)
elevCH1 = defaultChannel(1)
elevCH2 = defaultChannel(3)
end
-- Engine Menu
local engineModeItems = {"No", "Yes..."}
local function drawEngineMenu()
lcd.clear()
lcd.drawText(1, 0, "Has your model got an engine?", 0)
lcd.drawFilledRectangle(0, 0, LCD_W, 8, GREY_DEFAULT+FILL_WHITE)
lcd.drawCombobox(0, 8, LCD_W/2, engineModeItems, engineMode, getFieldFlags(0))
lcd.drawLine(LCD_W/2-1, 18, LCD_W/2-1, LCD_H-1, DOTTED, 0)
if engineMode == 0 then
-- No engine
lcd.drawPixmap(132, 8, "engine-0.bmp")
fieldsMax = 0
else
-- 1 channel
lcd.drawPixmap(132, 8, "engine-1.bmp")
lcd.drawText(25, LCD_H-16, "Assign channel", 0);
lcd.drawText(LCD_W/2-19, LCD_H-8, ">>>", 0);
lcd.drawSource(151, LCD_H-8, MIXSRC_CH1+thrCH1, getFieldFlags(1))
fieldsMax = 1
end
end
local function engineMenu(event)
if dirty then
dirty = false
drawEngineMenu()
end
navigate(event, fieldsMax, page, page+1)
if field==0 then
engineMode = fieldIncDec(event, engineMode, 1)
elseif field==1 then
thrCH1 = channelIncDec(event, thrCH1)
end
end
-- Elevons Menu
local elevonsModeItems = {"2 Channels..."}
local function drawElevonsMenu()
lcd.clear()
lcd.drawText(1, 0, "Select elevon channnels", 0)
lcd.drawFilledRectangle(0, 0, LCD_W, 8, GREY_DEFAULT+FILL_WHITE)
lcd.drawCombobox(0, 8, LCD_W/2, elevonsModeItems, elevonsMode, 0)
lcd.drawLine(LCD_W/2-1, 18, LCD_W/2-1, LCD_H-1, DOTTED, 0)
lcd.drawPixmap(110, 9, "elevons.bmp")
lcd.drawText(20, LCD_H-16, "Assign channels", 0);
lcd.drawText(LCD_W/2-19, LCD_H-8, ">>>", 0);
lcd.drawSource(116, LCD_H-8, MIXSRC_CH1+elevCH1, getFieldFlags(0))
lcd.drawSource(175, LCD_H-8, MIXSRC_CH1+elevCH2, getFieldFlags(1))
fieldsMax = 1
end
local function elevonsMenu(event)
if dirty then
dirty = false
drawElevonsMenu()
end
navigate(event, fieldsMax, page-1, page+1)
if field==0 then
elevCH1 = channelIncDec(event, elevCH1)
elseif field==1 then
elevCH2 = channelIncDec(event, elevCH2)
end
end
-- Rudder menu
local rudderModeItems = {"No", "Yes..."}
local function drawRudderMenu()
lcd.clear()
lcd.drawText(1, 0, "Has your model got a rudder?", 0)
lcd.drawFilledRectangle(0, 0, LCD_W, 8, GREY_DEFAULT+FILL_WHITE)
lcd.drawCombobox(0, 8, LCD_W/2, rudderModeItems, rudderMode, getFieldFlags(0))
lcd.drawLine(LCD_W/2-1, 18, LCD_W/2-1, LCD_H-1, DOTTED, 0)
if rudderMode == 0 then
-- No rudder
lcd.drawPixmap(109, 14, "drudder-0.bmp")
fieldsMax = 0
else
-- 1 channel
lcd.drawPixmap(109, 14, "drudder-1.bmp")
lcd.drawText(25, LCD_H-16, "Assign channel", 0);
lcd.drawText(LCD_W/2-19, LCD_H-8, ">>>", 0);
lcd.drawSource(190, LCD_H-55, MIXSRC_CH1+rudCH1, getFieldFlags(1))
fieldsMax = 1
end
end
local function rudderMenu(event)
if dirty then
dirty = false
drawRudderMenu()
end
navigate(event, fieldsMax, page-1, page+1)
if field==0 then
rudderMode = fieldIncDec(event, rudderMode, 1)
elseif field==1 then
rudCH1 = channelIncDec(event, rudCH1)
end
end
-- Servo (limits) Menu
local function drawServoMenu(limits)
lcd.clear()
lcd.drawSource(1, 0, MIXSRC_CH1+servoPage, 0)
lcd.drawText(25, 0, "servo min/max/center/direction?", 0)
lcd.drawFilledRectangle(0, 0, LCD_W, 8, GREY_DEFAULT+FILL_WHITE)
lcd.drawLine(LCD_W/2-1, 8, LCD_W/2-1, LCD_H-1, DOTTED, 0)
lcd.drawText(LCD_W/2-19, LCD_H-8, ">>>", 0);
lcd.drawPixmap(122, 8, "servo.bmp")
lcd.drawNumber(140, 35, limits.min, PREC1+getFieldFlags(0));
lcd.drawNumber(205, 35, limits.max, PREC1+getFieldFlags(1));
lcd.drawNumber(170, 9, limits.offset, PREC1+getFieldFlags(2));
if limits.revert == 0 then
lcd.drawText(129, 50, "\126", getFieldFlags(3));
else
lcd.drawText(129, 50, "\127", getFieldFlags(3));
end
fieldsMax = 3
end
local function servoMenu(event)
local limits = model.getOutput(servoPage)
if dirty then
dirty = false
drawServoMenu(limits)
end
navigate(event, fieldsMax, page, page)
if edit then
if field==0 then
limits.min = valueIncDec(event, limits.min, -1000, 0)
elseif field==1 then
limits.max = valueIncDec(event, limits.max, 0, 1000)
elseif field==2 then
limits.offset = valueIncDec(event, limits.offset, -1000, 1000)
elseif field==3 then
limits.revert = fieldIncDec(event, limits.revert, 1)
end
model.setOutput(servoPage, limits)
elseif event == EVT_EXIT_BREAK then
servoPage = nil
dirty = true
end
end
-- Confirmation Menu
local function addMix(channel, input, name, weight, index)
local mix = { source=input, name=name }
if weight ~= nil then
mix.weight = weight
end
if index == nil then
index = 0
end
model.insertMix(channel, index, mix)
end
local function applySettings()
model.defaultInputs()
model.deleteMixes()
if engineMode == 1 then
addMix(thrCH1, MIXSRC_FIRST_INPUT+defaultChannel(2), "Engine")
end
addMix(elevCH1, MIXSRC_FIRST_INPUT+defaultChannel(1), "Elev1-E", 50)
addMix(elevCH1, MIXSRC_FIRST_INPUT+defaultChannel(3), "Elev1-A", 50, 1)
addMix(elevCH2, MIXSRC_FIRST_INPUT+defaultChannel(1), "Elev2-E", 50)
addMix(elevCH2, MIXSRC_FIRST_INPUT+defaultChannel(3), "Elev2-A", -50, 1)
if rudderMode == 1 then
addMix(rudCH1, MIXSRC_FIRST_INPUT+defaultChannel(0), "Rudder")
end
end
local function drawNextLine(x, y, label, channel)
lcd.drawText(x, y, label, 0);
lcd.drawSource(x+52, y, MIXSRC_CH1+channel, 0)
y = y + 8
if y > 50 then
y = 12
x = 120
end
return x, y
end
local function drawConfirmationMenu()
local x = 22
local y = 12
lcd.clear()
lcd.drawText(48, 1, "Ready to go?", 0);
lcd.drawFilledRectangle(0, 0, LCD_W, 9, 0)
if engineMode == 1 then
x, y = drawNextLine(x, y, "Throttle:", thrCH1)
end
x, y = drawNextLine(x, y, "Elevons:", elevCH1)
x, y = drawNextLine(x, y, "Elevons:", elevCH2)
if rudderMode == 1 then
drawNextLine(x, y, "Rudder:", rudCH1)
end
lcd.drawText(48, LCD_H-8, "[Enter Long] to confirm", 0);
lcd.drawFilledRectangle(0, LCD_H-9, LCD_W, 9, 0)
lcd.drawPixmap(LCD_W-18, 0, "confirm-tick.bmp")
lcd.drawPixmap(0, LCD_H-17, "confirm-plane.bmp")
fieldsMax = 0
end
local function confirmationMenu(event)
if dirty then
dirty = false
drawConfirmationMenu()
end
navigate(event, fieldsMax, RUDDER_PAGE, page)
if event == EVT_EXIT_BREAK then
return 2
elseif event == EVT_ENTER_LONG then
killEvents(event)
applySettings()
return 2
else
return 0
end
end
-- Main
local function run(event)
if event == nil then
error("Cannot be run as a model script!")
end
if servoPage ~= nil then
servoMenu(event)
elseif page == ENGINE_PAGE then
engineMenu(event)
elseif page == ELEVONS_PAGE then
elevonsMenu(event)
elseif page == RUDDER_PAGE then
rudderMenu(event)
elseif page == CONFIRMATION_PAGE then
return confirmationMenu(event)
end
return 0
end
return { init=init, run=run }
-- Delta Wizard pages
local ENGINE_PAGE = 0
local ELEVONS_PAGE = 1
local RUDDER_PAGE = 2
local CONFIRMATION_PAGE = 3
-- Navigation variables
local page = ENGINE_PAGE
local dirty = true
local edit = false
local field = 0
local fieldsMax = 0
-- Model settings
local engineMode = 1
local thrCH1 = 0
local elevCH1 = 0
local elevCH2 = 0
local elevonsMode = 0
local rudderMode = 0
local rudCH1 = 0
local servoPage = nil
-- Common functions
local lastBlink = 0
local function blinkChanged()
local time = getTime() % 128
local blink = (time - time % 64) / 64
if blink ~= lastBlink then
lastBlink = blink
return true
else
return false
end
end
local function fieldIncDec(event, value, max, force)
if edit or force==true then
if event == EVT_PLUS_BREAK or event == EVT_ROT_LEFT then
value = (value + max)
dirty = true
elseif event == EVT_MINUS_BREAK or event == EVT_ROT_RIGHT then
value = (value + max + 2)
dirty = true
end
value = (value % (max+1))
end
return value
end
local function valueIncDec(event, value, min, max)
if edit then
if event == EVT_PLUS_FIRST or event == EVT_PLUS_REPT or event == EVT_ROT_RIGHT then
if value < max then
value = (value + 1)
dirty = true
end
elseif event == EVT_MINUS_FIRST or event == EVT_MINUS_REPT or event == EVT_ROT_LEFT then
if value > min then
value = (value - 1)
dirty = true
end
end
end
return value
end
local function navigate(event, fieldMax, prevPage, nextPage)
if event == EVT_ENTER_BREAK then
edit = not edit
dirty = true
elseif edit then
if event == EVT_EXIT_BREAK then
edit = false
dirty = true
elseif not dirty then
dirty = blinkChanged()
end
else
if event == EVT_PAGE_BREAK then
page = nextPage
field = 0
dirty = true
elseif event == EVT_PAGE_LONG then
page = prevPage
field = 0
killEvents(event);
dirty = true
else
field = fieldIncDec(event, field, fieldMax, true)
end
end
end
local function getFieldFlags(position)
flags = 0
if field == position then
flags = INVERS
if edit then
flags = INVERS + BLINK
end
end
return flags
end
local function channelIncDec(event, value)
if not edit and event==EVT_MENU_BREAK then
servoPage = value
dirty = true
else
value = valueIncDec(event, value, 0, 15)
end
return value
end
-- Init function
local function init()
rudCH1 = defaultChannel(0)
thrCH1 = defaultChannel(2)
elevCH1 = defaultChannel(1)
elevCH2 = defaultChannel(3)
end
-- Engine Menu
local engineModeItems = {"No", "Yes..."}
local function drawEngineMenu()
lcd.clear()
lcd.drawText(1, 0, "Has your model got an engine?", 0)
lcd.drawFilledRectangle(0, 0, LCD_W, 8, GREY_DEFAULT+FILL_WHITE)
lcd.drawCombobox(0, 8, LCD_W/2, engineModeItems, engineMode, getFieldFlags(0))
lcd.drawLine(LCD_W/2-1, 18, LCD_W/2-1, LCD_H-1, DOTTED, 0)
if engineMode == 0 then
-- No engine
lcd.drawPixmap(132, 8, "engine-0.bmp")
fieldsMax = 0
else
-- 1 channel
lcd.drawPixmap(132, 8, "engine-1.bmp")
lcd.drawText(25, LCD_H-16, "Assign channel", 0);
lcd.drawText(LCD_W/2-19, LCD_H-8, ">>>", 0);
lcd.drawSource(151, LCD_H-8, MIXSRC_CH1+thrCH1, getFieldFlags(1))
fieldsMax = 1
end
end
local function engineMenu(event)
if dirty then
dirty = false
drawEngineMenu()
end
navigate(event, fieldsMax, page, page+1)
if field==0 then
engineMode = fieldIncDec(event, engineMode, 1)
elseif field==1 then
thrCH1 = channelIncDec(event, thrCH1)
end
end
-- Elevons Menu
local elevonsModeItems = {"2 Channels..."}
local function drawElevonsMenu()
lcd.clear()
lcd.drawText(1, 0, "Select elevon channnels", 0)
lcd.drawFilledRectangle(0, 0, LCD_W, 8, GREY_DEFAULT+FILL_WHITE)
lcd.drawCombobox(0, 8, LCD_W/2, elevonsModeItems, elevonsMode, 0)
lcd.drawLine(LCD_W/2-1, 18, LCD_W/2-1, LCD_H-1, DOTTED, 0)
lcd.drawPixmap(110, 9, "elevons.bmp")
lcd.drawText(20, LCD_H-16, "Assign channels", 0);
lcd.drawText(LCD_W/2-19, LCD_H-8, ">>>", 0);
lcd.drawSource(116, LCD_H-8, MIXSRC_CH1+elevCH1, getFieldFlags(0))
lcd.drawSource(175, LCD_H-8, MIXSRC_CH1+elevCH2, getFieldFlags(1))
fieldsMax = 1
end
local function elevonsMenu(event)
if dirty then
dirty = false
drawElevonsMenu()
end
navigate(event, fieldsMax, page-1, page+1)
if field==0 then
elevCH1 = channelIncDec(event, elevCH1)
elseif field==1 then
elevCH2 = channelIncDec(event, elevCH2)
end
end
-- Rudder menu
local rudderModeItems = {"No", "Yes..."}
local function drawRudderMenu()
lcd.clear()
lcd.drawText(1, 0, "Has your model got a rudder?", 0)
lcd.drawFilledRectangle(0, 0, LCD_W, 8, GREY_DEFAULT+FILL_WHITE)
lcd.drawCombobox(0, 8, LCD_W/2, rudderModeItems, rudderMode, getFieldFlags(0))
lcd.drawLine(LCD_W/2-1, 18, LCD_W/2-1, LCD_H-1, DOTTED, 0)
if rudderMode == 0 then
-- No rudder
lcd.drawPixmap(109, 14, "drudder-0.bmp")
fieldsMax = 0
else
-- 1 channel
lcd.drawPixmap(109, 14, "drudder-1.bmp")
lcd.drawText(25, LCD_H-16, "Assign channel", 0);
lcd.drawText(LCD_W/2-19, LCD_H-8, ">>>", 0);
lcd.drawSource(190, LCD_H-55, MIXSRC_CH1+rudCH1, getFieldFlags(1))
fieldsMax = 1
end
end
local function rudderMenu(event)
if dirty then
dirty = false
drawRudderMenu()
end
navigate(event, fieldsMax, page-1, page+1)
if field==0 then
rudderMode = fieldIncDec(event, rudderMode, 1)
elseif field==1 then
rudCH1 = channelIncDec(event, rudCH1)
end
end
-- Servo (limits) Menu
local function drawServoMenu(limits)
lcd.clear()
lcd.drawSource(1, 0, MIXSRC_CH1+servoPage, 0)
lcd.drawText(25, 0, "servo min/max/center/direction?", 0)
lcd.drawFilledRectangle(0, 0, LCD_W, 8, GREY_DEFAULT+FILL_WHITE)
lcd.drawLine(LCD_W/2-1, 8, LCD_W/2-1, LCD_H-1, DOTTED, 0)
lcd.drawText(LCD_W/2-19, LCD_H-8, ">>>", 0);
lcd.drawPixmap(122, 8, "servo.bmp")
lcd.drawNumber(140, 35, limits.min, PREC1+getFieldFlags(0));
lcd.drawNumber(205, 35, limits.max, PREC1+getFieldFlags(1));
lcd.drawNumber(170, 9, limits.offset, PREC1+getFieldFlags(2));
if limits.revert == 0 then
lcd.drawText(129, 50, "\126", getFieldFlags(3));
else
lcd.drawText(129, 50, "\127", getFieldFlags(3));
end
fieldsMax = 3
end
local function servoMenu(event)
local limits = model.getOutput(servoPage)
if dirty then
dirty = false
drawServoMenu(limits)
end
navigate(event, fieldsMax, page, page)
if edit then
if field==0 then
limits.min = valueIncDec(event, limits.min, -1000, 0)
elseif field==1 then
limits.max = valueIncDec(event, limits.max, 0, 1000)
elseif field==2 then
limits.offset = valueIncDec(event, limits.offset, -1000, 1000)
elseif field==3 then
limits.revert = fieldIncDec(event, limits.revert, 1)
end
model.setOutput(servoPage, limits)
elseif event == EVT_EXIT_BREAK then
servoPage = nil
dirty = true
end
end
-- Confirmation Menu
local function addMix(channel, input, name, weight, index)
local mix = { source=input, name=name }
if weight ~= nil then
mix.weight = weight
end
if index == nil then
index = 0
end
model.insertMix(channel, index, mix)
end
local function applySettings()
model.defaultInputs()
model.deleteMixes()
if engineMode == 1 then
addMix(thrCH1, MIXSRC_FIRST_INPUT+defaultChannel(2), "Engine")
end
addMix(elevCH1, MIXSRC_FIRST_INPUT+defaultChannel(1), "Elev1-E", 50)
addMix(elevCH1, MIXSRC_FIRST_INPUT+defaultChannel(3), "Elev1-A", 50, 1)
addMix(elevCH2, MIXSRC_FIRST_INPUT+defaultChannel(1), "Elev2-E", 50)
addMix(elevCH2, MIXSRC_FIRST_INPUT+defaultChannel(3), "Elev2-A", -50, 1)
if rudderMode == 1 then
addMix(rudCH1, MIXSRC_FIRST_INPUT+defaultChannel(0), "Rudder")
end
end
local function drawNextLine(x, y, label, channel)
lcd.drawText(x, y, label, 0);
lcd.drawSource(x+52, y, MIXSRC_CH1+channel, 0)
y = y + 8
if y > 50 then
y = 12
x = 120
end
return x, y
end
local function drawConfirmationMenu()
local x = 22
local y = 12
lcd.clear()
lcd.drawText(48, 1, "Ready to go?", 0);
lcd.drawFilledRectangle(0, 0, LCD_W, 9, 0)
if engineMode == 1 then
x, y = drawNextLine(x, y, "Throttle:", thrCH1)
end
x, y = drawNextLine(x, y, "Elevons:", elevCH1)
x, y = drawNextLine(x, y, "Elevons:", elevCH2)
if rudderMode == 1 then
drawNextLine(x, y, "Rudder:", rudCH1)
end
lcd.drawText(48, LCD_H-8, "[Enter Long] to confirm", 0);
lcd.drawFilledRectangle(0, LCD_H-9, LCD_W, 9, 0)
lcd.drawPixmap(LCD_W-18, 0, "confirm-tick.bmp")
lcd.drawPixmap(0, LCD_H-17, "confirm-plane.bmp")
fieldsMax = 0
end
local function confirmationMenu(event)
if dirty then
dirty = false
drawConfirmationMenu()
end
navigate(event, fieldsMax, RUDDER_PAGE, page)
if event == EVT_EXIT_BREAK then
return 2
elseif event == EVT_ENTER_LONG then
killEvents(event)
applySettings()
return 2
else
return 0
end
end
-- Main
local function run(event)
if event == nil then
error("Cannot be run as a model script!")
end
if servoPage ~= nil then
servoMenu(event)
elseif page == ENGINE_PAGE then
engineMenu(event)
elseif page == ELEVONS_PAGE then
elevonsMenu(event)
elseif page == RUDDER_PAGE then
rudderMenu(event)
elseif page == CONFIRMATION_PAGE then
return confirmationMenu(event)
end
return 0
end
return { init=init, run=run }
+305 -305
View File
@@ -1,305 +1,305 @@
-- Multicopter Wizard pages
local THROTTLE_PAGE = 0
local ROLL_PAGE = 1
local PITCH_PAGE = 2
local YAW_PAGE = 3
local CONFIRMATION_PAGE = 4
-- Navigation variables
local page = THROTTLE_PAGE
local dirty = true
local edit = false
local field = 0
local fieldsMax = 0
local comboBoxMode = 0 -- Scrap variable
-- Model settings
local thrCH1 = 0
local rollCH1 = 0
local yawCH1 = 0
local pitchCH1 = 0
-- Common functions
local lastBlink = 0
local function blinkChanged()
local time = getTime() % 128
local blink = (time - time % 64) / 64
if blink ~= lastBlink then
lastBlink = blink
return true
else
return false
end
end
local function fieldIncDec(event, value, max, force)
if edit or force==true then
if event == EVT_PLUS_BREAK or event == EVT_ROT_LEFT then
value = (value + max)
dirty = true
elseif event == EVT_MINUS_BREAK or event == EVT_ROT_RIGHT then
value = (value + max + 2)
dirty = true
end
value = (value % (max+1))
end
return value
end
local function valueIncDec(event, value, min, max)
if edit then
if event == EVT_PLUS_FIRST or event == EVT_PLUS_REPT or event == EVT_ROT_RIGHT then
if value < max then
value = (value + 1)
dirty = true
end
elseif event == EVT_MINUS_FIRST or event == EVT_MINUS_REPT or event == EVT_ROT_LEFT then
if value > min then
value = (value - 1)
dirty = true
end
end
end
return value
end
local function navigate(event, fieldMax, prevPage, nextPage)
if event == EVT_ENTER_BREAK then
edit = not edit
dirty = true
elseif edit then
if event == EVT_EXIT_BREAK then
edit = false
dirty = true
elseif not dirty then
dirty = blinkChanged()
end
else
if event == EVT_PAGE_BREAK then
page = nextPage
field = 0
dirty = true
elseif event == EVT_PAGE_LONG then
page = prevPage
field = 0
killEvents(event);
dirty = true
else
field = fieldIncDec(event, field, fieldMax, true)
end
end
end
local function getFieldFlags(position)
flags = 0
if field == position then
flags = INVERS
if edit then
flags = INVERS + BLINK
end
end
return flags
end
local function channelIncDec(event, value)
if not edit and event==EVT_MENU_BREAK then
servoPage = value
dirty = true
else
value = valueIncDec(event, value, 0, 15)
end
return value
end
-- Init function
local function init()
thrCH1 = defaultChannel(2)
rollCH1 = defaultChannel(3)
yawCH1 = defaultChannel(0)
pitchCH1 = defaultChannel(1)
end
-- Throttle Menu
local function drawThrottleMenu()
lcd.clear()
lcd.drawText(1, 0, "Select multicopter throttle channel", 0)
lcd.drawFilledRectangle(0, 0, LCD_W, 8, GREY_DEFAULT+FILL_WHITE)
lcd.drawCombobox(0, 8, LCD_W/2, {"..."}, comboBoxMode, getFieldFlags(1))
lcd.drawLine(LCD_W/2-1, 18, LCD_W/2-1, LCD_H-1, DOTTED, 0)
lcd.drawPixmap(120, 8, "multi-thr.bmp")
lcd.drawText(20, LCD_H-16, "Assign Throttle", 0);
lcd.drawText(20, LCD_H-8, "Channel", 0);
lcd.drawText(LCD_W/2-19, LCD_H-8, ">>>", 0);
lcd.drawSource(113, LCD_H-8, MIXSRC_CH1+thrCH1, getFieldFlags(0))
fieldsMax = 0
end
local function throttleMenu(event)
if dirty then
dirty = false
drawThrottleMenu()
end
navigate(event, fieldsMax, page, page+1)
thrCH1 = channelIncDec(event, thrCH1)
end
-- Roll Menu
local function drawRollMenu()
lcd.clear()
lcd.drawText(1, 0, "Select multicopter roll channel", 0)
lcd.drawFilledRectangle(0, 0, LCD_W, 8, GREY_DEFAULT+FILL_WHITE)
lcd.drawCombobox(0, 8, LCD_W/2, {"..."}, comboBoxMode, getFieldFlags(1))
lcd.drawLine(LCD_W/2-1, 18, LCD_W/2-1, LCD_H-1, DOTTED, 0)
lcd.drawPixmap(120, 8, "multi-roll.bmp")
lcd.drawText(20, LCD_H-16, "Assign Roll", 0);
lcd.drawText(20, LCD_H-8, "Channel", 0);
lcd.drawText(LCD_W/2-19, LCD_H-8, ">>>", 0);
lcd.drawSource(113, LCD_H-8, MIXSRC_CH1+rollCH1, getFieldFlags(0))
fieldsMax = 0
end
local function rollMenu(event)
if dirty then
dirty = false
drawRollMenu()
end
navigate(event, fieldsMax, page-1, page+1)
rollCH1 = channelIncDec(event, rollCH1)
end
-- Pitch Menu
local function drawPitchMenu()
lcd.clear()
lcd.drawText(1, 0, "Select multicopter pitch channel", 0)
lcd.drawFilledRectangle(0, 0, LCD_W, 8, GREY_DEFAULT+FILL_WHITE)
lcd.drawCombobox(0, 8, LCD_W/2, {"..."}, comboBoxMode, getFieldFlags(1))
lcd.drawLine(LCD_W/2-1, 18, LCD_W/2-1, LCD_H-1, DOTTED, 0)
lcd.drawPixmap(120, 8, "multi-pitch.bmp")
lcd.drawText(20, LCD_H-16, "Assign Pitch", 0);
lcd.drawText(20, LCD_H-8, "Channel", 0);
lcd.drawText(LCD_W/2-19, LCD_H-8, ">>>", 0);
lcd.drawSource(113, LCD_H-8, MIXSRC_CH1+pitchCH1, getFieldFlags(0))
fieldsMax = 0
end
local function pitchMenu(event)
if dirty then
dirty = false
drawPitchMenu()
end
navigate(event, fieldsMax, page-1, page+1)
pitchCH1 = channelIncDec(event, pitchCH1)
end
-- Yaw Menu
local function drawYawMenu()
lcd.clear()
lcd.drawText(1, 0, "Select multicopter yaw channel", 0)
lcd.drawFilledRectangle(0, 0, LCD_W, 8, GREY_DEFAULT+FILL_WHITE)
lcd.drawCombobox(0, 8, LCD_W/2, {"..."}, comboBoxMode, getFieldFlags(1))
lcd.drawLine(LCD_W/2-1, 18, LCD_W/2-1, LCD_H-1, DOTTED, 0)
lcd.drawPixmap(120, 8, "multi-yaw.bmp")
lcd.drawText(20, LCD_H-16, "Assign Yaw", 0);
lcd.drawText(20, LCD_H-8, "Channel", 0);
lcd.drawText(LCD_W/2-19, LCD_H-8, ">>>", 0);
lcd.drawSource(113, LCD_H-8, MIXSRC_CH1+yawCH1, getFieldFlags(0))
fieldsMax = 0
end
local function yawMenu(event)
if dirty then
dirty = false
drawYawMenu()
end
navigate(event, fieldsMax, page-1, page+1)
yawCH1 = channelIncDec(event, yawCH1)
end
-- Confirmation Menu
local function drawNextLine(x, y, label, channel)
lcd.drawText(x, y, label, 0);
lcd.drawSource(x+52, y, MIXSRC_CH1+channel, 0)
y = y + 8
if y > 50 then
y = 12
x = 120
end
return x, y
end
local function drawConfirmationMenu()
local x = 22
local y = 12
lcd.clear()
lcd.drawText(48, 1, "Ready to go?", 0);
lcd.drawFilledRectangle(0, 0, LCD_W, 9, 0)
x, y = drawNextLine(x, y, "Throttle:", thrCH1)
x, y = drawNextLine(x, y, "Roll:", rollCH1)
x, y = drawNextLine(x, y, "Pitch:", pitchCH1)
x, y = drawNextLine(x, y, "Yaw:", yawCH1)
lcd.drawText(48, LCD_H-8, "[Enter Long] to confirm", 0);
lcd.drawFilledRectangle(0, LCD_H-9, LCD_W, 9, 0)
lcd.drawPixmap(LCD_W-18, 0, "confirm-tick.bmp")
lcd.drawPixmap(0, LCD_H-17, "confirm-plane.bmp")
fieldsMax = 0
end
local function addMix(channel, input, name, weight, index)
local mix = { source=input, name=name }
if weight ~= nil then
mix.weight = weight
end
if index == nil then
index = 0
end
model.insertMix(channel, index, mix)
end
local function applySettings()
model.defaultInputs()
model.deleteMixes()
addMix(thrCH1, MIXSRC_FIRST_INPUT+defaultChannel(2), "Throttle")
addMix(rollCH1, MIXSRC_FIRST_INPUT+defaultChannel(3), "Roll")
addMix(yawCH1, MIXSRC_FIRST_INPUT+defaultChannel(0), "Yaw")
addMix(pitchCH1, MIXSRC_FIRST_INPUT+defaultChannel(1), "Pitch")
end
local function confirmationMenu(event)
if dirty then
dirty = false
drawConfirmationMenu()
end
navigate(event, fieldsMax, YAW_PAGE, page)
if event == EVT_EXIT_BREAK then
return 2
elseif event == EVT_ENTER_LONG then
killEvents(event)
applySettings()
return 2
else
return 0
end
end
-- Main
local function run(event)
if event == nil then
error("Cannot be run as a model script!")
end
if page == THROTTLE_PAGE then
throttleMenu(event)
elseif page == ROLL_PAGE then
rollMenu(event)
elseif page == YAW_PAGE then
yawMenu(event)
elseif page == PITCH_PAGE then
pitchMenu(event)
elseif page == CONFIRMATION_PAGE then
return confirmationMenu(event)
end
return 0
end
return { init=init, run=run }
-- Multicopter Wizard pages
local THROTTLE_PAGE = 0
local ROLL_PAGE = 1
local PITCH_PAGE = 2
local YAW_PAGE = 3
local CONFIRMATION_PAGE = 4
-- Navigation variables
local page = THROTTLE_PAGE
local dirty = true
local edit = false
local field = 0
local fieldsMax = 0
local comboBoxMode = 0 -- Scrap variable
-- Model settings
local thrCH1 = 0
local rollCH1 = 0
local yawCH1 = 0
local pitchCH1 = 0
-- Common functions
local lastBlink = 0
local function blinkChanged()
local time = getTime() % 128
local blink = (time - time % 64) / 64
if blink ~= lastBlink then
lastBlink = blink
return true
else
return false
end
end
local function fieldIncDec(event, value, max, force)
if edit or force==true then
if event == EVT_PLUS_BREAK or event == EVT_ROT_LEFT then
value = (value + max)
dirty = true
elseif event == EVT_MINUS_BREAK or event == EVT_ROT_RIGHT then
value = (value + max + 2)
dirty = true
end
value = (value % (max+1))
end
return value
end
local function valueIncDec(event, value, min, max)
if edit then
if event == EVT_PLUS_FIRST or event == EVT_PLUS_REPT or event == EVT_ROT_RIGHT then
if value < max then
value = (value + 1)
dirty = true
end
elseif event == EVT_MINUS_FIRST or event == EVT_MINUS_REPT or event == EVT_ROT_LEFT then
if value > min then
value = (value - 1)
dirty = true
end
end
end
return value
end
local function navigate(event, fieldMax, prevPage, nextPage)
if event == EVT_ENTER_BREAK then
edit = not edit
dirty = true
elseif edit then
if event == EVT_EXIT_BREAK then
edit = false
dirty = true
elseif not dirty then
dirty = blinkChanged()
end
else
if event == EVT_PAGE_BREAK then
page = nextPage
field = 0
dirty = true
elseif event == EVT_PAGE_LONG then
page = prevPage
field = 0
killEvents(event);
dirty = true
else
field = fieldIncDec(event, field, fieldMax, true)
end
end
end
local function getFieldFlags(position)
flags = 0
if field == position then
flags = INVERS
if edit then
flags = INVERS + BLINK
end
end
return flags
end
local function channelIncDec(event, value)
if not edit and event==EVT_MENU_BREAK then
servoPage = value
dirty = true
else
value = valueIncDec(event, value, 0, 15)
end
return value
end
-- Init function
local function init()
thrCH1 = defaultChannel(2)
rollCH1 = defaultChannel(3)
yawCH1 = defaultChannel(0)
pitchCH1 = defaultChannel(1)
end
-- Throttle Menu
local function drawThrottleMenu()
lcd.clear()
lcd.drawText(1, 0, "Select multicopter throttle channel", 0)
lcd.drawFilledRectangle(0, 0, LCD_W, 8, GREY_DEFAULT+FILL_WHITE)
lcd.drawCombobox(0, 8, LCD_W/2, {"..."}, comboBoxMode, getFieldFlags(1))
lcd.drawLine(LCD_W/2-1, 18, LCD_W/2-1, LCD_H-1, DOTTED, 0)
lcd.drawPixmap(120, 8, "multi-thr.bmp")
lcd.drawText(20, LCD_H-16, "Assign Throttle", 0);
lcd.drawText(20, LCD_H-8, "Channel", 0);
lcd.drawText(LCD_W/2-19, LCD_H-8, ">>>", 0);
lcd.drawSource(113, LCD_H-8, MIXSRC_CH1+thrCH1, getFieldFlags(0))
fieldsMax = 0
end
local function throttleMenu(event)
if dirty then
dirty = false
drawThrottleMenu()
end
navigate(event, fieldsMax, page, page+1)
thrCH1 = channelIncDec(event, thrCH1)
end
-- Roll Menu
local function drawRollMenu()
lcd.clear()
lcd.drawText(1, 0, "Select multicopter roll channel", 0)
lcd.drawFilledRectangle(0, 0, LCD_W, 8, GREY_DEFAULT+FILL_WHITE)
lcd.drawCombobox(0, 8, LCD_W/2, {"..."}, comboBoxMode, getFieldFlags(1))
lcd.drawLine(LCD_W/2-1, 18, LCD_W/2-1, LCD_H-1, DOTTED, 0)
lcd.drawPixmap(120, 8, "multi-roll.bmp")
lcd.drawText(20, LCD_H-16, "Assign Roll", 0);
lcd.drawText(20, LCD_H-8, "Channel", 0);
lcd.drawText(LCD_W/2-19, LCD_H-8, ">>>", 0);
lcd.drawSource(113, LCD_H-8, MIXSRC_CH1+rollCH1, getFieldFlags(0))
fieldsMax = 0
end
local function rollMenu(event)
if dirty then
dirty = false
drawRollMenu()
end
navigate(event, fieldsMax, page-1, page+1)
rollCH1 = channelIncDec(event, rollCH1)
end
-- Pitch Menu
local function drawPitchMenu()
lcd.clear()
lcd.drawText(1, 0, "Select multicopter pitch channel", 0)
lcd.drawFilledRectangle(0, 0, LCD_W, 8, GREY_DEFAULT+FILL_WHITE)
lcd.drawCombobox(0, 8, LCD_W/2, {"..."}, comboBoxMode, getFieldFlags(1))
lcd.drawLine(LCD_W/2-1, 18, LCD_W/2-1, LCD_H-1, DOTTED, 0)
lcd.drawPixmap(120, 8, "multi-pitch.bmp")
lcd.drawText(20, LCD_H-16, "Assign Pitch", 0);
lcd.drawText(20, LCD_H-8, "Channel", 0);
lcd.drawText(LCD_W/2-19, LCD_H-8, ">>>", 0);
lcd.drawSource(113, LCD_H-8, MIXSRC_CH1+pitchCH1, getFieldFlags(0))
fieldsMax = 0
end
local function pitchMenu(event)
if dirty then
dirty = false
drawPitchMenu()
end
navigate(event, fieldsMax, page-1, page+1)
pitchCH1 = channelIncDec(event, pitchCH1)
end
-- Yaw Menu
local function drawYawMenu()
lcd.clear()
lcd.drawText(1, 0, "Select multicopter yaw channel", 0)
lcd.drawFilledRectangle(0, 0, LCD_W, 8, GREY_DEFAULT+FILL_WHITE)
lcd.drawCombobox(0, 8, LCD_W/2, {"..."}, comboBoxMode, getFieldFlags(1))
lcd.drawLine(LCD_W/2-1, 18, LCD_W/2-1, LCD_H-1, DOTTED, 0)
lcd.drawPixmap(120, 8, "multi-yaw.bmp")
lcd.drawText(20, LCD_H-16, "Assign Yaw", 0);
lcd.drawText(20, LCD_H-8, "Channel", 0);
lcd.drawText(LCD_W/2-19, LCD_H-8, ">>>", 0);
lcd.drawSource(113, LCD_H-8, MIXSRC_CH1+yawCH1, getFieldFlags(0))
fieldsMax = 0
end
local function yawMenu(event)
if dirty then
dirty = false
drawYawMenu()
end
navigate(event, fieldsMax, page-1, page+1)
yawCH1 = channelIncDec(event, yawCH1)
end
-- Confirmation Menu
local function drawNextLine(x, y, label, channel)
lcd.drawText(x, y, label, 0);
lcd.drawSource(x+52, y, MIXSRC_CH1+channel, 0)
y = y + 8
if y > 50 then
y = 12
x = 120
end
return x, y
end
local function drawConfirmationMenu()
local x = 22
local y = 12
lcd.clear()
lcd.drawText(48, 1, "Ready to go?", 0);
lcd.drawFilledRectangle(0, 0, LCD_W, 9, 0)
x, y = drawNextLine(x, y, "Throttle:", thrCH1)
x, y = drawNextLine(x, y, "Roll:", rollCH1)
x, y = drawNextLine(x, y, "Pitch:", pitchCH1)
x, y = drawNextLine(x, y, "Yaw:", yawCH1)
lcd.drawText(48, LCD_H-8, "[Enter Long] to confirm", 0);
lcd.drawFilledRectangle(0, LCD_H-9, LCD_W, 9, 0)
lcd.drawPixmap(LCD_W-18, 0, "confirm-tick.bmp")
lcd.drawPixmap(0, LCD_H-17, "confirm-plane.bmp")
fieldsMax = 0
end
local function addMix(channel, input, name, weight, index)
local mix = { source=input, name=name }
if weight ~= nil then
mix.weight = weight
end
if index == nil then
index = 0
end
model.insertMix(channel, index, mix)
end
local function applySettings()
model.defaultInputs()
model.deleteMixes()
addMix(thrCH1, MIXSRC_FIRST_INPUT+defaultChannel(2), "Throttle")
addMix(rollCH1, MIXSRC_FIRST_INPUT+defaultChannel(3), "Roll")
addMix(yawCH1, MIXSRC_FIRST_INPUT+defaultChannel(0), "Yaw")
addMix(pitchCH1, MIXSRC_FIRST_INPUT+defaultChannel(1), "Pitch")
end
local function confirmationMenu(event)
if dirty then
dirty = false
drawConfirmationMenu()
end
navigate(event, fieldsMax, YAW_PAGE, page)
if event == EVT_EXIT_BREAK then
return 2
elseif event == EVT_ENTER_LONG then
killEvents(event)
applySettings()
return 2
else
return 0
end
end
-- Main
local function run(event)
if event == nil then
error("Cannot be run as a model script!")
end
if page == THROTTLE_PAGE then
throttleMenu(event)
elseif page == ROLL_PAGE then
rollMenu(event)
elseif page == YAW_PAGE then
yawMenu(event)
elseif page == PITCH_PAGE then
pitchMenu(event)
elseif page == CONFIRMATION_PAGE then
return confirmationMenu(event)
end
return 0
end
return { init=init, run=run }
File diff suppressed because it is too large Load Diff
@@ -1,74 +1,74 @@
-- Navigation variables
local dirty = true
-- Model types
local modelType = 0
local MODELTYPE_PLANE = 0
--local MODELTYPE_HELI = 1
local MODELTYPE_DELTA = 1
local MODELTYPE_QUAD = 2
-- Common functions
local function fieldIncDec(event, value, max)
if event == EVT_PLUS_BREAK or event == EVT_ROT_LEFT or event == EVT_PLUS_REPT then
value = (value + max)
dirty = true
elseif event == EVT_MINUS_BREAK or event == EVT_ROT_RIGHT or event == EVT_MINUS_REPT then
value = (value + max + 2)
dirty = true
end
value = (value % (max+1))
return value
end
-- Model Type Menu
local function modelTypeSurround(index)
lcd.drawRectangle(12+47*index, 13, 48, 48)
lcd.drawPixmap(17+47*index, 8, "mark.bmp")
end
local function drawModelChoiceMenu()
lcd.clear()
lcd.drawScreenTitle("", 0, 0)
-- lcd.drawText(58, 13, "Select model type", 0)
lcd.drawPixmap( 16, 17, "plane.bmp")
--lcd.drawPixmap( 63, 17, "heli.bmp")
lcd.drawPixmap(63, 17, "delta.bmp")
lcd.drawPixmap(110, 17, "quadri.bmp")
modelTypeSurround(modelType)
end
local function modelTypeMenu(event)
if dirty == true then
drawModelChoiceMenu()
dirty = false
end
if event == EVT_ENTER_BREAK then
if modelType == MODELTYPE_PLANE then
return "plane.lua"
elseif modelType == MODELTYPE_HELI then
elseif modelType == MODELTYPE_DELTA then
return "delta.lua"
elseif modelType == MODELTYPE_QUAD then
return "multi.lua"
end
dirty = true
else
modelType = fieldIncDec(event, modelType, 2)
end
return 0
end
-- Main
local function run(event)
if event == nil then
error("Cannot be run as a model script!")
end
if event == EVT_EXIT_BREAK then
return 2
end
return modelTypeMenu(event)
end
return { run=run }
-- Navigation variables
local dirty = true
-- Model types
local modelType = 0
local MODELTYPE_PLANE = 0
--local MODELTYPE_HELI = 1
local MODELTYPE_DELTA = 1
local MODELTYPE_QUAD = 2
-- Common functions
local function fieldIncDec(event, value, max)
if event == EVT_PLUS_BREAK or event == EVT_ROT_LEFT or event == EVT_PLUS_REPT then
value = (value + max)
dirty = true
elseif event == EVT_MINUS_BREAK or event == EVT_ROT_RIGHT or event == EVT_MINUS_REPT then
value = (value + max + 2)
dirty = true
end
value = (value % (max+1))
return value
end
-- Model Type Menu
local function modelTypeSurround(index)
lcd.drawRectangle(12+47*index, 13, 48, 48)
lcd.drawPixmap(17+47*index, 8, "mark.bmp")
end
local function drawModelChoiceMenu()
lcd.clear()
lcd.drawScreenTitle("", 0, 0)
-- lcd.drawText(58, 13, "Select model type", 0)
lcd.drawPixmap( 16, 17, "plane.bmp")
--lcd.drawPixmap( 63, 17, "heli.bmp")
lcd.drawPixmap(63, 17, "delta.bmp")
lcd.drawPixmap(110, 17, "quadri.bmp")
modelTypeSurround(modelType)
end
local function modelTypeMenu(event)
if dirty == true then
drawModelChoiceMenu()
dirty = false
end
if event == EVT_ENTER_BREAK then
if modelType == MODELTYPE_PLANE then
return "plane.lua"
elseif modelType == MODELTYPE_HELI then
elseif modelType == MODELTYPE_DELTA then
return "delta.lua"
elseif modelType == MODELTYPE_QUAD then
return "multi.lua"
end
dirty = true
else
modelType = fieldIncDec(event, modelType, 2)
end
return 0
end
-- Main
local function run(event)
if event == nil then
error("Cannot be run as a model script!")
end
if event == EVT_EXIT_BREAK then
return 2
end
return modelTypeMenu(event)
end
return { run=run }
+176 -176
View File
@@ -1,176 +1,176 @@
--------------------------------------------------------------
-- Classic snake game
--
-- 2009 Led Lab @PUC-Rio www.eluaproject.net
-- Dado Sutter
-- Ives Negreiros
-- To Benjamin
---------------------------------------------------------------
local xMax = math.floor( LCD_W / 6 ) - 1
local yMax = math.floor( LCD_H / 8 ) - 1
local game_map = {}
local Head = {}
local Tail = {}
local highscore = 0
local size = 3
Tail.x = 1
Tail.y = 1
Head.x = Tail.x + ( size - 1 )
Head.y = Tail.y
local Food = {}
Food.x = false
Food.y = false
Head.dx = 1
Head.dy = 0
Tail.dx = Head.dx
Tail.dy = Head.dy
local direction = "right"
local score = 0
local function create_food()
Food.x, Food.y = math.random( xMax - 1), math.random( yMax - 1)
while game_map[ Food.x ][ Food.y ] do
Food.x, Food.y = math.random( xMax - 1 ), math.random( yMax - 1 )
end
game_map[ Food.x ][ Food.y ] = "food"
lcd.drawText( Food.x * 6, Food.y * 8+2, "@", 0 )
end
local function eat_food()
playFile("/SCRIPTS/snake.wav")
lcd.drawText( Head.x * 6, Head.y * 8, " ", 0 )
game_map[ Head.x ][ Head.y ] = nil
create_food()
score = score + 1
end
local function check_collision()
if Head.x < 0 or Head.x > xMax then
return true
elseif Head.y < 0 or Head.y > yMax then
return true
elseif ( ( game_map[ Head.x ][ Head.y ] ) and ( game_map[ Head.x ][ Head.y ] ~= "food" ) ) then
return true
end
return false
end
local function move()
if game_map[ Tail.x ][ Tail.y ] == "right" then
Tail.dx = 1
Tail.dy = 0
elseif game_map[ Tail.x ][ Tail.y ] == "left" then
Tail.dx = -1
Tail.dy = 0
elseif game_map[ Tail.x ][ Tail.y ] == "up" then
Tail.dx = 0
Tail.dy = -1
elseif game_map[ Tail.x ][ Tail.y ] == "down" then
Tail.dx = 0
Tail.dy = 1
end
game_map[ Head.x ][ Head.y ] = direction
Head.x = Head.x + Head.dx
Head.y = Head.y + Head.dy
if Head.x < 0 or Head.x > xMax or Head.y < 0 or Head.y > yMax then
return
elseif game_map[ Head.x ][ Head.y ] == "food" then
eat_food()
else
lcd.drawText(Tail.x * 6, Tail.y * 8, " ", 16)
game_map[ Tail.x ][ Tail.y ] = nil
Tail.x = Tail.x + Tail.dx
Tail.y = Tail.y + Tail.dy
end
lcd.drawText(Head.x * 6, Head.y * 8, "*", 0)
end
local function init()
food = false
lcd.clear()
size = 3
score = 0
Tail.x = 1
Tail.y = 1
Head.x = Tail.x + ( size - 1 )
Head.y = Tail.y
Head.dx = 1
Head.dy = 0
Tail.dx = Head.dx
Tail.dy = Head.dy
direction = "right"
for i = 0, xMax, 1 do
game_map[ i ] = {}
end
for i = 0, size - 1, 1 do
game_map[ Tail.x + ( i * Tail.dx ) ][ Tail.y + ( i * Tail.dy ) ] = direction
lcd.drawText( ( Tail.x + ( i * Tail.dx ) ) * 6, ( Tail.y + ( i * Tail.dy ) ) * 8, "*", 0 )
end
create_food()
end
local snakeCounter = 0
local function run(event)
if event == nil then
raise("Cannot be run as a model script!")
end
if event == EVT_EXIT_BREAK then
return 2
end
snakeCounter = snakeCounter + 1
if snakeCounter < 30 then
return 0
end
snakeCounter = 0
local dir = direction
if getValue('rud') > 100 and direction ~= "left" then
dir = "right"
Head.dx = 1
Head.dy = 0
end
if getValue('rud') < -100 and direction ~= "right" then
dir = "left"
Head.dx = -1
Head.dy = 0
end
if getValue('ele') > 100 and direction ~= "down" then
dir = "up"
Head.dx = 0
Head.dy = -1
end
if getValue('ele') < -100 and direction ~= "up" then
dir = "down"
Head.dx = 0
Head.dy = 1
end
direction = dir
move()
lcd.refresh()
if check_collision() then
return 1
end
return 0
end
return { init=init, run=run }
--------------------------------------------------------------
-- Classic snake game
--
-- 2009 Led Lab @PUC-Rio www.eluaproject.net
-- Dado Sutter
-- Ives Negreiros
-- To Benjamin
---------------------------------------------------------------
local xMax = math.floor( LCD_W / 6 ) - 1
local yMax = math.floor( LCD_H / 8 ) - 1
local game_map = {}
local Head = {}
local Tail = {}
local highscore = 0
local size = 3
Tail.x = 1
Tail.y = 1
Head.x = Tail.x + ( size - 1 )
Head.y = Tail.y
local Food = {}
Food.x = false
Food.y = false
Head.dx = 1
Head.dy = 0
Tail.dx = Head.dx
Tail.dy = Head.dy
local direction = "right"
local score = 0
local function create_food()
Food.x, Food.y = math.random( xMax - 1), math.random( yMax - 1)
while game_map[ Food.x ][ Food.y ] do
Food.x, Food.y = math.random( xMax - 1 ), math.random( yMax - 1 )
end
game_map[ Food.x ][ Food.y ] = "food"
lcd.drawText( Food.x * 6, Food.y * 8+2, "@", 0 )
end
local function eat_food()
playFile("/SCRIPTS/snake.wav")
lcd.drawText( Head.x * 6, Head.y * 8, " ", 0 )
game_map[ Head.x ][ Head.y ] = nil
create_food()
score = score + 1
end
local function check_collision()
if Head.x < 0 or Head.x > xMax then
return true
elseif Head.y < 0 or Head.y > yMax then
return true
elseif ( ( game_map[ Head.x ][ Head.y ] ) and ( game_map[ Head.x ][ Head.y ] ~= "food" ) ) then
return true
end
return false
end
local function move()
if game_map[ Tail.x ][ Tail.y ] == "right" then
Tail.dx = 1
Tail.dy = 0
elseif game_map[ Tail.x ][ Tail.y ] == "left" then
Tail.dx = -1
Tail.dy = 0
elseif game_map[ Tail.x ][ Tail.y ] == "up" then
Tail.dx = 0
Tail.dy = -1
elseif game_map[ Tail.x ][ Tail.y ] == "down" then
Tail.dx = 0
Tail.dy = 1
end
game_map[ Head.x ][ Head.y ] = direction
Head.x = Head.x + Head.dx
Head.y = Head.y + Head.dy
if Head.x < 0 or Head.x > xMax or Head.y < 0 or Head.y > yMax then
return
elseif game_map[ Head.x ][ Head.y ] == "food" then
eat_food()
else
lcd.drawText(Tail.x * 6, Tail.y * 8, " ", 16)
game_map[ Tail.x ][ Tail.y ] = nil
Tail.x = Tail.x + Tail.dx
Tail.y = Tail.y + Tail.dy
end
lcd.drawText(Head.x * 6, Head.y * 8, "*", 0)
end
local function init()
food = false
lcd.clear()
size = 3
score = 0
Tail.x = 1
Tail.y = 1
Head.x = Tail.x + ( size - 1 )
Head.y = Tail.y
Head.dx = 1
Head.dy = 0
Tail.dx = Head.dx
Tail.dy = Head.dy
direction = "right"
for i = 0, xMax, 1 do
game_map[ i ] = {}
end
for i = 0, size - 1, 1 do
game_map[ Tail.x + ( i * Tail.dx ) ][ Tail.y + ( i * Tail.dy ) ] = direction
lcd.drawText( ( Tail.x + ( i * Tail.dx ) ) * 6, ( Tail.y + ( i * Tail.dy ) ) * 8, "*", 0 )
end
create_food()
end
local snakeCounter = 0
local function run(event)
if event == nil then
raise("Cannot be run as a model script!")
end
if event == EVT_EXIT_BREAK then
return 2
end
snakeCounter = snakeCounter + 1
if snakeCounter < 30 then
return 0
end
snakeCounter = 0
local dir = direction
if getValue('rud') > 100 and direction ~= "left" then
dir = "right"
Head.dx = 1
Head.dy = 0
end
if getValue('rud') < -100 and direction ~= "right" then
dir = "left"
Head.dx = -1
Head.dy = 0
end
if getValue('ele') > 100 and direction ~= "down" then
dir = "up"
Head.dx = 0
Head.dy = -1
end
if getValue('ele') < -100 and direction ~= "up" then
dir = "down"
Head.dx = 0
Head.dy = 1
end
direction = dir
move()
lcd.refresh()
if check_collision() then
return 1
end
return 0
end
return { init=init, run=run }