mbed Paint for the RA8875 display with based touch screen.

Dependencies:   menu mbed RA8875

mPaint

mbed Paint - a demo for the (480x272) RA8875 Display with touchscreen.

Touch Screen

Having had several of the 4.3" WQVGA displays (that use the RA8875), I created the RA8875 driver library (initially derived derived from the work of others). Absent for some time was support for the touch-screen interface. Support first appeared with the contributions of others, and then a major update (due to a recent acquisition of a touch-screen version). This is now much more fully developed and it is part of the standard library.

Demo the Touch Screen

How to demonstrate the touch screen support? mPaint was created for just that purpose.

Screen Shots

Here's a couple of screen shots - you can capture the "canvas" (left) or the composite image (right). As you see, the composite picks up the menu information, however it remains subdued because of the transparency setting.

/media/uploads/WiredHome/mpaint_screen01.png/media/uploads/WiredHome/mpaint_screen02.png

Program Build Info

I'm sometimes a bit skeptical of the reported metrics (perhaps because most of my mbed applications have Ethernet), but here is the reported information from the build of this program.

mPaint Build Infoblinky Build Info
/media/uploads/WiredHome/mpaint_buildinfo.png/media/uploads/WiredHome/blinky_buildinfo.png
RA8875 Graphics library is the primary user.blinky is almost all "startup code" and standard libs

How does mPaint and the graphics library do this in about 1 kB RAM?

The answer is that the display is used as a "write-only" memory, and it has enough RAM hosted in the RA8875 for two full screens (in the WQVGA mode).

mPaint features

  • RGB color selection using touch, with a visible sample.
  • Pen size selection.
    From a limited set.
  • Tool choices.
    Dot, Line, Joined lines.
  • Save your creation.
    Select File | Save..., and it reads the display memory as it creates the BMP file on the local file system.
    This is rather slow (due to both the display read and the local file system).
  • Sorry, no undo.
    If you don't like what "ink" you put down, you can draw over it (much like other paint programs).

Files at this revision

API Documentation at this revision

Comitter:
WiredHome
Date:
Sat Jan 03 17:12:02 2015 +0000
Parent:
2:cf295dad3192
Child:
4:fbd196119f8c
Commit message:
Move RGB selection to the other layer - less visual interference with the canvas drawing.

Changed in this revision

main.cpp Show annotated file Show diff for this revision Revisions of this file
menu.lib Show annotated file Show diff for this revision Revisions of this file
--- a/main.cpp	Sat Jan 03 15:41:51 2015 +0000
+++ b/main.cpp	Sat Jan 03 17:12:02 2015 +0000
@@ -105,6 +105,7 @@
 Menu::post_fnc_action_t Tools(uint32_t v);
 Menu::post_fnc_action_t Tools_Type(uint32_t v);
 Menu::post_fnc_action_t PenSize(uint32_t v);
+Menu::post_fnc_action_t HideMenu(uint32_t v);
 
 // Some APIs
 extern "C" void mbed_reset();
@@ -143,6 +144,7 @@
     { "File", File, NULL, NULL, 0, file_menu },
     { "Pen",  NULL, NULL, NULL, 0, pen_menu },
     { "Tools", NULL, NULL, NULL, 0, tools_menu },
+    { "Hide", NULL, NULL, HideMenu, 0, NULL },
     { NULL, NULL, NULL, NULL, 0, NULL },
 };
 
@@ -150,17 +152,20 @@
 
 Menu::post_fnc_action_t File(uint32_t v)
 {
+    (void)v;
     INFO("File");
     return Menu::no_action;
 }
 Menu::post_fnc_action_t File_New(uint32_t v)
 {
+    (void)v;
     INFO("File_New");
     InitDisplay();
     return Menu::no_action;
 }
 Menu::post_fnc_action_t File_Save(uint32_t v)
 {
+    (void)v;
     INFO("File_Save");
     RA8875::LayerMode_T l = lcd.GetLayerMode();
     lcd.SetLayerMode(RA8875::ShowLayer0);
@@ -170,18 +175,21 @@
 }
 Menu::post_fnc_action_t File_Save_All(uint32_t v)
 {
+    (void)v;
     INFO("File_Save_All");
     GetScreenCapture();
     return Menu::close_menu;
 }
 Menu::post_fnc_action_t File_Cal(uint32_t v)
 {
+    (void)v;
     INFO("Tools_Cal");
     CalibrateTS();
     return Menu::no_action;
 }
 Menu::post_fnc_action_t File_Reset(uint32_t v)
 {
+    (void)v;
     INFO("rebooting now...");
     wait_ms(1000);
     mbed_reset();
@@ -189,11 +197,13 @@
 }
 Menu::post_fnc_action_t Edit(uint32_t v)
 {
+    (void)v;
     INFO("Edit");
     return Menu::no_action;
 }
 Menu::post_fnc_action_t Tools(uint32_t v)
 {
+    (void)v;
     INFO("Tools");
     return Menu::no_action;
 }
@@ -222,6 +232,11 @@
     ShowSampleRGB();
     return Menu::close_menu;
 }
+Menu::post_fnc_action_t HideMenu(uint32_t v)
+{
+    (void)v;
+    return Menu::close_menu;
+}
 
 void ShowSampleRGB(void)
 {
@@ -278,11 +293,8 @@
 
 void InitDisplay(void)
 {
-    lcd.cls(3); // both layers
     lcd.SelectDrawingLayer(CANVAS);
-    lcd.fillrect(RGBList[0], Red);
-    lcd.fillrect(RGBList[1], Green);
-    lcd.fillrect(RGBList[2], Blue);
+    lcd.cls();
     lcd.foreground(Blue);
     lcd.background(Black);
 }
@@ -307,16 +319,33 @@
     return 0;
 }
 
-void SeeIfUserSelectingRGBValues(point_t p, TouchCode_t touchcode)
+void ShowRGBSelectors(void)
 {
+    uint16_t curLayer = lcd.GetDrawingLayer();
+    lcd.SelectDrawingLayer(MENUS);
+    lcd.fillrect(RGBList[0], Red);
+    lcd.fillrect(RGBList[1], Green);
+    lcd.fillrect(RGBList[2], Blue);
+    lcd.SelectDrawingLayer(curLayer);
+}
+
+bool SeeIfUserSelectingRGBValues(point_t p, TouchCode_t touchcode)
+{
+    static bool wasIn = false;
+    
     // See if the touch is setting new RGB values
     for (int i=0; i<3; i++) {
         if (lcd.Intersect(RGBList[i], p)) {
             uint8_t mag = (255 * (p.x - RGBList[i].p1.x)) / (RGBList[i].p2.x - RGBList[i].p1.x);
+            wasIn = true;
+            if (touchcode == touch)
+                menu.Show();
+            else if (touchcode == release)
+                menu.Hide();
             rgbVal[i] = mag;
             // update the RGB values
             lcd.SelectDrawingLayer(MENUS);
-            lcd.SetTextCursor(lcd.width() - 100, lcd.height() - 18);
+            lcd.SetTextCursor(lcd.width() - 80, lcd.height() - 16);
             lcd.foreground(Blue);
             lcd.printf("(%02X,%02X,%02X)", rgbVal[0], rgbVal[1], rgbVal[2]);
             // show sample
@@ -325,9 +354,12 @@
             //
             lcd.SelectDrawingLayer(CANVAS);
             lcd.foreground(rgb);
-            break;
+            return true;
         }
     }
+    if (wasIn)
+        menu.Hide();
+    return false;
 }
 
 void ThickLine(point_t origin, point_t p)
@@ -405,9 +437,10 @@
 
     INFO("Turning on display");
     lcd.init();
-    menu.init();
     InitTS();
     InitDisplay();
+    menu.init();
+    ShowRGBSelectors();
 
     INFO("processing loop...");
 
@@ -419,22 +452,17 @@
             int curLayer = lcd.GetDrawingLayer();
             lcd.SelectDrawingLayer(MENUS);
             lcd.foreground(Blue);
-            lcd.SetTextCursor(0, 255);
+            lcd.SetTextCursor(0, lcd.height() - 16);
             lcd.printf("(%3d,%3d) - (%3d,%3d)", origin.x, origin.y, p.x, p.y);
             lcd.SelectDrawingLayer(curLayer);
 
             bool menuHandledIt = menu.HandledTouch(p, touchcode);
             if (menuHandledIt) {
                 // menu handled it
+            } else if (SeeIfUserSelectingRGBValues(p, touchcode)) {
+                // that handled it.
             } else {
-                // app to handle the touch
-                if (!menu.isVisible()) {
-                    SeeIfUserSelectingRGBValues(p, touchcode);
-                    SeeIfUserDrawingOnCanvas(p, touchcode);
-                } else { /* MENU */
-                    WARN("on menu - invalid x,y");
-                    menu.Hide();
-                }
+                SeeIfUserDrawingOnCanvas(p, touchcode);
             }
         } else {
             //non-touch
--- a/menu.lib	Sat Jan 03 15:41:51 2015 +0000
+++ b/menu.lib	Sat Jan 03 17:12:02 2015 +0000
@@ -1,1 +1,1 @@
-http://developer.mbed.org/users/WiredHome/code/menu/#905736afd672
+http://developer.mbed.org/users/WiredHome/code/menu/#d7a34c7f775b