qrcode.h 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  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. // #ifndef __cplusplus
  37. // typedef unsigned char bool;
  38. // static const bool false = 0;
  39. // static const bool true = 1;
  40. // #endif
  41. #include <stdbool.h>
  42. #include <stdint.h>
  43. // QR Code Format Encoding
  44. #define MODE_NUMERIC 0
  45. #define MODE_ALPHANUMERIC 1
  46. #define MODE_BYTE 2
  47. // Error Correction Code Levels
  48. #define ECC_LOW 0
  49. #define ECC_MEDIUM 1
  50. #define ECC_QUARTILE 2
  51. #define ECC_HIGH 3
  52. // If set to non-zero, this library can ONLY produce QR codes at that version
  53. // This saves a lot of dynamic memory, as the codeword tables are skipped
  54. #ifndef LOCK_VERSION
  55. #define LOCK_VERSION 0
  56. #endif
  57. typedef struct QRCode {
  58. uint8_t version;
  59. uint8_t size;
  60. uint8_t ecc;
  61. uint8_t mode;
  62. uint8_t mask;
  63. uint8_t* modules;
  64. } QRCode;
  65. #ifdef __cplusplus
  66. extern "C" {
  67. #endif /* __cplusplus */
  68. uint16_t qrcode_getBufferSize(uint8_t version);
  69. /* int8_t qrcode_initText(QRCode *qrcode, uint8_t *modules, uint8_t version, uint8_t ecc, const char *data); */
  70. int8_t qrcode_initBytes(
  71. QRCode* qrcode,
  72. uint8_t* modules,
  73. int8_t mode,
  74. uint8_t version,
  75. uint8_t ecc,
  76. uint8_t* data,
  77. uint16_t length);
  78. bool qrcode_getModule(QRCode* qrcode, uint8_t x, uint8_t y);
  79. #ifdef __cplusplus
  80. }
  81. #endif /* __cplusplus */
  82. #endif /* __QRCODE_H_ */