Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependencies: menu mbed RA8875
Diff: main.cpp
- Revision:
- 8:412e2819092e
- Parent:
- 7:e8a7c28c6ebf
- Child:
- 10:52b0f7ccbc40
--- a/main.cpp Sat Jan 23 17:46:01 2016 +0000
+++ b/main.cpp Sat May 06 20:23:53 2017 +0000
@@ -12,29 +12,12 @@
///
/// @author David Smart, Smartware Computing
//
-// +----------------------------------------------------+
-// | File Edit Pen Tools [sample](o)[rrrr][gggg][bbbb] |
-// +----------------------------------------------------+ 16
-// | |
-// | canvas |
-// | |
-// | |
-// | |
-// | |
-// | |
-// | |
-// | |
-// | |
-// +----------------------------------------------------+
-// | (xxx,yyy) - (xxx,yyy) rgb (RR,GG,BB) |
-// +----------------------------------------------------+ 271
-// 0 479
//
#include "mbed.h" // tested with v112
#include "RA8875.h" // tested with v102
#include "menu.h" // v3
-//#define DEBUG "mPaint"
+#define DEBUG "mPaint"
// ...
// INFO("Stuff to show %d", var); // new-line is automatically appended
//
@@ -49,17 +32,44 @@
#define HexDump(a, b, c)
#endif
-// Local File System:
-// - Store the touch screen calibration
-// - Capture works of art in BMP format.
-LocalFileSystem local("local");
+// Define this for 800x480 panel, undefine for 480x272
+#define BIG_SCREEN
+
+// Define this for Cap touch panel, undefine for resistive
+#define CAP_TOUCH
+
+#ifdef CAP_TOUCH
+RA8875 lcd(p5, p6, p7, p12, NC, p9,p10,p13, "tft"); // SPI:{MOSI,MISO,SCK,/ChipSelect,/reset}, I2C:{SDA,SCL,/IRQ}, name
+#else
+RA8875 lcd(p5, p6, p7, p12, NC, "tft"); // SPI:{MOSI,MISO,SCK,/ChipSelect,/reset}, name
+// LocalFileSystem local("local"); // if not otherwise needed; access to calibration file for resistive touch.
+#endif
+
+#define PC_BAUD 460800 // I like the serial communications to be very fast
-// The display interface
-RA8875 lcd(p5, p6, p7, p12, NC, "tft"); // MOSI, MISO, SCK, /ChipSelect, /reset, name
+// // // // // // // // // // // // // // // // // // // // // // // //
+// End of Configuration Section
+// // // // // // // // // // // // // // // // // // // // // // // //
+
+#ifdef BIG_SCREEN
+#define LCD_W 800
+#define LCD_H 480
+#define LCD_C 8 // color - bits per pixel
+#define DEF_RADIUS 50 // default radius of the fingerprint
+#define BL_NORM 25 // Backlight Normal setting (0 to 255)
+#else
+#define LCD_W 480
+#define LCD_H 272
+#define LCD_C 8 // color - bits per pixel
+#define DEF_RADIUS 20 // default radius of the fingerprint
+#define BL_NORM 25 // Backlight Normal setting (0 to 255)
+#endif
// A monitor port for the SW developer.
Serial pc(USBTX, USBRX);
+LocalFileSystem local("local");
+
// list of tools (dots, lines, joined lines).
typedef enum {
dot, // draw dots at the point
@@ -73,18 +83,51 @@
tooltype_t selectedtooltype = dot; // 0:dot, 1:line, 2:join
point_t origin = { 0, 0}; // tracks origin when drawing a line
+// 0 200 400 500 600 700 800
+// | | | | | | | | |
+// 0 100 200 300 400 500
+// | | | | | |
+// +---------------------------------------------------+ 0
+// | File Edit Pen Tools [smpl](o) [rrr][ggg][bbb] |
+// +---------------------------------------------------+
+// | | 16 32
+// | canvas |
+// | |
+// | |
+// | |
+// | |
+// | |
+// | |
+// | |
+// | |
+// +---------------------------------------------------+ 255 463
+// | (xxx,yyy) - (xxx,yyy) rgb (RR,GG,BB) |
+// +---------------------------------------------------+ 271 479
+// 0 479
+// 0 799
-// Adjust the following if using the 800x600 display
-const rect_t RGBList[] = { // regions on the display for special tools
- { 309,0, 359,15 }, // R
- { 369,0, 419,15 }, // G
- { 429,0, 479,15 }, // B
- { 249,0, 299,15 } // show selected color
+// Adjust the following if using the 800x480 v 480x272 display
+#if LCD_W == 800
+const rect_t RGBList[] = { // regions on the display for special tools
+ { 425,0, 425+50,30 }, // show selected color
+ { 500,0, 500+80,30 }, // R
+ { 600,0, 600+80,30 }, // G
+ { 700,0, 700+80,30 }, // B
};
const rect_t canvas_rect = { // the drawing surface
- 0,16, 479,271
+ 0,32, LCD_W-1,LCD_H-1
};
-
+#else
+const rect_t RGBList[] = { // regions on the display for special tools
+ { 249,0, 249+50,15 }, // show selected color
+ { 309,0, 309+50,15 }, // R
+ { 369,0, 369+50,15 }, // G
+ { 429,0, 429+50,15 }, // B
+};
+const rect_t canvas_rect = { // the drawing surface
+ 0,16, LCD_W-1,LCD_H-1
+};
+#endif
// File Pen Tools
@@ -240,14 +283,13 @@
void ShowSampleRGB(void)
{
- loc_t middle = (RGBList[3].p1.y + RGBList[3].p2.y)/2;
- lcd.fillrect(RGBList[3], Black);
- lcd.fillrect(RGBList[3], rgb);
+ loc_t middle = (RGBList[0].p1.y + RGBList[0].p2.y)/2;
+ lcd.fillrect(RGBList[0], Black);
if (selectedtooltype == dot) {
- lcd.fillcircle((RGBList[3].p1.x + RGBList[3].p2.x)/2,
- middle, pensize, rgb);
+ lcd.fillcircle((RGBList[0].p1.x + RGBList[0].p2.x)/2,
+ middle, pensize, rgb);
} else {
- lcd.fillrect(RGBList[3].p1.x,middle-pensize/2, RGBList[3].p2.x,middle+pensize/2, rgb);
+ lcd.fillrect(RGBList[0], rgb);
}
}
@@ -309,6 +351,7 @@
snprintf(fqfn, sizeof(fqfn), "/local/Screen%02d.bmp", i);
FILE * fh = fopen(fqfn, "rb");
if (!fh) {
+ INFO("Saving as %s", fqfn);
lcd.PrintScreen(0,0,lcd.width(),lcd.height(),fqfn);
INFO(" as /local/Screen%02d.bmp", i);
return i;
@@ -323,18 +366,18 @@
{
uint16_t curLayer = lcd.GetDrawingLayer();
lcd.SelectDrawingLayer(MENUS);
- lcd.fillrect(RGBList[0], Red);
- lcd.fillrect(RGBList[1], Green);
- lcd.fillrect(RGBList[2], Blue);
+ lcd.fillrect(RGBList[1], Red);
+ lcd.fillrect(RGBList[2], Green);
+ lcd.fillrect(RGBList[3], 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++) {
+ for (int i=1; 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;
@@ -342,10 +385,10 @@
menu.Show();
else if (touchcode == release)
menu.Hide();
- rgbVal[i] = mag;
+ rgbVal[i-1] = mag;
// update the RGB values
lcd.SelectDrawingLayer(MENUS);
- lcd.SetTextCursor(lcd.width() - 80, lcd.height() - 16);
+ lcd.SetTextCursor(lcd.width() - 10*lcd.fontwidth(), lcd.height() - lcd.fontheight());
lcd.foreground(Blue);
lcd.printf("(%02X,%02X,%02X)", rgbVal[0], rgbVal[1], rgbVal[2]);
// show sample
@@ -362,36 +405,16 @@
return false;
}
-void ThickLine(point_t origin, point_t p)
+int sgn(int x)
{
- double angleN;
- loc_t dy;
- loc_t dx;
- point_t s = { 0, 0 };
- point_t e = { 0, 0 };
+ if (sgn < 0)
+ return -1;
+ else if (sgn > 0)
+ return 1;
+ else
+ return 0;
+}
- lcd.line(origin,p, rgb);
- INFO(" End @ (%3d,%3d) - (%3d,%3d) [%d]", origin.x, origin.y, p.x, p.y, pensize);
- #define PI 3.14159
- dy = p.y - origin.y;
- dx = p.x - origin.x;
- INFO("delta (%+3d,%+3d)", dx,dy);
- angleN = atan2((double)(dy), (double)(dx));
- if (pensize == 1) {
- lcd.line(origin, p, rgb);
- } else {
- int thickness = pensize/2;
- for (int l=0; l<=pensize; l++) {
- s.x = origin.x + (l - thickness) * cos(angleN+PI/2);
- s.y = origin.y + (l - thickness) * sin(angleN+PI/2);
- e.x = p.x + (l - thickness) * cos(angleN+PI/2);
- e.y = p.y + (l - thickness) * sin(angleN+PI/2);
- lcd.line(s, e, rgb);
- INFO(" %+d @ (%3d,%3d) - (%3d,%3d) a:%+3.2f:%+3.2f",
- l, s.x,s.y, e.x,e.y, angleN, angleN+PI/2);
- }
- }
-}
void SeeIfUserDrawingOnCanvas(point_t p, TouchCode_t touchcode)
@@ -407,7 +430,7 @@
origin = p;
INFO("Origin @ (%3d,%3d)", p.x, p.y);
} else if (touchcode == release) {
- ThickLine(origin, p);
+ lcd.ThickLine(origin, p, pensize, rgb);
}
break;
case join:
@@ -416,13 +439,13 @@
origin = p;
INFO("Origin @ (%3d,%3d)", p.x, p.y);
} else if (touchcode == release) {
- ThickLine(origin, p);
+ lcd.ThickLine(origin, p, pensize, rgb);
} else if (touchcode == held) {
- ThickLine(origin, p);
+ lcd.ThickLine(origin, p, pensize, rgb);
origin = p;
INFO(" held @ (%3d,%3d)", p.x, p.y);
}
- break;
+ break;
default:
break;
}
@@ -436,9 +459,13 @@
pc.printf("\r\nRA8875 Menu - Build " __DATE__ " " __TIME__ "\r\n");
INFO("Turning on display");
- lcd.init();
+ lcd.init(LCD_W,LCD_H,LCD_C);
+ lcd.TouchPanelInit();
lcd.frequency(10000000);
- InitTS();
+ lcd.SetTextFontSize(2);
+#ifndef CAP_TOUCH
+ InitTS(); // resistive touch calibration
+#endif
InitDisplay();
menu.init();
ShowRGBSelectors();
@@ -450,13 +477,13 @@
TouchCode_t touchcode = lcd.TouchPanelReadable(&p);
if (touchcode != no_touch) {
- int curLayer = lcd.GetDrawingLayer();
+ //int curLayer = lcd.GetDrawingLayer();
// This is nice feedback, but certainly slows the drawing.
//lcd.SelectDrawingLayer(MENUS);
//lcd.foreground(Blue);
//lcd.SetTextCursor(0, lcd.height() - 16);
//lcd.printf("(%3d,%3d) - (%3d,%3d)", origin.x, origin.y, p.x, p.y);
- lcd.SelectDrawingLayer(curLayer);
+ //lcd.SelectDrawingLayer(curLayer);
bool menuHandledIt = menu.HandledTouch(p, touchcode);
if (menuHandledIt) {
@@ -471,6 +498,7 @@
}
}
}
+
#include <stdarg.h>
//Custom override for error()
void error(const char* format, ...)