luat_lib_adc.c 1.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. /*
  2. @module adc
  3. @summary 数模转换
  4. @version 1.0
  5. @data 2020.07.03
  6. */
  7. #include "luat_base.h"
  8. #include "luat_adc.h"
  9. static int l_adc_open(lua_State *L) {
  10. if (luat_adc_open(luaL_checkinteger(L, 1), NULL) == 0) {
  11. lua_pushboolean(L, 1);
  12. }
  13. else {
  14. lua_pushboolean(L, 0);
  15. }
  16. return 1;
  17. }
  18. static int l_adc_read(lua_State *L) {
  19. int val = 0xFF;
  20. int val2 = 0xFF;
  21. if (luat_adc_read(luaL_checkinteger(L, 1), &val, &val2) == 0) {
  22. lua_pushinteger(L, val);
  23. lua_pushinteger(L, val2);
  24. return 2;
  25. }
  26. else {
  27. lua_pushinteger(L, 0xFF);
  28. return 1;
  29. }
  30. }
  31. static int l_adc_close(lua_State *L) {
  32. luat_adc_close(luaL_checkinteger(L, 1));
  33. return 0;
  34. }
  35. #include "rotable.h"
  36. static const rotable_Reg reg_adc[] =
  37. {
  38. { "open" , l_adc_open , 0},
  39. { "read" , l_adc_read , 0},
  40. { "close" , l_adc_close, 0},
  41. { NULL, NULL , 0}
  42. };
  43. LUAMOD_API int luaopen_adc( lua_State *L ) {
  44. rotable_newlib(L, reg_adc);
  45. return 1;
  46. }