summaryrefslogtreecommitdiff
path: root/src/DisplayApp/LittleVgl.cpp
diff options
context:
space:
mode:
authorJF <jf@codingfield.com>2020-03-09 21:29:12 +0100
committerJF <jf@codingfield.com>2020-03-09 21:29:12 +0100
commit35e221078bf8e7b1548f5b75c391404d098442a0 (patch)
tree283687c96c5b8a33716229cc77c0fd23cc2ae5dd /src/DisplayApp/LittleVgl.cpp
parent968f18f4727d865242fc67d55f298b196f75b0f8 (diff)
Add support for gestures and integrate it with the vertical scrolling transition.
Diffstat (limited to 'src/DisplayApp/LittleVgl.cpp')
-rw-r--r--src/DisplayApp/LittleVgl.cpp155
1 files changed, 94 insertions, 61 deletions
diff --git a/src/DisplayApp/LittleVgl.cpp b/src/DisplayApp/LittleVgl.cpp
index 2796daac..1dfbc2d1 100644
--- a/src/DisplayApp/LittleVgl.cpp
+++ b/src/DisplayApp/LittleVgl.cpp
@@ -64,8 +64,10 @@ void LittleVgl::InitTouchpad() {
lv_indev_drv_register(&indev_drv);
}
-void LittleVgl::SetFullRefresh() {
- fullRefresh = true;
+void LittleVgl::SetFullRefresh(FullRefreshDirections direction) {
+ scrollDirection = direction;
+ if(scrollDirection == FullRefreshDirections::Down)
+ lv_disp_set_direction(lv_disp_get_default(), 1);
}
void LittleVgl::FlushDisplay(const lv_area_t *area, lv_color_t *color_p) {
@@ -74,86 +76,114 @@ void LittleVgl::FlushDisplay(const lv_area_t *area, lv_color_t *color_p) {
// TODO refactore and remove duplicated code
uint16_t x, y, y1, y2, width, height = 0;
- if(fullRefresh) {
- if(scrollDirection == LittleVgl::ScrollDirections::Down) {
- if(area->y2 == visibleNbLines-1) {
+ if(scrollDirection == LittleVgl::FullRefreshDirections::Down) {
+ if(area->y2 == visibleNbLines-1) {
writeOffset = ((writeOffset + totalNbLines) - visibleNbLines) % totalNbLines;
- }
- x = area->x1;
- width = (area->x2 - area->x1) + 1;
+ }
+ x = area->x1;
+ width = (area->x2 - area->x1) + 1;
- y1 = (area->y1 + writeOffset) % totalNbLines;
- y2 = (area->y2 + writeOffset) % totalNbLines;
- y = y1;
- height = (y2 - y1) + 1;
+ y1 = (area->y1 + writeOffset) % totalNbLines;
+ y2 = (area->y2 + writeOffset) % totalNbLines;
+ y = y1;
+ height = (y2 - y1) + 1;
- if(area->y2 < visibleNbLines - 1) {
- uint16_t toScroll = 0;
+ if(area->y2 < visibleNbLines - 1) {
+ uint16_t toScroll = 0;
if(area->y1 == 0) {
- toScroll = height*2;
- fullRefresh = false;
- lv_disp_set_direction(lv_disp_get_default(), 0);
- } else {
- toScroll = height;
- }
-
- if(scrollOffset >= toScroll)
- scrollOffset -= toScroll;
- else {
- toScroll -= scrollOffset;
- scrollOffset = (totalNbLines) - toScroll;
- }
+ toScroll = height*2;
+ scrollDirection = FullRefreshDirections::None;
+ lv_disp_set_direction(lv_disp_get_default(), 0);
+ } else {
+ toScroll = height;
+ }
- lcd.VerticalScrollDefinition(0, 320, 0);
- lcd.VerticalScrollStartAddress(scrollOffset);
+ if(scrollOffset >= toScroll)
+ scrollOffset -= toScroll;
+ else {
+ toScroll -= scrollOffset;
+ scrollOffset = (totalNbLines) - toScroll;
}
- lcd.BeginDrawBuffer(x, y, width, height);
- lcd.NextDrawBuffer(reinterpret_cast<const uint8_t *>(color_p), width * height*2) ;
+ lcd.VerticalScrollDefinition(0, 320, 0);
+ lcd.VerticalScrollStartAddress(scrollOffset);
+ }
- } else {
- if(area->y1 == 0) {
- writeOffset = (writeOffset + visibleNbLines) % totalNbLines;
- }
+ lcd.BeginDrawBuffer(x, y, width, height);
+ lcd.NextDrawBuffer(reinterpret_cast<const uint8_t *>(color_p), width * height*2) ;
- x = area->x1;
- width = (area->x2 - area->x1) + 1;
-
- y1 = (area->y1 + writeOffset) % totalNbLines;
- y2 = (area->y2 + writeOffset) % totalNbLines;
- y = y1;
- height = (y2 - y1) + 1;
-
- if(area->y1 > 0) {
- if(area->y2 == visibleNbLines -1) {
- scrollOffset += (height * 2);
- fullRefresh = false;
- lv_disp_set_direction(lv_disp_get_default(), 0);
- } else {
- scrollOffset += height;
- }
- scrollOffset = scrollOffset % totalNbLines;
- lcd.VerticalScrollDefinition(0, 320, 0);
- lcd.VerticalScrollStartAddress(scrollOffset);
- }
+ } else if(scrollDirection == FullRefreshDirections::Up) {
+ if(area->y1 == 0) {
+ writeOffset = (writeOffset + visibleNbLines) % totalNbLines;
+ }
- lcd.BeginDrawBuffer(x, y, width, height);
- lcd.NextDrawBuffer(reinterpret_cast<const uint8_t *>(color_p), width * height*2);
+ x = area->x1;
+ width = (area->x2 - area->x1) + 1;
+
+ y1 = (area->y1 + writeOffset) % totalNbLines;
+ y2 = (area->y2 + writeOffset) % totalNbLines;
+ y = y1;
+ height = (y2 - y1) + 1;
+
+ if(area->y1 > 0) {
+ if(area->y2 == visibleNbLines -1) {
+ scrollOffset += (height * 2);
+ scrollDirection = FullRefreshDirections::None;
+ lv_disp_set_direction(lv_disp_get_default(), 0);
+ } else {
+ scrollOffset += height;
+ }
+ scrollOffset = scrollOffset % totalNbLines;
+ lcd.VerticalScrollDefinition(0, 320, 0);
+ lcd.VerticalScrollStartAddress(scrollOffset);
}
+
+ lcd.BeginDrawBuffer(x, y, width, height);
+ lcd.NextDrawBuffer(reinterpret_cast<const uint8_t *>(color_p), width * height*2);
} else {
x = area->x1;
- y = area->y1;
width = (area->x2 - area->x1) + 1;
- height = (area->y2 - area->y1) + 1;
- lcd.BeginDrawBuffer(x, y, width, height);
- lcd.NextDrawBuffer(reinterpret_cast<const uint8_t *>(color_p), width * height*2) ;
+ y1 = (area->y1 + writeOffset) % totalNbLines;
+ y2 = (area->y2 + writeOffset) % totalNbLines;
+ y = y1;
+ height = (y2 - y1) + 1;
+
+ if (y2 < y1) {
+ height = (totalNbLines - 1) - y1;
+ lcd.BeginDrawBuffer(x, y1, width, height);
+ lcd.NextDrawBuffer(reinterpret_cast<const uint8_t *>(color_p), width * height * 2);
+ ulTaskNotifyTake(pdTRUE, 500);
+ height = y2;
+ lcd.BeginDrawBuffer(x, 0, width, height);
+ lcd.NextDrawBuffer(reinterpret_cast<const uint8_t *>(color_p), width * height * 2);
+ } else {
+ lcd.BeginDrawBuffer(x, y, width, height);
+ lcd.NextDrawBuffer(reinterpret_cast<const uint8_t *>(color_p), width * height * 2);
+ }
}
/* IMPORTANT!!!
* Inform the graphics library that you are ready with the flushing*/
lv_disp_flush_ready(&disp_drv);
}
+
+void LittleVgl::SetNewTapEvent(uint16_t x, uint16_t y) {
+ tap_x = x;
+ tap_y = y;
+ tapped = true;
+}
+
bool LittleVgl::GetTouchPadInfo(lv_indev_data_t *ptr) {
+ if(tapped) {
+ ptr->point.x = tap_x;
+ ptr->point.y = tap_y;
+ ptr->state = LV_INDEV_STATE_PR;
+ tapped = false;
+ } else {
+ ptr->state = LV_INDEV_STATE_REL;
+ }
+ return false;
+ /*
auto info = touchPanel.GetTouchInfo();
if((previousClick.x != info.x || previousClick.y != info.y) &&
@@ -173,6 +203,7 @@ bool LittleVgl::GetTouchPadInfo(lv_indev_data_t *ptr) {
ptr->point.x = info.x;
ptr->point.y = info.y;
return false;
+ */
}
void LittleVgl::InitTheme() {
@@ -790,3 +821,5 @@ void LittleVgl::InitThemeWindow() {
// theme.style.win.btn.pr = &win_btn_pr;
}
+
+