Skip to content

Commit 753cc99

Browse files
authored
Merge pull request #9 from CodyTolene/ct/issue-4-add-screen-orientation-function-and-setting
Add 'Orientation' setting and functionality.
2 parents c144ee3 + a5b3f6e commit 753cc99

8 files changed

+77
-29
lines changed

src-fap/camera-suite.c

+4-3
Original file line numberDiff line numberDiff line change
@@ -43,9 +43,10 @@ CameraSuite* camera_suite_app_alloc() {
4343
app->submenu = submenu_alloc();
4444

4545
// Set defaults, in case no config loaded
46-
app->haptic = 1;
47-
app->speaker = 1;
48-
app->led = 1;
46+
app->orientation = 0; // Orientation is "portrait", zero degrees by default.
47+
app->haptic = 1; // Haptic is on by default
48+
app->speaker = 1; // Speaker is on by default
49+
app->led = 1; // LED is on by default
4950

5051
// Load configs
5152
camera_suite_read_settings(app);

src-fap/camera-suite.h

+8
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ typedef struct {
3232
CameraSuiteViewStyle1* camera_suite_view_style_1;
3333
CameraSuiteViewStyle2* camera_suite_view_style_2;
3434
CameraSuiteViewGuide* camera_suite_view_guide;
35+
uint32_t orientation;
3536
uint32_t haptic;
3637
uint32_t speaker;
3738
uint32_t led;
@@ -47,6 +48,13 @@ typedef enum {
4748
CameraSuiteViewIdSettings,
4849
} CameraSuiteViewId;
4950

51+
typedef enum {
52+
CameraSuiteOrientation0,
53+
CameraSuiteOrientation90,
54+
CameraSuiteOrientation180,
55+
CameraSuiteOrientation270,
56+
} CameraSuiteOrientationState;
57+
5058
typedef enum {
5159
CameraSuiteHapticOff,
5260
CameraSuiteHapticOn,

src-fap/helpers/camera_suite_storage.c

+4
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,8 @@ void camera_suite_save_settings(void* context) {
4949
// Store Settings
5050
flipper_format_write_header_cstr(
5151
fff_file, BOILERPLATE_SETTINGS_HEADER, BOILERPLATE_SETTINGS_FILE_VERSION);
52+
flipper_format_write_uint32(
53+
fff_file, BOILERPLATE_SETTINGS_KEY_ORIENTATION, &app->orientation, 1);
5254
flipper_format_write_uint32(fff_file, BOILERPLATE_SETTINGS_KEY_HAPTIC, &app->haptic, 1);
5355
flipper_format_write_uint32(fff_file, BOILERPLATE_SETTINGS_KEY_SPEAKER, &app->speaker, 1);
5456
flipper_format_write_uint32(fff_file, BOILERPLATE_SETTINGS_KEY_LED, &app->led, 1);
@@ -98,6 +100,8 @@ void camera_suite_read_settings(void* context) {
98100
return;
99101
}
100102

103+
flipper_format_read_uint32(
104+
fff_file, BOILERPLATE_SETTINGS_KEY_ORIENTATION, &app->orientation, 1);
101105
flipper_format_read_uint32(fff_file, BOILERPLATE_SETTINGS_KEY_HAPTIC, &app->haptic, 1);
102106
flipper_format_read_uint32(fff_file, BOILERPLATE_SETTINGS_KEY_SPEAKER, &app->speaker, 1);
103107
flipper_format_read_uint32(fff_file, BOILERPLATE_SETTINGS_KEY_LED, &app->led, 1);

src-fap/helpers/camera_suite_storage.h

+1
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
#define BOILERPLATE_SETTINGS_SAVE_PATH CONFIG_FILE_DIRECTORY_PATH "/camera-suite.conf"
1010
#define BOILERPLATE_SETTINGS_SAVE_PATH_TMP BOILERPLATE_SETTINGS_SAVE_PATH ".tmp"
1111
#define BOILERPLATE_SETTINGS_HEADER "Camera Suite Config File"
12+
#define BOILERPLATE_SETTINGS_KEY_ORIENTATION "Orientation"
1213
#define BOILERPLATE_SETTINGS_KEY_HAPTIC "Haptic"
1314
#define BOILERPLATE_SETTINGS_KEY_LED "Led"
1415
#define BOILERPLATE_SETTINGS_KEY_SPEAKER "Speaker"

src-fap/scenes/camera_suite_scene_menu.c

+8-7
Original file line numberDiff line numberDiff line change
@@ -21,16 +21,17 @@ void camera_suite_scene_menu_on_enter(void* context) {
2121

2222
submenu_add_item(
2323
app->submenu,
24-
"Style 1: Atkinson",
24+
"Open Camera", // Style: Atkinson
2525
SubmenuIndexSceneStyle1,
2626
camera_suite_scene_menu_submenu_callback,
2727
app);
28-
submenu_add_item(
29-
app->submenu,
30-
"Style 2: Floyd-Steinberg",
31-
SubmenuIndexSceneStyle2,
32-
camera_suite_scene_menu_submenu_callback,
33-
app);
28+
// TODO: Uncomment when style 2 is implemented
29+
// submenu_add_item(
30+
// app->submenu,
31+
// "Style: Floyd-Steinberg",
32+
// SubmenuIndexSceneStyle2,
33+
// camera_suite_scene_menu_submenu_callback,
34+
// app);
3435
submenu_add_item(
3536
app->submenu, "Guide", SubmenuIndexGuide, camera_suite_scene_menu_submenu_callback, app);
3637
submenu_add_item(

src-fap/scenes/camera_suite_scene_settings.c

+34
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,21 @@
11
#include "../camera-suite.h"
22
#include <lib/toolbox/value_index.h>
33

4+
// Camera orientation, in degrees.
5+
const char* const orientation_text[4] = {
6+
"0",
7+
"90",
8+
"180",
9+
"270",
10+
};
11+
12+
const uint32_t orientation_value[4] = {
13+
CameraSuiteOrientation0,
14+
CameraSuiteOrientation90,
15+
CameraSuiteOrientation180,
16+
CameraSuiteOrientation270,
17+
};
18+
419
const char* const haptic_text[2] = {
520
"OFF",
621
"ON",
@@ -31,6 +46,14 @@ const uint32_t led_value[2] = {
3146
CameraSuiteLedOn,
3247
};
3348

49+
static void camera_suite_scene_settings_set_camera_orientation(VariableItem* item) {
50+
CameraSuite* app = variable_item_get_context(item);
51+
uint8_t index = variable_item_get_current_value_index(item);
52+
53+
variable_item_set_current_value_text(item, orientation_text[index]);
54+
app->orientation = orientation_value[index];
55+
}
56+
3457
static void camera_suite_scene_settings_set_haptic(VariableItem* item) {
3558
CameraSuite* app = variable_item_get_context(item);
3659
uint8_t index = variable_item_get_current_value_index(item);
@@ -63,6 +86,17 @@ void camera_suite_scene_settings_on_enter(void* context) {
6386
VariableItem* item;
6487
uint8_t value_index;
6588

89+
// Camera Orientation
90+
item = variable_item_list_add(
91+
app->variable_item_list,
92+
"Orientation:",
93+
4,
94+
camera_suite_scene_settings_set_camera_orientation,
95+
app);
96+
value_index = value_index_uint32(app->orientation, orientation_value, 4);
97+
variable_item_set_current_value_index(item, value_index);
98+
variable_item_set_current_value_text(item, orientation_text[value_index]);
99+
66100
// Haptic FX ON/OFF
67101
item = variable_item_list_add(
68102
app->variable_item_list, "Haptic FX:", 2, camera_suite_scene_settings_set_haptic, app);

src-fap/views/camera_suite_view_guide.c

+5-5
Original file line numberDiff line numberDiff line change
@@ -32,11 +32,11 @@ void camera_suite_view_guide_draw(Canvas* canvas, CameraSuiteViewGuideModel* mod
3232
canvas_set_font(canvas, FontPrimary);
3333
canvas_draw_str_aligned(canvas, 0, 0, AlignLeft, AlignTop, "Guide");
3434
canvas_set_font(canvas, FontSecondary);
35-
canvas_draw_str_aligned(canvas, 0, 12, AlignLeft, AlignTop, "Left = Contrast Down");
36-
canvas_draw_str_aligned(canvas, 0, 22, AlignLeft, AlignTop, "Right = Contrast Up");
37-
canvas_draw_str_aligned(canvas, 0, 32, AlignLeft, AlignTop, "Up = Brightness Up");
38-
canvas_draw_str_aligned(canvas, 0, 42, AlignLeft, AlignTop, "Down = Brightness Down");
39-
canvas_draw_str_aligned(canvas, 0, 52, AlignLeft, AlignTop, "Center = Take Picture");
35+
canvas_draw_str_aligned(canvas, 0, 12, AlignLeft, AlignTop, "Left = Toggle Invert");
36+
canvas_draw_str_aligned(canvas, 0, 22, AlignLeft, AlignTop, "Right = Toggle Dithering");
37+
canvas_draw_str_aligned(canvas, 0, 32, AlignLeft, AlignTop, "Up = Contrast Up");
38+
canvas_draw_str_aligned(canvas, 0, 42, AlignLeft, AlignTop, "Down = Contrast Down");
39+
canvas_draw_str_aligned(canvas, 0, 52, AlignLeft, AlignTop, "Center = Take Picture (TODO)");
4040
}
4141

4242
static void camera_suite_view_guide_model_init(CameraSuiteViewGuideModel* const model) {

src-fap/views/camera_suite_view_style_1.c

+13-14
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ struct CameraSuiteViewStyle1 {
1212
FuriStreamBuffer* rx_stream;
1313
FuriThread* worker_thread;
1414
View* view;
15-
int rotation_angle;
1615
void* context;
1716
};
1817

@@ -33,26 +32,29 @@ static void camera_suite_view_style_1_draw(Canvas* canvas, UartDumpModel* model)
3332
// Draw the frame.
3433
canvas_draw_frame(canvas, 0, 0, FRAME_WIDTH, FRAME_HEIGHT);
3534

35+
CameraSuite* app = current_instance->context;
36+
3637
// Draw the pixels with rotation.
3738
for(size_t p = 0; p < FRAME_BUFFER_LENGTH; ++p) {
3839
uint8_t x = p % ROW_BUFFER_LENGTH; // 0 .. 15
3940
uint8_t y = p / ROW_BUFFER_LENGTH; // 0 .. 63
4041

4142
// Apply rotation
4243
int16_t rotated_x, rotated_y;
43-
switch(current_instance->rotation_angle) {
44-
case 90:
44+
switch(app->orientation) {
45+
case 1: // 90 degrees
4546
rotated_x = y;
4647
rotated_y = FRAME_WIDTH - 1 - x;
4748
break;
48-
case 180:
49+
case 2: // 180 degrees
4950
rotated_x = FRAME_WIDTH - 1 - x;
5051
rotated_y = FRAME_HEIGHT - 1 - y;
5152
break;
52-
case 270:
53+
case 3: // 270 degrees
5354
rotated_x = FRAME_HEIGHT - 1 - y;
5455
rotated_y = x;
5556
break;
57+
case 0: // 0 degrees
5658
default:
5759
rotated_x = x;
5860
rotated_y = y;
@@ -63,19 +65,20 @@ static void camera_suite_view_style_1_draw(Canvas* canvas, UartDumpModel* model)
6365
if((model->pixels[p] & (1 << i)) != 0) {
6466
// Adjust the coordinates based on the new screen dimensions
6567
uint16_t screen_x, screen_y;
66-
switch(current_instance->rotation_angle) {
67-
case 90:
68+
switch(app->orientation) {
69+
case 1: // 90 degrees
6870
screen_x = rotated_x;
6971
screen_y = FRAME_HEIGHT - 8 + (rotated_y * 8) + i;
7072
break;
71-
case 180:
73+
case 2: // 180 degrees
7274
screen_x = FRAME_WIDTH - 8 + (rotated_x * 8) + i;
7375
screen_y = FRAME_HEIGHT - 1 - rotated_y;
7476
break;
75-
case 270:
77+
case 3: // 270 degrees
7678
screen_x = FRAME_WIDTH - 1 - rotated_x;
7779
screen_y = rotated_y * 8 + i;
7880
break;
81+
case 0: // 0 degrees
7982
default:
8083
screen_x = rotated_x * 8 + i;
8184
screen_y = rotated_y;
@@ -171,11 +174,7 @@ static bool camera_suite_view_style_1_input(InputEvent* event, void* context) {
171174
true);
172175
break;
173176
case InputKeyOk:
174-
// Rotate the camera image 90 degrees
175-
instance->rotation_angle += 90;
176-
if(instance->rotation_angle >= 360) {
177-
instance->rotation_angle = 0;
178-
}
177+
// TODO: Take picture.
179178
with_view_model(
180179
instance->view,
181180
UartDumpModel * model,

0 commit comments

Comments
 (0)