barcode_generator.h 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  1. #pragma once
  2. #include <furi.h>
  3. #include <gui/gui.h>
  4. #include <input/input.h>
  5. #include <stdlib.h>
  6. #include <storage/storage.h>
  7. #include <toolbox/saved_struct.h>
  8. #define BARCODE_SETTINGS_FILE_NAME "apps/Misc/barcodegen.save"
  9. #define BARCODE_SETTINGS_VER (1)
  10. #define BARCODE_SETTINGS_PATH EXT_PATH(BARCODE_SETTINGS_FILE_NAME)
  11. #define BARCODE_SETTINGS_MAGIC (0xC2)
  12. #define SAVE_BARCODE_SETTINGS(x) \
  13. saved_struct_save( \
  14. BARCODE_SETTINGS_PATH, \
  15. (x), \
  16. sizeof(BarcodeState), \
  17. BARCODE_SETTINGS_MAGIC, \
  18. BARCODE_SETTINGS_VER)
  19. #define LOAD_BARCODE_SETTINGS(x) \
  20. saved_struct_load( \
  21. BARCODE_SETTINGS_PATH, \
  22. (x), \
  23. sizeof(BarcodeState), \
  24. BARCODE_SETTINGS_MAGIC, \
  25. BARCODE_SETTINGS_VER)
  26. #define BARCODE_HEIGHT 50
  27. #define BARCODE_Y_START 3
  28. #define BARCODE_TEXT_OFFSET 9
  29. #define BARCODE_MAX_LENS 13
  30. #define NUMBER_OF_BARCODE_TYPES 3
  31. #define MENU_INDEX_VIEW 0
  32. #define MENU_INDEX_EDIT 1
  33. #define MENU_INDEX_PARITY 2
  34. #define MENU_INDEX_TYPE 3
  35. typedef enum {
  36. EventTypeTick,
  37. EventTypeKey,
  38. } EventType;
  39. typedef struct {
  40. EventType type;
  41. InputEvent input;
  42. } PluginEvent;
  43. typedef enum {
  44. ViewMode,
  45. EditMode,
  46. MenuMode,
  47. } Mode;
  48. typedef enum {
  49. BarEncodingTypeLeft,
  50. BarEncodingTypeRight,
  51. BarEncodingTypeG,
  52. } BarEncodingType;
  53. typedef enum {
  54. BarTypeEAN8,
  55. BarTypeUPCA,
  56. BarTypeEAN13,
  57. } BarType;
  58. typedef struct {
  59. char* name;
  60. int numberOfDigits;
  61. int startPos;
  62. BarType bartype;
  63. } BarcodeType;
  64. typedef struct {
  65. int barcodeNumeral[BARCODE_MAX_LENS]; //The current barcode number
  66. bool doParityCalculation; //Should do parity check?
  67. int barcodeTypeIndex;
  68. } BarcodeState;
  69. typedef struct {
  70. FuriMutex* mutex;
  71. BarcodeState barcode_state;
  72. int editingIndex; //The index of the editing symbol
  73. int menuIndex; //The index of the menu cursor
  74. Mode mode; //View, edit or menu
  75. } PluginState;
  76. static const int DIGITS[10][4] = {
  77. {3, 2, 1, 1},
  78. {2, 2, 2, 1},
  79. {2, 1, 2, 2},
  80. {1, 4, 1, 1},
  81. {1, 1, 3, 2},
  82. {1, 2, 3, 1},
  83. {1, 1, 1, 4},
  84. {1, 3, 1, 2},
  85. {1, 2, 1, 3},
  86. {3, 1, 1, 2},
  87. };
  88. static const uint8_t EAN13ENCODE[10] = {
  89. 0b000000,
  90. 0b110100,
  91. 0b101100,
  92. 0b011100,
  93. 0b110010,
  94. 0b100110,
  95. 0b001110,
  96. 0b101010,
  97. 0b011010,
  98. 0b010110,
  99. };