Y-con P020 Electric Paper Display

Dependents:   YconP020_USBIFEx

This is a library for Y-con P020 Electric Paper Display.

sample program is here.

詳しくはこちら(sorry only in Japanese)をご覧ください。

Revision:
1:a7e6ebc4cb72
Parent:
0:4dbc7e226777
diff -r 4dbc7e226777 -r a7e6ebc4cb72 YconP020.h
--- a/YconP020.h	Fri Jul 01 13:22:18 2016 +0000
+++ b/YconP020.h	Sun Jul 03 10:38:58 2016 +0000
@@ -9,47 +9,40 @@
 #include <queue>
 using namespace std;
 #include "GraphicsDisplay.h"
+/// \class TextDisplay
+/// \brief interface class for display text
+///
+/// Because it is derived from mbed::Stream, TextDisplay has function putc(),puts(),printf() and more
 
+
+// for internal baffer
 class YconP020GBuf : public GraphicsDisplay {
 public:
-    enum INTERNALBUF { MAX_X=200,MAX_Y=96 };
-    YconP020GBuf(const char *name=NULL) : GraphicsDisplay(name) {
-        setpixelsize();
-    }
-    virtual void pixel(int x, int y, int b) {
-        if(x<0 || x>=MAX_X/pixelsizex || y<0 || y>=MAX_Y/pixelsizey) return;
-        for(int i=0; i<pixelsizex; i++) {
-            for(int j=0; j<pixelsizey; j++) {
-                pixel1x1(x*pixelsizex+i, y*pixelsizey+j, b);
-            }
-        }
-    }
-    void setpixelsize(int x=1, int y=1) {
-        pixelsizex=x;
-        pixelsizey=y;
-    }
+    enum { MAX_X=200,MAX_Y=96 };
+    YconP020GBuf(const char *name=NULL) : GraphicsDisplay(name) { setfontscale(); }
+    virtual void pixel(int x, int y, int b);
+    void setfontscale(uint8_t x=1, uint8_t y=1);
+    void pixel1x1(int x, int y, int b);
+    virtual void cls();
+    uint8_t getbyte(size_t x,size_t y) const {return buffer[y][x];}
+protected:
+private:
     virtual int width() {return MAX_X;}
     virtual int height() {return MAX_Y;}
-    int8_t get8(size_t x,size_t y) {return buffer[y][x];}
-protected:
-    void pixel1x1(int x, int y, int b) {
-        if(x<0 || x>=MAX_X || y<0 || y>=MAX_Y) return;
-        if(!b) buffer[MAX_Y-1-y][x/8] |= 1<<(7-(x%8));
-        else buffer[MAX_Y-1-y][x/8] &= ~(1<<(7-(x%8)));
-    }
-private:
-    int8_t buffer[MAX_Y][MAX_X/8];
-    int pixelsizex;
-    int pixelsizey;
+    uint8_t buffer[MAX_Y][MAX_X/8];
+    uint8_t pixelsizex;
+    uint8_t pixelsizey;
 };
 
+/// Y-con P020 Electric Paper Display
 class YconP020 : public Stream {
 static const size_t MAXRECBUFSIZE=1000;
 public:
     typedef enum {
         NOERROR=0,FILEOPENERR=1,REGINDEXERR=2,FILENOTEXIST=3,DIROPENERR=4
     } error_t;
-
+    
+    /// @param UART PinName to Y-con P020
     YconP020(PinName tx, PinName rx);
  
     /// Similar to Serial::readable()
@@ -64,36 +57,55 @@
     bool command_mode();
 
     //commands
-    string help_str() {return get_stringparam("?");} // (1)?
-    void clear_screen(bool white=true) {void_command(white? "W":"B");} //(2)W, (3)B
-    void negative_screen() {void_command("N");} //(4)N
-    void dispstoredpict(int picnum); //(5)D
-    error_t storepictfile(const string& filename, const int picnum); //(6)R
-    string infomation_str() {return get_stringparam("I");}//(7)I
-    void start_demo() {void_command("DEMO",false);} //(8)DEMO    
+    /// Y-con P020 command (1)?
+    string help_str() {return get_stringparam("?");}
+    /// Y-con P020 command (2)W, (3)B
+    void clear_screen(bool white=true) {void_command(white? "W":"B");}
+    /// Y-con P020 command (4)N
+    void negative_screen() {void_command("N");}
+    /// Y-con P020 command (5)D
+    void dispstoredpict(int picnum) {set_param("D", picnum);} //(5)D
+    /// Y-con P020 command (6)R
+    error_t storepictfile(const string& filename, const int picnum);
+    /// Y-con P020 command (7)I
+    string infomation_str() {return get_stringparam("I");}
+    /// Y-con P020 command (8)DEMO
+    void start_demo() {void_command("DEMO",false);}    
+    /// Y-con P020 command (8)DEMO stop (send ctrl+Z)
     void stop_demo();
-    int get_interval() {return get_intparam("INTERVAL","Interval");} //(9)INTERVAL
-    void set_interval(int t) {set_intparam("INTERVAL", t);}
-    //(10)LASTWAIT
-    int get_lastwait() {return get_intparam("LASTWAIT","Wait");}
-    void set_lastwait(int t) {return set_intparam("LASTWAIT", t);}
-    //(11)STANDBY
-    bool get_standby() {return get_boolparam("STANDBY");}
-    void set_standby(bool f) {return set_intparam("STANDBY", f);}
-    //(12)LED
-    bool get_led() {return get_boolparam("LED");}
-    void set_led(bool f) {return set_intparam("LED", f);}
-    //(13)P37
-    int get_p37() {return get_boolparam("P37");}
-    void set_p37(bool f) {return set_intparam("P37", f);}
-    void exit_commandmode() {void_command("EXIT",false);} //(14)EXIT
-    void reset_screen() {void_command("RESET",false);} //(15)RESET
-    string yslab_info() {return get_stringparam("YSLAB");} //(16)YSLAB
+    /// Y-con P020 command (9)INTERVAL
+    int command_interval() {return get_intparam("INTERVAL","Interval");}
+    /// Y-con P020 command (9)INTERVAL time
+    void command_interval(int t) {set_param("INTERVAL", t);}
+    /// Y-con P020 command (10)LASTWAIT
+    int command_lastwait() {return get_intparam("LASTWAIT","Wait");}
+    /// Y-con P020 command (10)LASTWAIT time
+    void command_lastwait(int t) {return set_param("LASTWAIT", t);}
+    /// Y-con P020 command (11)STANDBY
+    bool command_standby() {return get_boolparam("STANDBY");}
+    /// Y-con P020 command (11)STANDBY [0|1]
+    void command_standby(bool f) {return set_param("STANDBY", f);}
+    /// Y-con P020 command (12)LED
+    bool command_led() {return get_boolparam("LED");}
+    /// Y-con P020 command (12)LED [0|1]
+    void command_led(bool f) {return set_param("LED", f);}
+    /// Y-con P020 command (13)P37
+    bool command_p37() {return get_boolparam("P37");}
+    /// Y-con P020 command (13)P37 [0|1]
+    void command_p37(bool f) {return set_param("P37", f);}
+    /// Y-con P020 command (14)EXIT
+    void command_exit() {void_command("EXIT",false);}
+    /// Y-con P020 command (15)RESET
+    void command_reset() {void_command("RESET",false);}
+    /// Y-con P020 command (16)YSLAB
+    string yslab_info() {return get_stringparam("YSLAB");}
         
     /// get file list of directories
     const vector<string>& getfilelist(const vector<string>& dirs);
     /// get file list of directory
-    const vector<string>& getfilelist(const string& dir);
+    const vector<string>& getfilelist(const string& dir) {
+        return getfilelist(vector<string>(1,dir));
+    }
     /// return previous file list
     const vector<string>& getfilelist() const {return filelist;}
     /// get all file list
@@ -101,11 +113,29 @@
     /// display file
     error_t dispfile(const string& filename);
 
+    /** output text to internal buffer. for example
+     * @code
+     * epd.text()->cls();
+     * epd.setfontscale(2,3);
+     * epd.text()->puts("Hello World\nYconP020\n");
+     * epd.setfontscale();
+     * epd.text()->printf("%d\n", epd.command_led());
+     * epd.display_internalbuf();
+     * @endcode
+     */ 
     TextDisplay* text() {return &internalbuf;}
-    void setpixelsize(int x=0, int y=0) {internalbuf.setpixelsize(x,y);}
-    void pset(int x, int y, bool b=true) {internalbuf.pixel(x,y,b);}
-    void clear_internalbuf(int8_t data=0) { internalbuf.cls(); }
+    /// set size of pixel
+    void setfontscale(uint8_t x=1, uint8_t y=1) {internalbuf.setfontscale(x,y);}
+    /// set pixel at internal buffer
+    void pset(int x, int y, bool b=true) {internalbuf.pixel1x1(x,y,b);}
+    /// clear internal buffer
+    void clear_internalbuf() { internalbuf.cls(); }
+    /// send internal buffer to Y-con P020
     void display_internalbuf();
+    /// width of Y-con P020 (==200)
+    int width() const { return YconP020GBuf::MAX_X; }
+    /// height of Y-con P020 (==96)
+    int height() const { return YconP020GBuf::MAX_Y; }
 protected:       
     void uartint();
     void push_recbuf(char c);
@@ -114,13 +144,14 @@
     error_t sendfile(const string& filename);
 
     //for command line intercept
-    int putc_intercept(int c);
-    bool commandline_D(const string &comline);
-    bool commandline_L(const string &comline);
+    string localcomline;
+    virtual int putc_intercept(int c);
 
-    //sub-functions for execute commands
+    //sub-functions for functions of Y-con P020 command
+    void send_command(const string& command, bool waitready=true);
     void void_command(const string& command, bool waitready=true);
-    void set_intparam(const string& command, int param);
+    void set_param(const string& command, int param);
+    //void set_param(const string& command, bool param); //int版で代用できるので要らない
     int get_intparam(const string& command, const string& retstr);
     bool get_boolparam(const string& command);
     string get_stringparam(const string& command);
@@ -132,7 +163,6 @@
     string recinbuf;
     bool use_recinbuf;
     vector<string> filelist;
-    string localcomline;
     YconP020GBuf internalbuf;
 
     virtual int _getc();