LCD LIB
Fork of RA8875 by
Revision 149:c62c4b2d6a15, committed 2017-08-06
- Comitter:
- WiredHome
- Date:
- Sun Aug 06 17:05:54 2017 +0000
- Parent:
- 148:33e99de1aca6
- Child:
- 150:35a4db3081c1
- Commit message:
- Revised the idle callback. It is additionally called from PrintScreen to communicate percent complete (with an additional parameter), since PrintScreen can take a while to finish based on the display size, layers, and SPI configuration.
Changed in this revision
--- a/RA8875.cpp Tue Jun 13 23:12:26 2017 +0000 +++ b/RA8875.cpp Sun Aug 06 17:05:54 2017 +0000 @@ -404,7 +404,7 @@ wait_us(POLLWAITuSec); // COUNTIDLETIME(POLLWAITuSec); // As it is voluntary to call the getc and pend. Don't tally it. if (idle_callback) { - if (external_abort == (*idle_callback)(getc_wait)) { + if (external_abort == (*idle_callback)(getc_wait, 0)) { return 0; } } @@ -673,7 +673,7 @@ wait_us(POLLWAITuSec); COUNTIDLETIME(POLLWAITuSec); if (idle_callback) { - if (external_abort == (*idle_callback)(status_wait)) { + if (external_abort == (*idle_callback)(status_wait, 0)) { return false; } } @@ -695,7 +695,7 @@ wait_us(POLLWAITuSec); COUNTIDLETIME(POLLWAITuSec); if (idle_callback) { - if (external_abort == (*idle_callback)(command_wait)) { + if (external_abort == (*idle_callback)(command_wait, 0)) { return false; } } @@ -2132,6 +2132,10 @@ // Read the display from the last line toward the top // so we can write the file in one pass. for (int j = h - 1; j >= 0; j--) { + if (idle_callback) { + (*idle_callback)(progress, (h - 1 - j) * 100 / (h - 1)); + } + if (ltpr0 >= 2) // Need to combine the layers... SelectDrawingLayer(0); // so read layer 0 first // Read one line of pixels to a local buffer @@ -2303,6 +2307,10 @@ // Read the display from the last line toward the top // so we can write the file in one pass. for (int j = h - 1; j >= 0; j--) { + if (idle_callback) { + (*idle_callback)(progress, (h - 1 - j) * 100 / (h - 1)); + } + if (ltpr0 >= 2) // Need to combine the layers... SelectDrawingLayer(0); // so read layer 0 first // Read one line of pixels to a local buffer
--- a/RA8875.h Tue Jun 13 23:12:26 2017 +0000 +++ b/RA8875.h Sun Aug 06 17:05:54 2017 +0000 @@ -336,10 +336,13 @@ /// print screen callback /// /// The special form of the print screen will pass one blob at a time - /// to the callback. There are basic command declaring that the stream + /// to the callback. There are basic commands declaring that the stream /// can be opened, a block written, and the stream closed. There is /// also a command to communicate the total size being delivered. /// + /// If the idle callback is registered, it will be activated passing + /// a parameter indicating the percent complete, which may be of value. + /// /// @code /// lcd.PrintScreen(x,y,w,h,callback); /// ... @@ -376,7 +379,8 @@ command_wait, ///< driver is polling the command register while busy getc_wait, ///< user has called the getc function touch_wait, ///< user has called the touch function - touchcal_wait ///< driver is performing a touch calibration + touchcal_wait, ///< driver is performing a touch calibration + progress, ///< communicates progress } IdleReason_T; /// Idle Callback @@ -395,7 +399,7 @@ /// when the CPU is largely idle. /// /// @code - /// RetCode_t myIdle_handler(RA8875::IdleReason_T reason) + /// RetCode_t myIdle_handler(RA8875::IdleReason_T reason, uint16_t param) /// { /// idleFlasher = !idleFlasher; /// if (it_has_been_too_long()) @@ -406,10 +410,12 @@ /// @endcode /// /// @param reason informs the callback why it is idle. + /// @param param is a 2nd parameter, which is used for certain reason codes + /// for 'progress' reason code, param ranges from 0 to 100 (percent) /// @returns noerror to allow the driver continue waiting. /// @returns external_abort if the pending action should be aborted. /// - typedef RetCode_t (* IdleCallback_T)(IdleReason_T reason); + typedef RetCode_t (* IdleCallback_T)(IdleReason_T reason, uint16_t param = 0); /// Basic constructor for a display based on the RAiO RA8875 /// display controller, which can be used with no touchscreen, @@ -2556,6 +2562,9 @@ /// only layer 1 is visible, then the bitmap is only layer 1. However, /// if there is some other operation in effect (transparent mode). /// + /// If the idle callback is registered, it will be activated passing + /// a parameter indicating the percent complete, which may be of value. + /// /// @param[in] x is the left edge of the region to capture /// @param[in] y is the top edge of the region to capture /// @param[in] w is the width of the region to capture @@ -2578,6 +2587,9 @@ /// if there is some other operation in effect (transparent mode), it /// will return the blended image. /// + /// If the idle callback is registered, it will be activated passing + /// a parameter indicating the percent complete, which may be of value. + /// /// @param[in] x is the left edge of the region to capture /// @param[in] y is the top edge of the region to capture /// @param[in] w is the width of the region to capture @@ -2645,6 +2657,26 @@ /// a watchdog, when you may have called an API that will "hang" waiting /// on the user. /// + /// @code + /// RetCode_t myIdle_handler(RA8875::IdleReason_T reason, uint16_t param) + /// { + /// static uint16_t lastProgress = 0xFFFF; + /// + /// if (reason == RA8875::progress && param != lastProgress) { + /// printf("Progress %3d%%\r\n", param); + /// lastProgress = progress; + /// } + /// return noerror; + /// } + /// + /// ... + /// lcd.AttachIdleHandler(myIdle_handler); + /// ... + /// RetCode_t r = lcd.PrintScreen(0,0,LCD_W,LCD_H,"/local/print.bmp"); + /// if (r ...) + /// @endcode + /// + /// /// @param callback is the idle callback function. Without a callback function /// it will unregister the handler. /// @@ -2938,7 +2970,7 @@ RetCode_t (* c_callback)(filecmd_t cmd, uint8_t * buffer, uint16_t size); FPointerDummy *obj_callback; RetCode_t (FPointerDummy::*method_callback)(filecmd_t cmd, uint8_t * buffer, uint16_t size); - RetCode_t (* idle_callback)(IdleReason_T reason); + RetCode_t (* idle_callback)(IdleReason_T reason, uint16_t param); };
--- a/RA8875_Touch.cpp Tue Jun 13 23:12:26 2017 +0000 +++ b/RA8875_Touch.cpp Sun Aug 06 17:05:54 2017 +0000 @@ -119,7 +119,7 @@ while (TouchPanelA2DFiltered(&x, &y) && timeout.read() < maxwait_s) { wait_ms(20); if (idle_callback) { - if (external_abort == (*idle_callback)(touchcal_wait)) { + if (external_abort == (*idle_callback)(touchcal_wait, 0)) { return external_abort; } } @@ -143,7 +143,7 @@ while (!TouchPanelA2DFiltered(&x, &y) && timeout.read() < maxwait_s) { wait_ms(20); if (idle_callback) { - if (external_abort == (*idle_callback)(touchcal_wait)) { + if (external_abort == (*idle_callback)(touchcal_wait, 0)) { return external_abort; } } @@ -157,7 +157,7 @@ while (TouchPanelA2DFiltered(&x, &y) && timeout.read() < maxwait_s) { wait_ms(20); if (idle_callback) { - if (external_abort == (*idle_callback)(touchcal_wait)) { + if (external_abort == (*idle_callback)(touchcal_wait, 0)) { return external_abort; } } @@ -165,7 +165,7 @@ for (int t=0; t<100; t++) { wait_ms(20); if (idle_callback) { - if (external_abort == (*idle_callback)(touchcal_wait)) { + if (external_abort == (*idle_callback)(touchcal_wait, 0)) { return external_abort; } } @@ -290,7 +290,7 @@ if (t != no_touch) break; if (idle_callback) { - if (external_abort == (*idle_callback)(touch_wait)) { + if (external_abort == (*idle_callback)(touch_wait, 0)) { return no_touch; } }