Library for 4D systems touchscreen
Diff: TouchScreen.h
- Revision:
- 0:edf5f3d8645e
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/TouchScreen.h Tue Aug 21 14:40:18 2012 +0000 @@ -0,0 +1,123 @@ +/*************************** + * Created by Ashley Mills * + ***************************/ +#pragma once +#include "mbed.h" +#include "rtos.h" + +#define lowByte(w) ((uint8_t) ((w) & 0xff)) +#define highByte(w) ((uint8_t) ((w) >> 8)) + +typedef enum { + NO_TOUCH_ACTIVITY=0, + TOUCH_PRESS, + TOUCH_RELEASE, + TOUCH_MOVING +} eTouchStatus; + +typedef enum { + LANDSCAPE=0, + LANDSCAPE_R, + NATIVE, + PORTRAIT_R +} eScreenOrientation; + +typedef enum { + BAUD_9600, + BAUD_14400, + BAUD_19200, + BAUD_57600, + BAUD_115200, + BAUD_256000 +} eBaudRate; + +typedef struct { + uint16_t x; + uint16_t y; +} TouchPoint; + +typedef enum { + INTERNAL_FONT_5x7, + INTERNAL_FONT_8x8, + INTERNAL_FONT_8x12, + INTERNAL_FONT_12x16 +} eInternalFont; + +class TouchScreen : Serial { + public: + static const int WIDTH = 320; + static const int HEIGHT = 240; + + // constructors + TouchScreen(PinName tx, PinName rx, PinName resetPin, const char *name = NULL); + TouchScreen(PinName tx, PinName rx, PinName resetPin, eBaudRate baud, const char *name = NULL); + bool begin(); + + // drawing commands + void drawCircle(uint16_t xPos, uint16_t yPos, uint16_t radius, uint16_t color); + void drawPixel(uint16_t xPos, uint16_t yPos, uint16_t color); + void clearScreen(); + void setBackgroundColor(uint16_t color); + void setPenSolid(); + void setPenWireframe(); + void drawImage(char *name, uint16_t x, uint16_t y); + void drawGraphicsFormatString(uint16_t x, uint16_t y, eInternalFont font, uint16_t textColor, uint8_t charWidth, uint8_t charHeight, char* text); + + void drawRectangle(uint16_t topLeftX, uint16_t topLeftY, uint16_t botRightX, uint16_t botRightY, uint16_t color); + void drawRectangleWH(uint16_t topLeftX, uint16_t topLeftY, uint16_t width, uint16_t height, uint16_t color); + void drawRectangleWH(uint16_t topLeftX, uint16_t topLeftY, uint16_t width, uint16_t height); + void drawLine(uint16_t topLeftX, uint16_t topLeftY, uint16_t botRightX, uint16_t botRightY, uint16_t color); + + // drawing text + void drawTextFormatString(uint8_t row, uint8_t column, eInternalFont font, uint16_t textColor, char* text); + void drawChar(char c, uint16_t x, uint16_t y, uint16_t color, uint8_t width, uint8_t height); + void drawText(char *s, uint16_t x, uint16_t y); + void setFont(uint8_t fontIndex); + + // color creation + uint16_t createRGB(uint8_t r, uint8_t g, uint8_t b); + uint16_t createRGBClassic(int r, int g, int b); + uint16_t createRGBF(float r, float g, float b); + + // touch commands + void enableTouch(); + void disableTouch(); + eTouchStatus getTouchStatus(); + TouchPoint getLastTouch(); + void reset(); + + // misc commands + void getVersion(); + void setOrientation(eScreenOrientation o); + bool setBaudRate(eBaudRate baud); + void setBacklight(bool state); + void setContrast(uint8_t value); + + void setFillColor(uint16_t c); + void setStrokeColor(uint16_t c); + + private: + void dropByte(); + void dropBytes(uint16_t numBytes); + void dropByteAndWaitUntilReadable(); + bool gack(); + bool waitUntilReadable(); + + DigitalOut *_resetPin; + uint16_t _fillColor; + uint16_t _strokeColor; + bool _initOK; +}; + + +/* +Header (6 bytes as 3 words) +word1 (Hi:Lo) = width : horizontal size of the image +word2 (Hi:Lo) = height : vertical size of the image +Word3 = colour_mode : 16dec = 65K colour mode, 16bits/2bytes per pixel (msb, lsb) + +The header is then followed by the pixel data +Pixel1�PixelN: Image pixel data and N is the total number of pixels + N = height x width when colour_mode = 0 + N = height x width x 2 when colour_mode = 1 +*/