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
- Committer:
- jk1lot
- Date:
- 2016-07-01
- Revision:
- 0:4dbc7e226777
- Child:
- 1:a7e6ebc4cb72
File content as of revision 0:4dbc7e226777:
#ifndef YCONP020_H #define YCONP020_H #include "Stream.h" #include "Serial.h" using namespace mbed; #include <string> #include <vector> #include <queue> using namespace std; #include "GraphicsDisplay.h" 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; } 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; }; 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; YconP020(PinName tx, PinName rx); /// Similar to Serial::readable() bool readable() {return !recoutbuf.empty();} /// check ready to send command bool command_ready() const { return lastchar=='!'; } /// wait for ready to send command /// @return false timeout bool wait_command_ready(int ms=10000); /// change to command mode from normal(send file) mode /// @return flase timeout 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 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 /// 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); /// return previous file list const vector<string>& getfilelist() const {return filelist;} /// get all file list const vector<string>& getfilelistall(); /// display file error_t dispfile(const string& filename); 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(); } void display_internalbuf(); protected: void uartint(); void push_recbuf(char c); void push_recbuf(const string& s); 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); //sub-functions for execute commands void void_command(const string& command, bool waitready=true); void set_intparam(const string& command, int param); int get_intparam(const string& command, const string& retstr); bool get_boolparam(const string& command); string get_stringparam(const string& command); private: Serial uart; volatile char lastchar; queue<char> recoutbuf; string recinbuf; bool use_recinbuf; vector<string> filelist; string localcomline; YconP020GBuf internalbuf; virtual int _getc(); virtual int _putc(int c); }; #endif