Skip to content

Commit 301c8bd

Browse files
committed
rewrite set_orientation to use the ugfx_screen_flip for rotations >= 180 degrees
1 parent d4f810f commit 301c8bd

File tree

1 file changed

+11
-2
lines changed

1 file changed

+11
-2
lines changed

esp32/modugfx.c

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@ uint8_t target_lut;
6262

6363
typedef struct _ugfx_obj_t { mp_obj_base_t base; } ugfx_obj_t;
6464

65+
extern bool ugfx_screen_flipped;
6566
static orientation_t get_orientation(int a){
6667
if (a == 90)
6768
return GDISP_ROTATE_90;
@@ -146,11 +147,19 @@ STATIC MP_DEFINE_CONST_FUN_OBJ_0(ugfx_get_lut_obj, ugfx_get_lut);
146147
STATIC mp_obj_t ugfx_set_orientation(mp_uint_t n_args, const mp_obj_t *args) {
147148
if (n_args > 0){
148149
int a = mp_obj_get_int(args[0]);
150+
a %= 360;
151+
if (a >= 180) {
152+
ugfx_screen_flipped = true;
153+
a -= 180;
154+
}
149155
gdispSetOrientation(get_orientation(a));
150-
151156
}
152157

153-
return mp_obj_new_int(gdispGetOrientation());
158+
int a = gdispGetOrientation();
159+
if (ugfx_screen_flipped)
160+
a += 180;
161+
a %= 360;
162+
return mp_obj_new_int(a);
154163
}
155164
STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(ugfx_set_orientation_obj, 0, 1, ugfx_set_orientation);
156165

0 commit comments

Comments
 (0)