David Smart
/
PUB_RA8875_TouchColors
An example program using the RA8875 Display controller with the touch-screen option.
main.cpp
- Committer:
- WiredHome
- Date:
- 2016-01-23
- Revision:
- 3:45ef2ebfeebc
- Parent:
- 1:47e5fbdb28f1
- Child:
- 4:daf56708ae86
File content as of revision 3:45ef2ebfeebc:
#include "mbed.h" // tested with v112 #include "RA8875.h" // tested with v102 LocalFileSystem local("local"); RA8875 lcd(p5, p6, p7, p12, NC, "tft"); // MOSI, MISO, SCK, /ChipSelect, /reset, name Serial pc(USBTX, USBRX); extern "C" void mbed_reset(); #define min(a,b) ((a<b)?a:b) #define max(a,b) ((a>b)?a:b) bool Intersect(rect_t rect, point_t p) { if (p.x >= min(rect.p1.x, rect.p2.x) && p.x <= max(rect.p1.x, rect.p2.x) && p.y >= min(rect.p1.y, rect.p2.y) && p.y <= max(rect.p1.y, rect.p2.y)) return true; else return false; } int GetScreenCapture(void) { char fqfn[50]; int i = 0; pc.printf("Screen Capture... "); for (i=1; i< 100; i++) { snprintf(fqfn, sizeof(fqfn), "/local/Screen%02d.bmp", i); FILE * fh = fopen(fqfn, "rb"); if (!fh) { lcd.PrintScreen(0,0,480,272,fqfn); pc.printf(" as /local/Screen%02d.bmp\r\n", i); return i; } else { fclose(fh); // close this and try the next } } return 0; } int main() { pc.baud(460800); // I like a snappy terminal, so crank it up! pc.printf("\r\nRA8875 Touch Colors - Build " __DATE__ " " __TIME__ "\r\n"); pc.printf("Turning on display\r\n"); lcd.init(); lcd.TouchPanelCalibrate("Calibrate the touch panel"); lcd.cls(); // +----------------------------------------------------+ // | (x,y) (xxx,yyy) [Capture] rgb (RR,GG,BB) | // | +------------------------------------------------+ | y = 50 // | | Sample Shown Here | | // | +------------------------------------------------+ | y = 89 // | Red 0 to 255 ------------------------------------+ | y = 100 // | | | | // | +------------------------------------------------+ | y = 139 // | Grn 0 to 255 ------------------------------------+ | y = 150 // | | | | // | +------------------------------------------------+ | y = 189 // | Blu 0 to 255 ------------------------------------+ | y = 200 // | | | | // | +------------------------------------------------+ | y = 239 // +----------------------------------------------------+ y = 271 // 10 470 rect_t RGBList[] = { { 10,100, 470,139 }, // R { 10,150, 470,189 }, // G { 10,200, 470,239 }, // B { 10, 50, 470, 89 } // This for the Sample }; rect_t PrintScreenRect = { 235-30, 5, 235+30, 40}; lcd.fillrect(RGBList[0], Red); lcd.fillrect(RGBList[1], Green); lcd.fillrect(RGBList[2], Blue); lcd.fillrect(PrintScreenRect, Gray); lcd.foreground(Blue); lcd.background(Gray); lcd.puts(235-28, 15, "Capture"); lcd.background(Black); color_t rgb = Black; uint8_t rgbVal[3] = { 0, 0, 0 }; for (;;) { point_t p; if (lcd.TouchPanelReadable(&p)) { lcd.foreground(Blue); lcd.SetTextCursor(10, 15); lcd.printf("(%3d,%3d)", p.x, p.y); if (Intersect(PrintScreenRect, p)) { GetScreenCapture(); } for (int i=0; i<3; i++) { if (Intersect(RGBList[i], p)) { uint8_t mag = (255 * (p.x - RGBList[i].p1.x)) / (RGBList[i].p2.x - RGBList[i].p1.x); rgbVal[i] = mag; lcd.SetTextCursor(380, 15); lcd.foreground(Blue); lcd.printf("(%02X,%02X,%02X)", rgbVal[0], rgbVal[1], rgbVal[2]); rgb = RGB(rgbVal[0], rgbVal[1], rgbVal[2]); lcd.fillrect(RGBList[3], rgb); break; } } } } }