barcode_utils.h 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. #pragma once
  2. #include <furi.h>
  3. #include <furi_hal.h>
  4. #define NUMBER_OF_BARCODE_TYPES 8
  5. typedef enum {
  6. WrongNumberOfDigits, //There is too many or too few digits in the barcode
  7. InvalidCharacters, //The barcode contains invalid characters
  8. UnsupportedType, //the barcode type is not supported
  9. FileOpening, //A problem occurred when opening the barcode data file
  10. InvalidFileData, //One of the key in the file doesn't exist or there is a typo
  11. MissingEncodingTable, //The encoding table txt for the barcode type is missing
  12. EncodingTableError, //Something is wrong with the encoding table, probably missing data or typo
  13. OKCode
  14. } ErrorCode;
  15. typedef enum {
  16. UPCA,
  17. EAN8,
  18. EAN13,
  19. CODE39,
  20. CODE128,
  21. CODE128C,
  22. CODABAR,
  23. UNKNOWN
  24. } BarcodeType;
  25. typedef struct {
  26. char* name; //The name of the barcode type
  27. BarcodeType type; //The barcode type enum
  28. int min_digits; //the minimum number of digits
  29. int max_digits; //the maximum number of digits
  30. int start_pos; //where to start drawing the barcode, set to -1 to dynamically draw barcode
  31. } BarcodeTypeObj;
  32. typedef struct {
  33. BarcodeTypeObj* type_obj;
  34. int check_digit; //A place to store the check digit
  35. FuriString* raw_data; //the data directly from the file
  36. FuriString* correct_data; //the corrected/processed data
  37. bool valid; //true if the raw data is correctly formatted, such as correct num of digits, valid characters, etc.
  38. ErrorCode reason; //the reason why this barcode is invalid
  39. } BarcodeData;
  40. //All available barcode types
  41. extern BarcodeTypeObj* barcode_type_objs[NUMBER_OF_BARCODE_TYPES];
  42. void init_types();
  43. void free_types();
  44. BarcodeTypeObj* get_type(FuriString* type_string);
  45. const char* get_error_code_name(ErrorCode error_code);
  46. const char* get_error_code_message(ErrorCode error_code);