Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
ruanhaishen
Nodemcu Firmware
Commits
9b3ea241
Commit
9b3ea241
authored
Feb 17, 2015
by
Vowstar
Browse files
Merge pull request #226 from devsaurus/dev
Include u8glib
parents
378398d4
4fd11fdf
Changes
102
Show whitespace changes
Inline
Side-by-side
lua_examples/u8g_graphics_test.lua
0 → 100644
View file @
9b3ea241
-- setup I2c and connect display
function
init_i2c_display
()
sda
=
5
scl
=
6
sla
=
0x3c
i2c
.
setup
(
0
,
sda
,
scl
,
i2c
.
SLOW
)
disp
=
u8g
.
ssd1306_128x64_i2c
(
sla
)
end
-- graphic test components
function
prepare
()
disp
:
setFont
(
u8g
.
font_6x10
)
disp
:
setFontRefHeightExtendedText
()
disp
:
setDefaultForegroundColor
()
disp
:
setFontPosTop
()
end
function
box_frame
(
a
)
disp
:
drawStr
(
0
,
0
,
"drawBox"
)
disp
:
drawBox
(
5
,
10
,
20
,
10
)
disp
:
drawBox
(
10
+
a
,
15
,
30
,
7
)
disp
:
drawStr
(
0
,
30
,
"drawFrame"
)
disp
:
drawFrame
(
5
,
10
+
30
,
20
,
10
)
disp
:
drawFrame
(
10
+
a
,
15
+
30
,
30
,
7
)
end
function
disc_circle
(
a
)
disp
:
drawStr
(
0
,
0
,
"drawDisc"
)
disp
:
drawDisc
(
10
,
18
,
9
)
disp
:
drawDisc
(
24
+
a
,
16
,
7
)
disp
:
drawStr
(
0
,
30
,
"drawCircle"
)
disp
:
drawCircle
(
10
,
18
+
30
,
9
)
disp
:
drawCircle
(
24
+
a
,
16
+
30
,
7
)
end
function
r_frame
(
a
)
disp
:
drawStr
(
0
,
0
,
"drawRFrame/Box"
)
disp
:
drawRFrame
(
5
,
10
,
40
,
30
,
a
+
1
)
disp
:
drawRBox
(
50
,
10
,
25
,
40
,
a
+
1
)
end
function
stringtest
(
a
)
disp
:
drawStr
(
30
+
a
,
31
,
" 0"
)
disp
:
drawStr90
(
30
,
31
+
a
,
" 90"
)
disp
:
drawStr180
(
30
-
a
,
31
,
" 180"
)
disp
:
drawStr270
(
30
,
31
-
a
,
" 270"
)
end
function
line
(
a
)
disp
:
drawStr
(
0
,
0
,
"drawLine"
)
disp
:
drawLine
(
7
+
a
,
10
,
40
,
55
)
disp
:
drawLine
(
7
+
a
*
2
,
10
,
60
,
55
)
disp
:
drawLine
(
7
+
a
*
3
,
10
,
80
,
55
)
disp
:
drawLine
(
7
+
a
*
4
,
10
,
100
,
55
)
end
function
triangle
(
a
)
local
offset
=
a
disp
:
drawStr
(
0
,
0
,
"drawTriangle"
)
disp
:
drawTriangle
(
14
,
7
,
45
,
30
,
10
,
40
)
disp
:
drawTriangle
(
14
+
offset
,
7
-
offset
,
45
+
offset
,
30
-
offset
,
57
+
offset
,
10
-
offset
)
disp
:
drawTriangle
(
57
+
offset
*
2
,
10
,
45
+
offset
*
2
,
30
,
86
+
offset
*
2
,
53
)
disp
:
drawTriangle
(
10
+
offset
,
40
+
offset
,
45
+
offset
,
30
+
offset
,
86
+
offset
,
53
+
offset
)
end
function
ascii_1
()
local
x
,
y
,
s
disp
:
drawStr
(
0
,
0
,
"ASCII page 1"
)
for
y
=
0
,
5
,
1
do
for
x
=
0
,
15
,
1
do
s
=
y
*
16
+
x
+
32
disp
:
drawStr
(
x
*
7
,
y
*
10
+
10
,
string.char
(
s
))
end
end
end
function
ascii_2
()
local
x
,
y
,
s
disp
:
drawStr
(
0
,
0
,
"ASCII page 2"
)
for
y
=
0
,
5
,
1
do
for
x
=
0
,
15
,
1
do
s
=
y
*
16
+
x
+
160
disp
:
drawStr
(
x
*
7
,
y
*
10
+
10
,
string.char
(
s
))
end
end
end
function
extra_page
(
a
)
disp
:
drawStr
(
0
,
12
,
"setScale2x2"
)
disp
:
setScale2x2
()
disp
:
drawStr
(
0
,
6
+
a
,
"setScale2x2"
)
disp
:
undoScale
()
end
-- the draw() routine
function
draw
(
draw_state
)
local
component
=
bit
.
rshift
(
draw_state
,
3
)
prepare
()
if
(
component
==
0
)
then
box_frame
(
bit
.
band
(
draw_state
,
7
))
elseif
(
component
==
1
)
then
disc_circle
(
bit
.
band
(
draw_state
,
7
))
elseif
(
component
==
2
)
then
r_frame
(
bit
.
band
(
draw_state
,
7
))
elseif
(
component
==
3
)
then
stringtest
(
bit
.
band
(
draw_state
,
7
))
elseif
(
component
==
4
)
then
line
(
bit
.
band
(
draw_state
,
7
))
elseif
(
component
==
5
)
then
triangle
(
bit
.
band
(
draw_state
,
7
))
elseif
(
component
==
6
)
then
ascii_1
()
elseif
(
component
==
7
)
then
ascii_2
()
elseif
(
component
==
8
)
then
extra_page
(
bit
.
band
(
draw_state
,
7
))
end
end
function
graphics_test
()
init_i2c_display
()
print
(
"--- Starting Graphics Test ---"
)
-- cycle through all components
local
draw_state
for
draw_state
=
0
,
7
+
8
*
8
,
1
do
disp
:
firstPage
()
repeat
draw
(
draw_state
)
until
disp
:
nextPage
()
==
false
--print(node.heap())
-- re-trigger Watchdog!
tmr
.
wdclr
()
end
print
(
"--- Graphics Test done ---"
)
end
graphics_test
()
lua_examples/u8g_rotation.lua
0 → 100644
View file @
9b3ea241
-- setup I2c and connect display
function
init_i2c_display
()
sda
=
5
scl
=
6
sla
=
0x3c
i2c
.
setup
(
0
,
sda
,
scl
,
i2c
.
SLOW
)
disp
=
u8g
.
ssd1306_128x64_i2c
(
sla
)
end
-- the draw() routine
function
draw
()
disp
:
setFont
(
u8g
.
font_6x10
)
disp
:
drawStr
(
0
+
0
,
20
+
0
,
"Hello!"
)
disp
:
drawStr
(
0
+
2
,
20
+
16
,
"Hello!"
)
disp
:
drawBox
(
0
,
0
,
3
,
3
)
disp
:
drawBox
(
disp
:
getWidth
()
-
6
,
0
,
6
,
6
)
disp
:
drawBox
(
disp
:
getWidth
()
-
9
,
disp
:
getHeight
()
-
9
,
9
,
9
)
disp
:
drawBox
(
0
,
disp
:
getHeight
()
-
12
,
12
,
12
)
end
function
rotate
()
if
(
next_rotation
<
tmr
.
now
()
/
1000
)
then
if
(
dir
==
0
)
then
disp
:
undoRotation
()
elseif
(
dir
==
1
)
then
disp
:
setRot90
()
elseif
(
dir
==
2
)
then
disp
:
setRot180
()
elseif
(
dir
==
3
)
then
disp
:
setRot270
()
end
dir
=
dir
+
1
dir
=
bit
.
band
(
dir
,
3
)
next_rotation
=
tmr
.
now
()
/
1000
+
1000
end
end
function
rotation_test
()
init_i2c_display
()
print
(
"--- Starting Rotation Test ---"
)
dir
=
0
next_rotation
=
0
local
loopcnt
for
loopcnt
=
1
,
100
,
1
do
rotate
()
disp
:
firstPage
()
repeat
draw
(
draw_state
)
until
disp
:
nextPage
()
==
false
tmr
.
wdclr
()
end
print
(
"--- Rotation Test done ---"
)
end
rotation_test
()
Prev
1
2
3
4
5
6
Next
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment