u8g2_qrcode.c 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. #include "u8g2/u8g2.h"
  2. #include "qrcode/qrcode.h"
  3. #include <furi.h>
  4. /*
  5. TODO: rework with new app api
  6. void u8g2_DrawPixelSize(u8g2_t* u8g2, uint8_t x, uint8_t y, uint8_t size) {
  7. for(uint8_t px = 0; px < size; px++) {
  8. for(uint8_t py = 0; py < size; py++) {
  9. u8g2_DrawPixel(u8g2, x + px, y + py);
  10. }
  11. }
  12. }
  13. int32_t u8g2_qrcode(void* p) {
  14. // open record
  15. FuriRecordSubscriber* fb_record =
  16. furi_open_deprecated("u8g2_fb", false, false, NULL, NULL, NULL);
  17. // Allocate a chunk of memory to store the QR code
  18. // https://github.com/ricmoo/QRCode
  19. // we init version 1, 21x21 px, 16 alphanumeric chars with
  20. // QUARTILE error correction
  21. const uint8_t qr_version = 1;
  22. const uint8_t qr_error_correction = ECC_QUARTILE;
  23. const uint8_t qr_x = 32;
  24. const uint8_t qr_y = 0;
  25. const uint8_t qr_size = 3;
  26. // The structure to manage the QR code
  27. QRCode qrcode;
  28. // QR Code init
  29. uint8_t qrcodeBytes[qrcode_getBufferSize(qr_version)];
  30. qrcode_initText(&qrcode, qrcodeBytes, qr_version, qr_error_correction, "HELLO FLIPPER");
  31. if(fb_record == NULL) {
  32. printf("[view_port] cannot create fb record\r\n");
  33. return 255;
  34. }
  35. u8g2_t* fb = furi_take(fb_record);
  36. // clear display
  37. if(fb != NULL) {
  38. u8g2_ClearBuffer(fb);
  39. }
  40. while(1) {
  41. if(fb != NULL) {
  42. // draw qr code
  43. for(uint8_t y = 0; y < qrcode.size; y++) {
  44. for(uint8_t x = 0; x < qrcode.size; x++) {
  45. if(qrcode_getModule(&qrcode, x, y)) {
  46. u8g2_SetDrawColor(fb, 1);
  47. u8g2_DrawPixelSize(fb, qr_x + x * qr_size, qr_y + y * qr_size, qr_size);
  48. } else {
  49. u8g2_SetDrawColor(fb, 0);
  50. u8g2_DrawPixelSize(fb, qr_x + x * qr_size, qr_y + y * qr_size, qr_size);
  51. }
  52. }
  53. }
  54. } else {
  55. return 255;
  56. }
  57. furi_commit(fb_record);
  58. delay(1);
  59. }
  60. return 0;
  61. }
  62. */