Forked para SNOCC
Fork of RA8875 by
Diff: RA8875.h
- Revision:
- 96:40b74dd3695b
- Parent:
- 90:d113d71ae4f0
- Child:
- 98:ecebed9b80b2
--- a/RA8875.h Tue Jul 07 17:05:59 2015 +0000 +++ b/RA8875.h Sat Nov 28 15:39:44 2015 +0000 @@ -104,6 +104,7 @@ //namespace SW_graphics //{ +class FPointerDummy; // used by the callback methods. /// This is a graphics library for the Raio RA8875 Display Controller chip /// attached to a 4-wire SPI interface. @@ -219,6 +220,49 @@ TP_Auto, ///< Auto touch detection mode TP_Manual, ///< Manual touch detection mode } tpmode_t; + + /// printscreen callback commands + typedef enum + { + OPEN, ///< command to open the file. cast uint32_t * to the buffer to get the total size to be written. + WRITE, ///< command to write some data, buffer points to the data and the size is in bytes. + CLOSE, ///< command to close the file + } filecmd_t; + + /// 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 + /// can be opened, a block written, and the stream closed. There is + /// also a command to communicate the total size being delivered. + /// + /// @code + /// lcd.PrintScreen(x,y,w,h,callback); + /// ... + /// void callback(filecmd_t cmd, uint8_t * buffer, uint16_t size) { + /// switch(cmd) { + /// case OPEN: + /// pc.printf("About to write %u bytes\r\n", *(uint32_t *)buffer); + /// fh = fopen("file.bmp", "w+b"); + /// break; + /// case WRITE: + /// fwrite(buffer, size, fh); + /// break; + /// case CLOSE: + /// fclose(fh); + /// break; + /// default: + /// pc.printf("Unexpected callback %d\r\n", cmd); + /// break; + /// } + /// } + /// @endcode + /// + /// @param cmd is the command to execute. @see filecmd_t. + /// @param buffer is a pointer to the buffer being passed. + /// @param size is the number of bytes in the buffer. + /// + typedef RetCode_t (* PrintCallback_T)(filecmd_t cmd, uint8_t * buffer, uint16_t size); /// Constructor for a display based on the RAiO RA8875 /// display controller. @@ -1812,6 +1856,51 @@ /// RetCode_t PrintScreen(loc_t x, loc_t y, dim_t w, dim_t h, const char *Name_BMP); + /// This method captures the specified area as a 24-bit bitmap file + /// and delivers it to the previously attached callback. + /// + /// Even though this is a 16-bit display, the stored image is in + /// 24-bit format. + /// + /// This method will interrogate the current display setting and + /// create a bitmap based on those settings. For instance, if + /// only layer 1 is visible, then the bitmap is only layer 1. However, + /// if there is some other operation in effect (transparent mode), it + /// will return the blended image. + /// + /// @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 + /// @param[in] h is the height of the region to capture. + /// @return success or error code. + /// + RetCode_t PrintScreen(loc_t x, loc_t y, dim_t w, dim_t h); + + /// PrintScreen callback registration. + /// + /// This method attaches a simple c-compatible callback of type PrintCallback_T. + /// Then, the PrintScreen(x,y,w,h) method is called. Each chunk of data in the + /// BMP file to be created is passed to this callback. + /// + /// @param callback is the callback function. + /// + void AttachPrintHandler(PrintCallback_T callback) { c_callback = callback; } + + /// PrintScreen callback registration. + /// + /// This method attaches a c++ class method as a callback of type PrintCallback_T. + /// Then, the PrintScreen(x,y,w,h) method is called. Each chunk of data in the + /// BMP file to be created is passed to this callback. + /// + /// @param object is the class hosting the callback function. + /// @param callback is the callback function. + /// + template <class T> + void AttachPrintHandler(T *object, RetCode_t (T::*member)(void)) { + obj_callback = (FPointerDummy *)item; + method_callback = (uint32_t (FPointerDummy::*)(uint32_t))method; + } + /// This method captures the specified area as a 24-bit bitmap file, /// including the option of layer selection. /// @@ -2003,8 +2092,29 @@ void RegisterPerformance(method_e method); Timer performance; #endif + + RetCode_t _printCallback(RA8875::filecmd_t cmd, uint8_t * buffer, uint16_t size); + + FILE * _printFH; ///< PrintScreen file handle + + RetCode_t privateCallback(filecmd_t cmd, uint8_t * buffer, uint16_t size) { + if (c_callback != NULL) { + return (*c_callback)(cmd, buffer, size); + } + else { + if (obj_callback != NULL && method_callback != NULL) { + return (obj_callback->*method_callback)(cmd, buffer, size); + } + } + return noerror; + } + + 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); }; + //} // namespace //using namespace SW_graphics;