qrcode.h 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  1. /**
  2. * The MIT License (MIT)
  3. *
  4. * This library is written and maintained by Richard Moore.
  5. * Major parts were derived from Project Nayuki's library.
  6. *
  7. * Copyright (c) 2017 Richard Moore (https://github.com/ricmoo/QRCode)
  8. * Copyright (c) 2017 Project Nayuki (https://www.nayuki.io/page/qr-code-generator-library)
  9. *
  10. * Permission is hereby granted, free of charge, to any person obtaining a copy
  11. * of this software and associated documentation files (the "Software"), to deal
  12. * in the Software without restriction, including without limitation the rights
  13. * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  14. * copies of the Software, and to permit persons to whom the Software is
  15. * furnished to do so, subject to the following conditions:
  16. *
  17. * The above copyright notice and this permission notice shall be included in
  18. * all copies or substantial portions of the Software.
  19. *
  20. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  21. * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  22. * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  23. * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  24. * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  25. * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  26. * THE SOFTWARE.
  27. */
  28. /**
  29. * Special thanks to Nayuki (https://www.nayuki.io/) from which this library was
  30. * heavily inspired and compared against.
  31. *
  32. * See: https://github.com/nayuki/QR-Code-generator/tree/master/cpp
  33. */
  34. #ifndef __QRCODE_H_
  35. #define __QRCODE_H_
  36. #include <stdint.h>
  37. #define SIZE_17X17 0
  38. #define SIZE_21X21 1
  39. #define SIZE_25X25 2
  40. #define SIZE_29X29 3
  41. #define SIZE_33X33 4
  42. #define SIZE_37X37 5
  43. #define SIZE_41X41 6
  44. #define SIZE_45X45 7
  45. #define SIZE_49X49 8
  46. #define SIZE_53X53 9
  47. #define TRUE 1
  48. #define FALSE 0
  49. // QR Code Format Encoding
  50. #define MODE_NUMERIC 0
  51. #define MODE_ALPHANUMERIC 1
  52. #define MODE_BYTE 2
  53. // Error Correction Code Levels
  54. #define ECC_LOW 0
  55. #define ECC_MEDIUM 1
  56. #define ECC_QUARTILE 2
  57. #define ECC_HIGH 3
  58. // If set to non-zero, this library can ONLY produce QR codes at that version
  59. // This saves a lot of dynamic memory, as the codeword tables are skipped
  60. #ifndef LOCK_VERSION
  61. #define LOCK_VERSION 0
  62. #endif
  63. typedef struct QRCode {
  64. uint8_t version;
  65. uint8_t size;
  66. uint8_t ecc;
  67. uint8_t mode;
  68. uint8_t mask;
  69. uint8_t *modules;
  70. } QRCode;
  71. #ifdef __cplusplus
  72. extern "C"{
  73. #endif /* __cplusplus */
  74. uint16_t qrcode_getBufferSize(uint8_t version);
  75. int8_t qrcode_initText(QRCode *qrcode, uint8_t *modules, uint8_t version, uint8_t ecc, const char *data);
  76. int8_t qrcode_initBytes(QRCode *qrcode, uint8_t *modules, uint8_t version, uint8_t ecc, uint8_t *data, uint16_t length);
  77. uint8_t qrcode_getModule(QRCode *qrcode, uint8_t x, uint8_t y);
  78. #ifdef __cplusplus
  79. }
  80. #endif /* __cplusplus */
  81. #endif /* __QRCODE_H_ */