diff options
Diffstat (limited to 'src/displayapp/LittleVgl.cpp')
-rw-r--r-- | src/displayapp/LittleVgl.cpp | 69 |
1 files changed, 32 insertions, 37 deletions
diff --git a/src/displayapp/LittleVgl.cpp b/src/displayapp/LittleVgl.cpp index 500fd752..36df51b4 100644 --- a/src/displayapp/LittleVgl.cpp +++ b/src/displayapp/LittleVgl.cpp @@ -11,17 +11,18 @@ using namespace Pinetime::Components; lv_style_t* LabelBigStyle = nullptr; -static void disp_flush(lv_disp_drv_t * disp_drv, const lv_area_t * area, lv_color_t * color_p) { +static void disp_flush(lv_disp_drv_t* disp_drv, const lv_area_t* area, lv_color_t* color_p) { auto* lvgl = static_cast<LittleVgl*>(disp_drv->user_data); lvgl->FlushDisplay(area, color_p); } -bool touchpad_read(lv_indev_drv_t * indev_drv, lv_indev_data_t * data) { +bool touchpad_read(lv_indev_drv_t* indev_drv, lv_indev_data_t* data) { auto* lvgl = static_cast<LittleVgl*>(indev_drv->user_data); return lvgl->GetTouchPadInfo(data); } -LittleVgl::LittleVgl(Pinetime::Drivers::St7789& lcd, Pinetime::Drivers::Cst816S& touchPanel) : lcd{lcd}, touchPanel{touchPanel}, previousClick{0,0} { +LittleVgl::LittleVgl(Pinetime::Drivers::St7789& lcd, Pinetime::Drivers::Cst816S& touchPanel) + : lcd {lcd}, touchPanel {touchPanel}, previousClick {0, 0} { lv_init(); InitTheme(); InitDisplay(); @@ -29,8 +30,8 @@ LittleVgl::LittleVgl(Pinetime::Drivers::St7789& lcd, Pinetime::Drivers::Cst816S& } void LittleVgl::InitDisplay() { - lv_disp_buf_init(&disp_buf_2, buf2_1, buf2_2, LV_HOR_RES_MAX * 4); /*Initialize the display buffer*/ - lv_disp_drv_init(&disp_drv); /*Basic initialization*/ + lv_disp_buf_init(&disp_buf_2, buf2_1, buf2_2, LV_HOR_RES_MAX * 4); /*Initialize the display buffer*/ + lv_disp_drv_init(&disp_drv); /*Basic initialization*/ /*Set up the functions to access to your display*/ @@ -59,7 +60,7 @@ void LittleVgl::InitTouchpad() { } void LittleVgl::SetFullRefresh(FullRefreshDirections direction) { - if(scrollDirection == FullRefreshDirections::None) { + if (scrollDirection == FullRefreshDirections::None) { scrollDirection = direction; if (scrollDirection == FullRefreshDirections::Down) { lv_disp_set_direction(lv_disp_get_default(), 1); @@ -75,16 +76,16 @@ void LittleVgl::SetFullRefresh(FullRefreshDirections direction) { } } -void LittleVgl::FlushDisplay(const lv_area_t *area, lv_color_t *color_p) { +void LittleVgl::FlushDisplay(const lv_area_t* area, lv_color_t* color_p) { uint16_t y1, y2, width, height = 0; ulTaskNotifyTake(pdTRUE, 200); // NOtification is still needed (even if there is a mutex on SPI) because of the DataCommand pin // which cannot be set/clear during a transfert. - - if( (scrollDirection == LittleVgl::FullRefreshDirections::Down) && (area->y2 == visibleNbLines - 1)) { + + if ((scrollDirection == LittleVgl::FullRefreshDirections::Down) && (area->y2 == visibleNbLines - 1)) { writeOffset = ((writeOffset + totalNbLines) - visibleNbLines) % totalNbLines; - } else if( (scrollDirection == FullRefreshDirections::Up) && (area->y1 == 0) ) { + } else if ((scrollDirection == FullRefreshDirections::Up) && (area->y1 == 0)) { writeOffset = (writeOffset + visibleNbLines) % totalNbLines; } @@ -94,11 +95,11 @@ void LittleVgl::FlushDisplay(const lv_area_t *area, lv_color_t *color_p) { width = (area->x2 - area->x1) + 1; height = (area->y2 - area->y1) + 1; - if(scrollDirection == LittleVgl::FullRefreshDirections::Down) { + if (scrollDirection == LittleVgl::FullRefreshDirections::Down) { - if(area->y2 < visibleNbLines - 1) { + if (area->y2 < visibleNbLines - 1) { uint16_t toScroll = 0; - if(area->y1 == 0) { + if (area->y1 == 0) { toScroll = height * 2; scrollDirection = FullRefreshDirections::None; lv_disp_set_direction(lv_disp_get_default(), 0); @@ -106,19 +107,19 @@ void LittleVgl::FlushDisplay(const lv_area_t *area, lv_color_t *color_p) { toScroll = height; } - if(scrollOffset >= toScroll) + if (scrollOffset >= toScroll) scrollOffset -= toScroll; else { toScroll -= scrollOffset; - scrollOffset = (totalNbLines) - toScroll; + scrollOffset = (totalNbLines) -toScroll; } lcd.VerticalScrollStartAddress(scrollOffset); } - } else if(scrollDirection == FullRefreshDirections::Up) { + } else if (scrollDirection == FullRefreshDirections::Up) { - if(area->y1 > 0) { - if(area->y2 == visibleNbLines - 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); @@ -128,13 +129,13 @@ void LittleVgl::FlushDisplay(const lv_area_t *area, lv_color_t *color_p) { scrollOffset = scrollOffset % totalNbLines; lcd.VerticalScrollStartAddress(scrollOffset); } - } else if(scrollDirection == FullRefreshDirections::Left or scrollDirection == FullRefreshDirections::LeftAnim) { - if(area->x2 == visibleNbLines - 1) { + } else if (scrollDirection == FullRefreshDirections::Left or scrollDirection == FullRefreshDirections::LeftAnim) { + if (area->x2 == visibleNbLines - 1) { scrollDirection = FullRefreshDirections::None; lv_disp_set_direction(lv_disp_get_default(), 0); } - } else if(scrollDirection == FullRefreshDirections::Right or scrollDirection == FullRefreshDirections::RightAnim) { - if(area->x1 == 0) { + } else if (scrollDirection == FullRefreshDirections::Right or scrollDirection == FullRefreshDirections::RightAnim) { + if (area->x1 == 0) { scrollDirection = FullRefreshDirections::None; lv_disp_set_direction(lv_disp_get_default(), 0); } @@ -143,17 +144,17 @@ void LittleVgl::FlushDisplay(const lv_area_t *area, lv_color_t *color_p) { if (y2 < y1) { height = totalNbLines - y1; - if ( height > 0 ) { - lcd.DrawBuffer(area->x1, y1, width, height, reinterpret_cast<const uint8_t *>(color_p), width * height * 2); + if (height > 0) { + lcd.DrawBuffer(area->x1, y1, width, height, reinterpret_cast<const uint8_t*>(color_p), width * height * 2); ulTaskNotifyTake(pdTRUE, 100); } - + uint16_t pixOffset = width * height; height = y2 + 1; - lcd.DrawBuffer(area->x1, 0, width, height, reinterpret_cast<const uint8_t *>(color_p + pixOffset), width * height * 2); + lcd.DrawBuffer(area->x1, 0, width, height, reinterpret_cast<const uint8_t*>(color_p + pixOffset), width * height * 2); } else { - lcd.DrawBuffer(area->x1, y1, width, height, reinterpret_cast<const uint8_t *>(color_p), width * height * 2); + lcd.DrawBuffer(area->x1, y1, width, height, reinterpret_cast<const uint8_t*>(color_p), width * height * 2); } // IMPORTANT!!! @@ -167,8 +168,8 @@ void LittleVgl::SetNewTapEvent(uint16_t x, uint16_t y) { tapped = true; } -bool LittleVgl::GetTouchPadInfo(lv_indev_data_t *ptr) { - if(tapped) { +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; @@ -202,14 +203,8 @@ bool LittleVgl::GetTouchPadInfo(lv_indev_data_t *ptr) { void LittleVgl::InitTheme() { - lv_theme_t * th = lv_pinetime_theme_init( - LV_COLOR_WHITE, LV_COLOR_SILVER, - 0, - &jetbrains_mono_bold_20, - &jetbrains_mono_bold_20, - &jetbrains_mono_bold_20, - &jetbrains_mono_bold_20); + lv_theme_t* th = lv_pinetime_theme_init( + LV_COLOR_WHITE, LV_COLOR_SILVER, 0, &jetbrains_mono_bold_20, &jetbrains_mono_bold_20, &jetbrains_mono_bold_20, &jetbrains_mono_bold_20); lv_theme_set_act(th); - } |