camera_suite_view_camera.h 3.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  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. #ifdef xtreme_settings
  18. /**
  19. * Enable the following line for "Xtreme Firmware" & "Xtreme Apps" (Flipper-XFW).
  20. *
  21. * @see https://github.com/Flipper-XFW/Xtreme-Firmware
  22. * @see https://github.com/Flipper-XFW/Xtreme-Apps
  23. */
  24. #define UART_CH (xtreme_settings.uart_esp_channel)
  25. #elif defined momentum_settings
  26. /**
  27. * Enable the following line for "Momentum Firmware" & "Momentum Apps".
  28. *
  29. * @see https://github.com/Next-Flip/Momentum-Firmware
  30. * @see https://github.com/Next-Flip/Momentum-Apps
  31. */
  32. #include <momentum/momentum.h>
  33. #define UART_CH (momentum_settings.uart_esp_channel)
  34. #else
  35. #define UART_CH (FuriHalSerialIdUsart)
  36. #endif
  37. #define BITMAP_HEADER_LENGTH 62
  38. #define FRAME_BIT_DEPTH 1
  39. #define FRAME_BUFFER_LENGTH 1024
  40. #define FRAME_HEIGHT 64
  41. #define FRAME_WIDTH 128
  42. #define HEADER_LENGTH 3 // 'Y', ':', and row identifier
  43. #define LAST_ROW_INDEX 1008
  44. #define RING_BUFFER_LENGTH 19
  45. #define ROW_BUFFER_LENGTH 16
  46. static const unsigned char bitmap_header[BITMAP_HEADER_LENGTH] = {
  47. 0x42, 0x4D, 0x3E, 0x04, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x3E, 0x00, 0x00, 0x00, 0x28, 0x00,
  48. 0x00, 0x00, 0x80, 0x00, 0x00, 0x00, 0x40, 0x00, 0x00, 0x00, 0x01, 0x00, 0x01, 0x00, 0x00, 0x00,
  49. 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  50. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xFF, 0xFF, 0xFF, 0x00};
  51. typedef enum {
  52. WorkerEventReserved = (1 << 0), // Reserved for StreamBuffer internal event
  53. WorkerEventStop = (1 << 1),
  54. WorkerEventRx = (1 << 2),
  55. } WorkerEventFlags;
  56. #define CAMERA_WORKER_EVENTS_MASK (WorkerEventStop | WorkerEventRx)
  57. // Forward declaration
  58. typedef void (*CameraSuiteViewCameraCallback)(CameraSuiteCustomEvent event, void* context);
  59. typedef struct CameraSuiteViewCamera {
  60. CameraSuiteViewCameraCallback callback;
  61. FuriStreamBuffer* camera_rx_stream;
  62. FuriHalSerialHandle* serial_handle;
  63. FuriThread* camera_worker_thread;
  64. NotificationApp* notification;
  65. View* view;
  66. void* context;
  67. } CameraSuiteViewCamera;
  68. typedef struct UartDumpModel {
  69. bool is_dithering_enabled;
  70. bool is_initialized;
  71. bool is_inverted;
  72. int rotation_angle;
  73. uint32_t orientation;
  74. uint8_t pixels[FRAME_BUFFER_LENGTH];
  75. uint8_t ringbuffer_index;
  76. uint8_t row_identifier;
  77. uint8_t row_ringbuffer[RING_BUFFER_LENGTH];
  78. } UartDumpModel;
  79. // Function Prototypes
  80. CameraSuiteViewCamera* camera_suite_view_camera_alloc();
  81. View* camera_suite_view_camera_get_view(CameraSuiteViewCamera* camera_suite_static);
  82. void camera_suite_view_camera_free(CameraSuiteViewCamera* camera_suite_static);
  83. void camera_suite_view_camera_set_callback(
  84. CameraSuiteViewCamera* camera_suite_view_camera,
  85. CameraSuiteViewCameraCallback callback,
  86. void* context);