diff --git a/amy b/amy index c2671396c..13da5eb1d 160000 --- a/amy +++ b/amy @@ -1 +1 @@ -Subproject commit c2671396ca0c47c7bd9dc1ad15ae922d21a2b4d0 +Subproject commit 13da5eb1d66c63107d3719cdc893dfa7071992d4 diff --git a/docs/tulip_api.md b/docs/tulip_api.md index f5e918ec7..f3bdb0ce7 100644 --- a/docs/tulip_api.md +++ b/docs/tulip_api.md @@ -308,7 +308,7 @@ tulip.keyboard_callback() # removes callbacks. # Modify the touch screen calibration if needed (on Tulip CC only) # Run ex/calibrate.py to determine this for your panel -tulip.touch_delta(-20, 0) # -20 x, 0 y +tulip.touch_delta(-20, 0, 0.8) # -20 x, 0 y, 0.8 y scale tulip.touch_delta() # returns current delta # Set up a callback to receive raw touch events. up == 1 when finger / mouse lifted up diff --git a/tulip/esp32s3/gt911_touchscreen.c b/tulip/esp32s3/gt911_touchscreen.c index a7e761d1c..26c8cb55d 100644 --- a/tulip/esp32s3/gt911_touchscreen.c +++ b/tulip/esp32s3/gt911_touchscreen.c @@ -6,11 +6,11 @@ // Default for my V4R11 int16_t touch_x_delta = -2; int16_t touch_y_delta = -12; -float y_scale = 0.8f; +float touch_y_scale = 0.8f; #else int16_t touch_x_delta = 0; int16_t touch_y_delta = 0; -float y_scale = 1.0f; +float touch_y_scale = 1.0f; #endif esp_lcd_touch_handle_t tp; @@ -120,9 +120,9 @@ void run_gt911(void *param) { last_touch_x[i] = touch_x[i] + touch_x_delta; #ifdef TDECK // tdeck has swapped y that mirror_y doesn't fix - last_touch_y[i] = ((V_RES-touch_y[i]) + touch_y_delta)*y_scale; + last_touch_y[i] = ((V_RES-touch_y[i]) + touch_y_delta)*touch_y_scale; #else - last_touch_y[i] = (touch_y[i] + touch_y_delta)*y_scale; + last_touch_y[i] = (touch_y[i] + touch_y_delta)*touch_y_scale; #endif } //fprintf(stderr, "touch DOWN %d %d\n", last_touch_x[0], last_touch_y[0]); diff --git a/tulip/fs/ex/calibrate.py b/tulip/fs/ex/calibrate.py index dcc8e8296..b50fd9583 100644 --- a/tulip/fs/ex/calibrate.py +++ b/tulip/fs/ex/calibrate.py @@ -42,15 +42,20 @@ def touch_cb(x): for (x,y) in deltas: x_mean += x y_mean += y + + +old_delta = tulip.touch_delta() x_mean = int(float(x_mean) / float(len(deltas))) y_mean = int(float(y_mean) / float(len(deltas))) -old_delta = tulip.touch_delta() -print("New computed delta is [%d, %d]. It was [%d, %d]. " %(x_mean, y_mean, old_delta[0], old_delta[1])) +# TODO: compute this from the deltas +y_scale = old_delta[2] + +print("New computed delta is [%d, %d, %f]. It was [%d, %d, %f]. " %(x_mean, y_mean, y_scale, old_delta[0], old_delta[1], old_delta[2])) if(tulip.prompt("Set it?")): - tulip.touch_delta(x_mean, y_mean) + tulip.touch_delta(x_mean, y_mean, y_scale) if(tulip.prompt("Set. Add calibration to boot.py?")): - tulip.add_to_bootpy("tulip.touch_delta(%d,%d)" % (x_mean, y_mean)) + tulip.add_to_bootpy("tulip.touch_delta(%d,%d,%f)" % (x_mean, y_mean, y_scale)) print("Added.") tulip.bg_clear() diff --git a/tulip/shared/modtulip.c b/tulip/shared/modtulip.c index 13a19adef..9092da358 100644 --- a/tulip/shared/modtulip.c +++ b/tulip/shared/modtulip.c @@ -1051,26 +1051,31 @@ STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(tulip_touch_obj, 0, 0, tulip_touch); #ifdef ESP_PLATFORM extern int16_t touch_x_delta; extern int16_t touch_y_delta; +extern float touch_y_scale; #else int16_t touch_x_delta = 0; int16_t touch_y_delta = 0; +float touch_y_scale = 1.0; #endif STATIC mp_obj_t tulip_touch_delta(size_t n_args, const mp_obj_t *args) { if(n_args > 0) { touch_x_delta = mp_obj_get_int(args[0]); touch_y_delta = mp_obj_get_int(args[1]); + // Allow people to still set x,y delta without scale + if(n_args > 2) touch_y_scale = mp_obj_get_float(args[2]); } else { - mp_obj_t tuple[2]; + mp_obj_t tuple[3]; tuple[0] = mp_obj_new_int(touch_x_delta); tuple[1] = mp_obj_new_int(touch_y_delta); - return mp_obj_new_tuple(2, tuple); + tuple[2] = mp_obj_new_float(touch_y_scale); + return mp_obj_new_tuple(3, tuple); } return mp_const_none; } -STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(tulip_touch_delta_obj, 0, 2, tulip_touch_delta); +STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(tulip_touch_delta_obj, 0, 3, tulip_touch_delta); STATIC mp_obj_t tulip_key_remap(size_t n_args, const mp_obj_t *args) {