qrcode.h 2.5 KB

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