-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathblink_merge.lua
51 lines (40 loc) · 1.04 KB
/
blink_merge.lua
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
#!/usr/bin/lua
-- if #arg ~= 1 then
-- print("Missing sketch file name")
-- return 1
-- end
local uploaded_name = "./Blink.ino.hex"
local destination_file = "./mega2560.hex"
local io = require("io")
local uploaded_sketch = io.open(uploaded_name)
if not uploaded_sketch then
print("Unable to open file " .. uploaded_name .. " for reading")
return 1
end
local sketch = {}
for line in uploaded_sketch:lines() do
table.insert(sketch, line)
end
uploaded_sketch:close()
--removes last line
table.remove(sketch)
for line in io.lines("./stk500boot_v2_mega2560.hex") do
table.insert(sketch, line)
end
local final_sketch = io.open(destination_file, "w+")
if not final_sketch then
print("Unable to open file " .. uploaded_name .. " for writing")
return 1
end
for idx, line in ipairs(sketch) do
line = string.gsub(line, "\n", "")
line = string.gsub(line, "\r", "")
line = string.gsub(line, " ", "")
if line ~= "" then
final_sketch:write(line)
final_sketch:write("\n")
end
end
final_sketch:flush()
final_sketch:close()
return 0