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
dofile("actions.lua")

function sayhello(seconds)
    local message = string.format("Hello from LUA for %d seconds", seconds)
    rb.splash(seconds * rb.HZ, message)
end

line = 0
function printf(message)
    rb.lcd_puts(0, line, message)
    rb.lcd_update()

    line = line + 1
    if(line > rb.LCD_HEIGHT/10) then
        line = 0
    end
end

function read_file(filename)
    local fd = rb.open(filename, rb.O_RDONLY)

    if(fd < 0) then
        return nil
    end

    local text = rb.read(fd, rb.filesize(fd))
    rb.close(fd)

    return text
end

function write_file(filename, text)
    local flags = rb.O_WRONLY
    if not rb.file_exists(filename) then
        flags = flags + rb.O_CREAT
    end

    local fd = rb.open(filename, flags)

    if(fd < 0) then
        return false
    end

    local size = rb.write(fd, text)
    rb.close(fd)

    return size == string.len(text)
end

function print_r (t, indent)
  local indent = indent or ''
  local ret = ''
  for key, value in pairs(t) do
    ret = ret .. indent .. '[' .. tostring(key) .. ']'
    if type(value)=="table" then
        printf(ret .. ':')
        ret = ''
        print_r(value, indent..'    ')
    else
        printf(ret .. ' = ' .. tostring(value))
        ret = ''
    end
  end
end

-- Draw an X on the screen
rb.lcd_clear_display()
rb.lcd_drawline(0, 0, rb.LCD_WIDTH, rb.LCD_HEIGHT)
rb.lcd_drawline(rb.LCD_WIDTH, 0, 0, rb.LCD_HEIGHT)
rb.lcd_fillrect(10, 10, 10, 10)
rb.lcd_update()

printf("test")
printf(string.format("test %d", 2))
printf(string.format("a rockbox hz = %d", rb.HZ))
print_r({ a = 5, rb.HZ, {5, 3} })
--print_r(rb.actions)

seconds = 2

rb.sleep(seconds * rb.HZ)

sayhello(seconds)

rb.splash(3 * rb.HZ, rb.kbd_input())

rb.splash(3 * rb.HZ, string.format("Hi there! %d", rb.actions.ACTION_YESNO_ACCEPT))
--rb.splash(3 * rb.HZ, read_file("/test/test.lua"))
--write_file("/test/test2.lua", "haai!")

while(true) do
    action = rb.get_action(rb.contexts.CONTEXT_STD, rb.HZ/2)
    if(action == rb.actions.ACTION_TOUCHSCREEN) then
        result, x, y = rb.action_get_touchscreen_press()
        rb.splash(rb.HZ, string.format("%d %d %d", result, x, y))
    else
        rb.splash(rb.HZ/2, string.format("%d %d", action, rb.actions.ACTION_TOUCHSCREEN))
    end
    rb.yield()
end