camera_suite_view_camera.h 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. #pragma once
  2. #include <furi.h>
  3. #include <furi_hal.h>
  4. #include <furi_hal_serial_control.h>
  5. #include <furi_hal_serial.h>
  6. #include <gui/elements.h>
  7. #include <gui/gui.h>
  8. #include <gui/icon_i.h>
  9. #include <gui/modules/dialog_ex.h>
  10. #include <gui/view.h>
  11. #include <gui/view_dispatcher.h>
  12. #include <notification/notification.h>
  13. #include <notification/notification_messages.h>
  14. #include <storage/filesystem_api_defines.h>
  15. #include <storage/storage.h>
  16. #include "../helpers/camera_suite_custom_event.h"
  17. #include <xtreme/xtreme.h>
  18. #define UART_CH (xtreme_settings.uart_esp_channel)
  19. #define BITMAP_HEADER_LENGTH 62
  20. #define FRAME_BIT_DEPTH 1
  21. #define FRAME_BUFFER_LENGTH 1024
  22. #define FRAME_HEIGHT 64
  23. #define FRAME_WIDTH 128
  24. #define HEADER_LENGTH 3 // 'Y', ':', and row identifier
  25. #define LAST_ROW_INDEX 1008
  26. #define RING_BUFFER_LENGTH 19
  27. #define ROW_BUFFER_LENGTH 16
  28. static const unsigned char bitmap_header[BITMAP_HEADER_LENGTH] = {
  29. 0x42, 0x4D, 0x3E, 0x04, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x3E, 0x00, 0x00, 0x00, 0x28, 0x00,
  30. 0x00, 0x00, 0x80, 0x00, 0x00, 0x00, 0x40, 0x00, 0x00, 0x00, 0x01, 0x00, 0x01, 0x00, 0x00, 0x00,
  31. 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  32. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xFF, 0xFF, 0xFF, 0x00};
  33. typedef enum {
  34. WorkerEventReserved = (1 << 0), // Reserved for StreamBuffer internal event
  35. WorkerEventStop = (1 << 1),
  36. WorkerEventRx = (1 << 2),
  37. } WorkerEventFlags;
  38. #define WORKER_EVENTS_MASK (WorkerEventStop | WorkerEventRx)
  39. // Forward declaration
  40. typedef void (*CameraSuiteViewCameraCallback)(CameraSuiteCustomEvent event, void* context);
  41. typedef struct CameraSuiteViewCamera {
  42. CameraSuiteViewCameraCallback callback;
  43. FuriStreamBuffer* rx_stream;
  44. FuriHalSerialHandle* serial_handle;
  45. FuriThread* worker_thread;
  46. NotificationApp* notification;
  47. View* view;
  48. void* context;
  49. } CameraSuiteViewCamera;
  50. typedef struct UartDumpModel {
  51. bool is_dithering_enabled;
  52. bool is_initialized;
  53. bool is_inverted;
  54. int rotation_angle;
  55. uint32_t orientation;
  56. uint8_t pixels[FRAME_BUFFER_LENGTH];
  57. uint8_t ringbuffer_index;
  58. uint8_t row_identifier;
  59. uint8_t row_ringbuffer[RING_BUFFER_LENGTH];
  60. } UartDumpModel;
  61. // Function Prototypes
  62. CameraSuiteViewCamera* camera_suite_view_camera_alloc();
  63. View* camera_suite_view_camera_get_view(CameraSuiteViewCamera* camera_suite_static);
  64. void camera_suite_view_camera_free(CameraSuiteViewCamera* camera_suite_static);
  65. void camera_suite_view_camera_set_callback(
  66. CameraSuiteViewCamera* camera_suite_view_camera,
  67. CameraSuiteViewCameraCallback callback,
  68. void* context);