qrcode_sample.c 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. #include <rtthread.h>
  2. #include "qrcode.h"
  3. #if defined(RT_USING_FINSH) && defined(FINSH_USING_MSH)
  4. #include <finsh.h>
  5. static void qrcode(uint8_t argc, char **argv)
  6. {
  7. #define DEFAULT_QR_VERSION 3
  8. #define DEFAULT_QR_STRING "HELLO WORLD"
  9. QRCode qrc;
  10. uint8_t x, y, *qrcodeBytes = (uint8_t *)rt_calloc(1, qrcode_getBufferSize(DEFAULT_QR_VERSION));
  11. int8_t result;
  12. char *qrstr = DEFAULT_QR_STRING;
  13. if (qrcodeBytes)
  14. {
  15. if (argc > 1)
  16. {
  17. qrstr = argv[1];
  18. }
  19. result = qrcode_initText(&qrc, qrcodeBytes, DEFAULT_QR_VERSION, ECC_LOW, qrstr);
  20. if (result >= 0)
  21. {
  22. rt_kprintf("\n");
  23. for (y = 0; y < qrc.size; y++)
  24. {
  25. for (x = 0; x < qrc.size; x++)
  26. {
  27. if (qrcode_getModule(&qrc, x, y))
  28. {
  29. rt_kprintf("\xdb\xdb");
  30. }
  31. else
  32. {
  33. rt_kprintf(" ");
  34. }
  35. }
  36. rt_kprintf("\n");
  37. }
  38. }
  39. else
  40. {
  41. rt_kprintf("QR CODE(%s) General FAILED(%d)\n", qrstr, result);
  42. }
  43. rt_free(qrcodeBytes);
  44. }
  45. else
  46. {
  47. rt_kprintf("Warning: no memory!\n");
  48. }
  49. }
  50. MSH_CMD_EXPORT(qrcode, qrcode generator: qrcode [string]);
  51. #endif /* defined(RT_USING_FINSH) && defined(FINSH_USING_MSH) */