Y-con P020 Electric Paper Display
This is a library for Y-con P020 Electric Paper Display.
sample program is here.
詳しくはこちら(sorry only in Japanese)をご覧ください。
YconP020.h@1:a7e6ebc4cb72, 2016-07-03 (annotated)
- Committer:
- jk1lot
- Date:
- Sun Jul 03 10:38:58 2016 +0000
- Revision:
- 1:a7e6ebc4cb72
- Parent:
- 0:4dbc7e226777
1st published version
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
jk1lot | 0:4dbc7e226777 | 1 | #ifndef YCONP020_H |
jk1lot | 0:4dbc7e226777 | 2 | #define YCONP020_H |
jk1lot | 0:4dbc7e226777 | 3 | |
jk1lot | 0:4dbc7e226777 | 4 | #include "Stream.h" |
jk1lot | 0:4dbc7e226777 | 5 | #include "Serial.h" |
jk1lot | 0:4dbc7e226777 | 6 | using namespace mbed; |
jk1lot | 0:4dbc7e226777 | 7 | #include <string> |
jk1lot | 0:4dbc7e226777 | 8 | #include <vector> |
jk1lot | 0:4dbc7e226777 | 9 | #include <queue> |
jk1lot | 0:4dbc7e226777 | 10 | using namespace std; |
jk1lot | 0:4dbc7e226777 | 11 | #include "GraphicsDisplay.h" |
jk1lot | 1:a7e6ebc4cb72 | 12 | /// \class TextDisplay |
jk1lot | 1:a7e6ebc4cb72 | 13 | /// \brief interface class for display text |
jk1lot | 1:a7e6ebc4cb72 | 14 | /// |
jk1lot | 1:a7e6ebc4cb72 | 15 | /// Because it is derived from mbed::Stream, TextDisplay has function putc(),puts(),printf() and more |
jk1lot | 0:4dbc7e226777 | 16 | |
jk1lot | 1:a7e6ebc4cb72 | 17 | |
jk1lot | 1:a7e6ebc4cb72 | 18 | // for internal baffer |
jk1lot | 0:4dbc7e226777 | 19 | class YconP020GBuf : public GraphicsDisplay { |
jk1lot | 0:4dbc7e226777 | 20 | public: |
jk1lot | 1:a7e6ebc4cb72 | 21 | enum { MAX_X=200,MAX_Y=96 }; |
jk1lot | 1:a7e6ebc4cb72 | 22 | YconP020GBuf(const char *name=NULL) : GraphicsDisplay(name) { setfontscale(); } |
jk1lot | 1:a7e6ebc4cb72 | 23 | virtual void pixel(int x, int y, int b); |
jk1lot | 1:a7e6ebc4cb72 | 24 | void setfontscale(uint8_t x=1, uint8_t y=1); |
jk1lot | 1:a7e6ebc4cb72 | 25 | void pixel1x1(int x, int y, int b); |
jk1lot | 1:a7e6ebc4cb72 | 26 | virtual void cls(); |
jk1lot | 1:a7e6ebc4cb72 | 27 | uint8_t getbyte(size_t x,size_t y) const {return buffer[y][x];} |
jk1lot | 1:a7e6ebc4cb72 | 28 | protected: |
jk1lot | 1:a7e6ebc4cb72 | 29 | private: |
jk1lot | 0:4dbc7e226777 | 30 | virtual int width() {return MAX_X;} |
jk1lot | 0:4dbc7e226777 | 31 | virtual int height() {return MAX_Y;} |
jk1lot | 1:a7e6ebc4cb72 | 32 | uint8_t buffer[MAX_Y][MAX_X/8]; |
jk1lot | 1:a7e6ebc4cb72 | 33 | uint8_t pixelsizex; |
jk1lot | 1:a7e6ebc4cb72 | 34 | uint8_t pixelsizey; |
jk1lot | 0:4dbc7e226777 | 35 | }; |
jk1lot | 0:4dbc7e226777 | 36 | |
jk1lot | 1:a7e6ebc4cb72 | 37 | /// Y-con P020 Electric Paper Display |
jk1lot | 0:4dbc7e226777 | 38 | class YconP020 : public Stream { |
jk1lot | 0:4dbc7e226777 | 39 | static const size_t MAXRECBUFSIZE=1000; |
jk1lot | 0:4dbc7e226777 | 40 | public: |
jk1lot | 0:4dbc7e226777 | 41 | typedef enum { |
jk1lot | 0:4dbc7e226777 | 42 | NOERROR=0,FILEOPENERR=1,REGINDEXERR=2,FILENOTEXIST=3,DIROPENERR=4 |
jk1lot | 0:4dbc7e226777 | 43 | } error_t; |
jk1lot | 1:a7e6ebc4cb72 | 44 | |
jk1lot | 1:a7e6ebc4cb72 | 45 | /// @param UART PinName to Y-con P020 |
jk1lot | 0:4dbc7e226777 | 46 | YconP020(PinName tx, PinName rx); |
jk1lot | 0:4dbc7e226777 | 47 | |
jk1lot | 0:4dbc7e226777 | 48 | /// Similar to Serial::readable() |
jk1lot | 0:4dbc7e226777 | 49 | bool readable() {return !recoutbuf.empty();} |
jk1lot | 0:4dbc7e226777 | 50 | /// check ready to send command |
jk1lot | 0:4dbc7e226777 | 51 | bool command_ready() const { return lastchar=='!'; } |
jk1lot | 0:4dbc7e226777 | 52 | /// wait for ready to send command |
jk1lot | 0:4dbc7e226777 | 53 | /// @return false timeout |
jk1lot | 0:4dbc7e226777 | 54 | bool wait_command_ready(int ms=10000); |
jk1lot | 0:4dbc7e226777 | 55 | /// change to command mode from normal(send file) mode |
jk1lot | 0:4dbc7e226777 | 56 | /// @return flase timeout |
jk1lot | 0:4dbc7e226777 | 57 | bool command_mode(); |
jk1lot | 0:4dbc7e226777 | 58 | |
jk1lot | 0:4dbc7e226777 | 59 | //commands |
jk1lot | 1:a7e6ebc4cb72 | 60 | /// Y-con P020 command (1)? |
jk1lot | 1:a7e6ebc4cb72 | 61 | string help_str() {return get_stringparam("?");} |
jk1lot | 1:a7e6ebc4cb72 | 62 | /// Y-con P020 command (2)W, (3)B |
jk1lot | 1:a7e6ebc4cb72 | 63 | void clear_screen(bool white=true) {void_command(white? "W":"B");} |
jk1lot | 1:a7e6ebc4cb72 | 64 | /// Y-con P020 command (4)N |
jk1lot | 1:a7e6ebc4cb72 | 65 | void negative_screen() {void_command("N");} |
jk1lot | 1:a7e6ebc4cb72 | 66 | /// Y-con P020 command (5)D |
jk1lot | 1:a7e6ebc4cb72 | 67 | void dispstoredpict(int picnum) {set_param("D", picnum);} //(5)D |
jk1lot | 1:a7e6ebc4cb72 | 68 | /// Y-con P020 command (6)R |
jk1lot | 1:a7e6ebc4cb72 | 69 | error_t storepictfile(const string& filename, const int picnum); |
jk1lot | 1:a7e6ebc4cb72 | 70 | /// Y-con P020 command (7)I |
jk1lot | 1:a7e6ebc4cb72 | 71 | string infomation_str() {return get_stringparam("I");} |
jk1lot | 1:a7e6ebc4cb72 | 72 | /// Y-con P020 command (8)DEMO |
jk1lot | 1:a7e6ebc4cb72 | 73 | void start_demo() {void_command("DEMO",false);} |
jk1lot | 1:a7e6ebc4cb72 | 74 | /// Y-con P020 command (8)DEMO stop (send ctrl+Z) |
jk1lot | 0:4dbc7e226777 | 75 | void stop_demo(); |
jk1lot | 1:a7e6ebc4cb72 | 76 | /// Y-con P020 command (9)INTERVAL |
jk1lot | 1:a7e6ebc4cb72 | 77 | int command_interval() {return get_intparam("INTERVAL","Interval");} |
jk1lot | 1:a7e6ebc4cb72 | 78 | /// Y-con P020 command (9)INTERVAL time |
jk1lot | 1:a7e6ebc4cb72 | 79 | void command_interval(int t) {set_param("INTERVAL", t);} |
jk1lot | 1:a7e6ebc4cb72 | 80 | /// Y-con P020 command (10)LASTWAIT |
jk1lot | 1:a7e6ebc4cb72 | 81 | int command_lastwait() {return get_intparam("LASTWAIT","Wait");} |
jk1lot | 1:a7e6ebc4cb72 | 82 | /// Y-con P020 command (10)LASTWAIT time |
jk1lot | 1:a7e6ebc4cb72 | 83 | void command_lastwait(int t) {return set_param("LASTWAIT", t);} |
jk1lot | 1:a7e6ebc4cb72 | 84 | /// Y-con P020 command (11)STANDBY |
jk1lot | 1:a7e6ebc4cb72 | 85 | bool command_standby() {return get_boolparam("STANDBY");} |
jk1lot | 1:a7e6ebc4cb72 | 86 | /// Y-con P020 command (11)STANDBY [0|1] |
jk1lot | 1:a7e6ebc4cb72 | 87 | void command_standby(bool f) {return set_param("STANDBY", f);} |
jk1lot | 1:a7e6ebc4cb72 | 88 | /// Y-con P020 command (12)LED |
jk1lot | 1:a7e6ebc4cb72 | 89 | bool command_led() {return get_boolparam("LED");} |
jk1lot | 1:a7e6ebc4cb72 | 90 | /// Y-con P020 command (12)LED [0|1] |
jk1lot | 1:a7e6ebc4cb72 | 91 | void command_led(bool f) {return set_param("LED", f);} |
jk1lot | 1:a7e6ebc4cb72 | 92 | /// Y-con P020 command (13)P37 |
jk1lot | 1:a7e6ebc4cb72 | 93 | bool command_p37() {return get_boolparam("P37");} |
jk1lot | 1:a7e6ebc4cb72 | 94 | /// Y-con P020 command (13)P37 [0|1] |
jk1lot | 1:a7e6ebc4cb72 | 95 | void command_p37(bool f) {return set_param("P37", f);} |
jk1lot | 1:a7e6ebc4cb72 | 96 | /// Y-con P020 command (14)EXIT |
jk1lot | 1:a7e6ebc4cb72 | 97 | void command_exit() {void_command("EXIT",false);} |
jk1lot | 1:a7e6ebc4cb72 | 98 | /// Y-con P020 command (15)RESET |
jk1lot | 1:a7e6ebc4cb72 | 99 | void command_reset() {void_command("RESET",false);} |
jk1lot | 1:a7e6ebc4cb72 | 100 | /// Y-con P020 command (16)YSLAB |
jk1lot | 1:a7e6ebc4cb72 | 101 | string yslab_info() {return get_stringparam("YSLAB");} |
jk1lot | 0:4dbc7e226777 | 102 | |
jk1lot | 0:4dbc7e226777 | 103 | /// get file list of directories |
jk1lot | 0:4dbc7e226777 | 104 | const vector<string>& getfilelist(const vector<string>& dirs); |
jk1lot | 0:4dbc7e226777 | 105 | /// get file list of directory |
jk1lot | 1:a7e6ebc4cb72 | 106 | const vector<string>& getfilelist(const string& dir) { |
jk1lot | 1:a7e6ebc4cb72 | 107 | return getfilelist(vector<string>(1,dir)); |
jk1lot | 1:a7e6ebc4cb72 | 108 | } |
jk1lot | 0:4dbc7e226777 | 109 | /// return previous file list |
jk1lot | 0:4dbc7e226777 | 110 | const vector<string>& getfilelist() const {return filelist;} |
jk1lot | 0:4dbc7e226777 | 111 | /// get all file list |
jk1lot | 0:4dbc7e226777 | 112 | const vector<string>& getfilelistall(); |
jk1lot | 0:4dbc7e226777 | 113 | /// display file |
jk1lot | 0:4dbc7e226777 | 114 | error_t dispfile(const string& filename); |
jk1lot | 0:4dbc7e226777 | 115 | |
jk1lot | 1:a7e6ebc4cb72 | 116 | /** output text to internal buffer. for example |
jk1lot | 1:a7e6ebc4cb72 | 117 | * @code |
jk1lot | 1:a7e6ebc4cb72 | 118 | * epd.text()->cls(); |
jk1lot | 1:a7e6ebc4cb72 | 119 | * epd.setfontscale(2,3); |
jk1lot | 1:a7e6ebc4cb72 | 120 | * epd.text()->puts("Hello World\nYconP020\n"); |
jk1lot | 1:a7e6ebc4cb72 | 121 | * epd.setfontscale(); |
jk1lot | 1:a7e6ebc4cb72 | 122 | * epd.text()->printf("%d\n", epd.command_led()); |
jk1lot | 1:a7e6ebc4cb72 | 123 | * epd.display_internalbuf(); |
jk1lot | 1:a7e6ebc4cb72 | 124 | * @endcode |
jk1lot | 1:a7e6ebc4cb72 | 125 | */ |
jk1lot | 0:4dbc7e226777 | 126 | TextDisplay* text() {return &internalbuf;} |
jk1lot | 1:a7e6ebc4cb72 | 127 | /// set size of pixel |
jk1lot | 1:a7e6ebc4cb72 | 128 | void setfontscale(uint8_t x=1, uint8_t y=1) {internalbuf.setfontscale(x,y);} |
jk1lot | 1:a7e6ebc4cb72 | 129 | /// set pixel at internal buffer |
jk1lot | 1:a7e6ebc4cb72 | 130 | void pset(int x, int y, bool b=true) {internalbuf.pixel1x1(x,y,b);} |
jk1lot | 1:a7e6ebc4cb72 | 131 | /// clear internal buffer |
jk1lot | 1:a7e6ebc4cb72 | 132 | void clear_internalbuf() { internalbuf.cls(); } |
jk1lot | 1:a7e6ebc4cb72 | 133 | /// send internal buffer to Y-con P020 |
jk1lot | 0:4dbc7e226777 | 134 | void display_internalbuf(); |
jk1lot | 1:a7e6ebc4cb72 | 135 | /// width of Y-con P020 (==200) |
jk1lot | 1:a7e6ebc4cb72 | 136 | int width() const { return YconP020GBuf::MAX_X; } |
jk1lot | 1:a7e6ebc4cb72 | 137 | /// height of Y-con P020 (==96) |
jk1lot | 1:a7e6ebc4cb72 | 138 | int height() const { return YconP020GBuf::MAX_Y; } |
jk1lot | 0:4dbc7e226777 | 139 | protected: |
jk1lot | 0:4dbc7e226777 | 140 | void uartint(); |
jk1lot | 0:4dbc7e226777 | 141 | void push_recbuf(char c); |
jk1lot | 0:4dbc7e226777 | 142 | void push_recbuf(const string& s); |
jk1lot | 0:4dbc7e226777 | 143 | |
jk1lot | 0:4dbc7e226777 | 144 | error_t sendfile(const string& filename); |
jk1lot | 0:4dbc7e226777 | 145 | |
jk1lot | 0:4dbc7e226777 | 146 | //for command line intercept |
jk1lot | 1:a7e6ebc4cb72 | 147 | string localcomline; |
jk1lot | 1:a7e6ebc4cb72 | 148 | virtual int putc_intercept(int c); |
jk1lot | 0:4dbc7e226777 | 149 | |
jk1lot | 1:a7e6ebc4cb72 | 150 | //sub-functions for functions of Y-con P020 command |
jk1lot | 1:a7e6ebc4cb72 | 151 | void send_command(const string& command, bool waitready=true); |
jk1lot | 0:4dbc7e226777 | 152 | void void_command(const string& command, bool waitready=true); |
jk1lot | 1:a7e6ebc4cb72 | 153 | void set_param(const string& command, int param); |
jk1lot | 1:a7e6ebc4cb72 | 154 | //void set_param(const string& command, bool param); //int版で代用できるので要らない |
jk1lot | 0:4dbc7e226777 | 155 | int get_intparam(const string& command, const string& retstr); |
jk1lot | 0:4dbc7e226777 | 156 | bool get_boolparam(const string& command); |
jk1lot | 0:4dbc7e226777 | 157 | string get_stringparam(const string& command); |
jk1lot | 0:4dbc7e226777 | 158 | |
jk1lot | 0:4dbc7e226777 | 159 | private: |
jk1lot | 0:4dbc7e226777 | 160 | Serial uart; |
jk1lot | 0:4dbc7e226777 | 161 | volatile char lastchar; |
jk1lot | 0:4dbc7e226777 | 162 | queue<char> recoutbuf; |
jk1lot | 0:4dbc7e226777 | 163 | string recinbuf; |
jk1lot | 0:4dbc7e226777 | 164 | bool use_recinbuf; |
jk1lot | 0:4dbc7e226777 | 165 | vector<string> filelist; |
jk1lot | 0:4dbc7e226777 | 166 | YconP020GBuf internalbuf; |
jk1lot | 0:4dbc7e226777 | 167 | |
jk1lot | 0:4dbc7e226777 | 168 | virtual int _getc(); |
jk1lot | 0:4dbc7e226777 | 169 | virtual int _putc(int c); |
jk1lot | 0:4dbc7e226777 | 170 | }; |
jk1lot | 0:4dbc7e226777 | 171 | |
jk1lot | 0:4dbc7e226777 | 172 | #endif |