luat_lib_lvgl_gauge_ex.c 885 B

123456789101112131415161718192021222324252627282930
  1. /*
  2. @module lvgl
  3. @summary LVGL图像库
  4. @version 1.0
  5. @date 2021.06.01
  6. */
  7. #include "luat_base.h"
  8. #include "lvgl.h"
  9. #include "luat_lvgl.h"
  10. #include "luat_malloc.h"
  11. int luat_lv_gauge_set_needle_count(lua_State *L) {
  12. LV_DEBUG("CALL lv_gauge_set_needle_count");
  13. lv_obj_t* gauge = (lv_obj_t*)lua_touserdata(L, 1);
  14. uint8_t needle_cnt = (uint8_t)luaL_checkinteger(L, 2);
  15. lv_color_t *colors = (lv_color_t*)luat_heap_calloc(needle_cnt,sizeof(lv_color_t));
  16. if (lua_istable(L,3)){
  17. for (int i = 0; i < needle_cnt; i++) {
  18. lua_pushinteger(L, i+1);
  19. if (LUA_TNUMBER == lua_gettable(L, 3)) {
  20. colors[i].full = luaL_checkinteger(L, -1);
  21. }
  22. lua_pop(L, 1);
  23. }
  24. }
  25. lv_gauge_set_needle_count(gauge, needle_cnt,colors);
  26. //luat_heap_free(colors);
  27. return 0;
  28. }