From 8e42631a818dfd4a5b847639ccaa38e2717f3122 Mon Sep 17 00:00:00 2001 From: devsaurus Date: Thu, 19 Feb 2015 12:12:14 +0100 Subject: [PATCH] implement drawBitmap --- README.md | 6 +++--- app/modules/u8g.c | 21 +++++++++++++++++++++ lua_examples/u8g_bitmaps.lua | 11 ++++++++--- lua_examples/u8g_rook.bm | Bin 0 -> 8 bytes 4 files changed, 32 insertions(+), 6 deletions(-) create mode 100644 lua_examples/u8g_rook.bm diff --git a/README.md b/README.md index f4cf9c85..42712dc1 100644 --- a/README.md +++ b/README.md @@ -368,9 +368,9 @@ They'll be available as `u8g.` in Lua. - [ ] setCursorFont() - [ ] setCursorPos() - [ ] setCursorStyle() -- [ ] Bitmaps - - [ ] drawBitmap() - - [ ] drawXBM() +- [x] Bitmaps + - [x] drawBitmap() + - [x] drawXBM() - [ ] General functions - [x] begin() - [ ] print() diff --git a/app/modules/u8g.c b/app/modules/u8g.c index e91b4f5b..316ccddd 100644 --- a/app/modules/u8g.c +++ b/app/modules/u8g.c @@ -596,6 +596,26 @@ static int lu8g_drawXBM( lua_State *L ) return 0; } +// Lua: u8g.drawBitmap( self, x, y, count, height, data ) +static int lu8g_drawBitmap( lua_State *L ) +{ + lu8g_userdata_t *lud; + + if ((lud = get_lud( L )) == NULL) + return 0; + + u8g_uint_t args[4]; + lu8g_get_int_args( L, 2, 4, args ); + + const char *bm_data = luaL_checkstring( L, (1+4) + 1 ); + if (bm_data == NULL) + return 0; + + u8g_DrawBitmap( lud, args[0], args[1], args[2], args[3], (const uint8_t *)bm_data ); + + return 0; +} + // Lua: u8g.setScale2x2( self ) static int lu8g_setScale2x2( lua_State *L ) { @@ -951,6 +971,7 @@ static const LUA_REG_TYPE lu8g_display_map[] = { LSTRKEY( "drawPixel" ), LFUNCVAL( lu8g_drawPixel ) }, { LSTRKEY( "drawHLine" ), LFUNCVAL( lu8g_drawHLine ) }, { LSTRKEY( "drawVLine" ), LFUNCVAL( lu8g_drawVLine ) }, + { LSTRKEY( "drawBitmap" ), LFUNCVAL( lu8g_drawBitmap ) }, { LSTRKEY( "drawXBM" ), LFUNCVAL( lu8g_drawXBM ) }, { LSTRKEY( "setScale2x2" ), LFUNCVAL( lu8g_setScale2x2 ) }, { LSTRKEY( "undoScale" ), LFUNCVAL( lu8g_undoScale ) }, diff --git a/lua_examples/u8g_bitmaps.lua b/lua_examples/u8g_bitmaps.lua index 43f49d8c..0a8ac8e7 100644 --- a/lua_examples/u8g_bitmaps.lua +++ b/lua_examples/u8g_bitmaps.lua @@ -15,11 +15,11 @@ function xbm_picture() disp:drawXBM( 0, 20, 38, 24, xbm_data ) end -function bitmap_picture() +function bitmap_picture(state) disp:setFont(u8g.font_6x10) disp:drawStr( 0, 10, "Bitmap picture") - --disp:drawXBM( 0, 20, 38, 24, bitmap_data ) + disp:drawBitmap( 0 + (state * 10), 20 + (state * 4), 1, 8, bm_data ) end -- the draw() routine @@ -42,12 +42,17 @@ function bitmap_test() xbm_data = file.read() file.close() + -- read Bitmap picture + file.open("u8g_rook.bm", "r") + bm_data = file.read() + file.close() + print("--- Starting Bitmap Test ---") dir = 0 next_rotation = 0 local draw_state - for draw_state = 1, 7 + 0*8, 1 do + for draw_state = 1, 7 + 1*8, 1 do disp:firstPage() repeat draw(draw_state) diff --git a/lua_examples/u8g_rook.bm b/lua_examples/u8g_rook.bm new file mode 100644 index 0000000000000000000000000000000000000000..9dd93966f264609e124d1438e97c63b29a56c805 GIT binary patch literal 8 NcmZPwt+xY$dH@MH0!#n^ literal 0 HcmV?d00001