Kerry Martin
/
Liz_Test_Code
KSM edits
main.cpp@19:fee3f71fab2d, 2019-07-10 (annotated)
- Committer:
- lizard753
- Date:
- Wed Jul 10 13:30:27 2019 +0000
- Revision:
- 19:fee3f71fab2d
- Parent:
- 18:307303d9c8f6
- Child:
- 20:d25fb9c55781
Adding button library and main code for button
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
WiredHome | 16:231837aa2c37 | 1 | // |
WiredHome | 16:231837aa2c37 | 2 | // Demo Program |
WiredHome | 17:c8ef96a6e43b | 3 | // mbed version Graphics Working PrintScreen Working? "/local/file.bmp" |
WiredHome | 17:c8ef96a6e43b | 4 | // v148 Yes No, FILE *Image = fopen(Name_BMP, "wb"); fails |
WiredHome | 17:c8ef96a6e43b | 5 | // v142 Yes No, FILE *Image = fopen(Name_BMP, "wb"); fails |
WiredHome | 17:c8ef96a6e43b | 6 | // v140 Yes No, FILE *Image = fopen(Name_BMP, "wb"); fails |
WiredHome | 17:c8ef96a6e43b | 7 | // v138 Yes No, FILE *Image = fopen(Name_BMP, "wb"); fails |
WiredHome | 17:c8ef96a6e43b | 8 | // v137 Yes Yes |
WiredHome | 17:c8ef96a6e43b | 9 | // v136 Yes Yes |
WiredHome | 17:c8ef96a6e43b | 10 | // v128 Yes Yes |
WiredHome | 17:c8ef96a6e43b | 11 | // |
WiredHome | 17:c8ef96a6e43b | 12 | #include "mbed.h" // testing: v147 - working: v146, v145, v142, v136, v128, fails: v148 |
WiredHome | 17:c8ef96a6e43b | 13 | #include "RA8875.h" // v138 - tested working |
WiredHome | 5:bb970d40cd7d | 14 | #include "MyFont18x32.h" |
WiredHome | 5:bb970d40cd7d | 15 | #include "BPG_Arial08x08.h" |
WiredHome | 5:bb970d40cd7d | 16 | #include "BPG_Arial10x10.h" |
WiredHome | 5:bb970d40cd7d | 17 | #include "BPG_Arial20x20.h" |
WiredHome | 5:bb970d40cd7d | 18 | #include "BPG_Arial31x32.h" |
WiredHome | 5:bb970d40cd7d | 19 | #include "BPG_Arial63x63.h" |
lizard753 | 19:fee3f71fab2d | 20 | #include "Button.h" |
WiredHome | 0:037b95a5cc85 | 21 | |
WiredHome | 15:ab07c064c952 | 22 | // These two defines can be enabled, or commented out |
lizard753 | 19:fee3f71fab2d | 23 | //#define BIG_SCREEN |
WiredHome | 18:307303d9c8f6 | 24 | //#define CAP_TOUCH |
WiredHome | 15:ab07c064c952 | 25 | #define LCD_C 16 // color - bits per pixel |
lizard753 | 19:fee3f71fab2d | 26 | // Needed for Resistive Touch |
lizard753 | 19:fee3f71fab2d | 27 | void CalibrateTS(void); |
WiredHome | 15:ab07c064c952 | 28 | |
WiredHome | 15:ab07c064c952 | 29 | #ifdef CAP_TOUCH |
WiredHome | 15:ab07c064c952 | 30 | RA8875 lcd(p5, p6, p7, p12, NC, p9,p10,p13, "tft"); // MOSI,MISO,SCK,/ChipSelect,/reset, SDA,SCL,/IRQ, name |
WiredHome | 15:ab07c064c952 | 31 | #else |
WiredHome | 15:ab07c064c952 | 32 | RA8875 lcd(p5, p6, p7, p12, NC, "tft"); //MOSI, MISO, SCK, /ChipSelect, /reset, name |
WiredHome | 16:231837aa2c37 | 33 | #endif |
WiredHome | 17:c8ef96a6e43b | 34 | LocalFileSystem local("local"); // access to calibration file for resistive touch and printscreen |
WiredHome | 15:ab07c064c952 | 35 | |
WiredHome | 15:ab07c064c952 | 36 | #ifdef BIG_SCREEN |
WiredHome | 18:307303d9c8f6 | 37 | #define LCD_W 800 |
WiredHome | 18:307303d9c8f6 | 38 | #define LCD_H 480 |
WiredHome | 15:ab07c064c952 | 39 | #else |
WiredHome | 18:307303d9c8f6 | 40 | #define LCD_W 480 |
WiredHome | 18:307303d9c8f6 | 41 | #define LCD_H 272 |
WiredHome | 15:ab07c064c952 | 42 | #endif |
WiredHome | 15:ab07c064c952 | 43 | |
WiredHome | 5:bb970d40cd7d | 44 | Serial pc(USBTX, USBRX); // And a little feedback |
WiredHome | 13:43cc0a997c53 | 45 | Timer measurement; |
lizard753 | 19:fee3f71fab2d | 46 | Button button_calibration((loc_t)10, (loc_t)10, (loc_t)20, (loc_t)20, (color_t)RGB(255,255,0), &lcd, "CAL"); |
lizard753 | 19:fee3f71fab2d | 47 | Button button_data_rate_select((loc_t)10, (loc_t)10, (loc_t)20, (loc_t)20, (color_t)RGB(255,255,0), &lcd, "250"); |
WiredHome | 0:037b95a5cc85 | 48 | |
WiredHome | 18:307303d9c8f6 | 49 | RetCode_t callback(RA8875::filecmd_t cmd, uint8_t * buffer, uint16_t size) |
WiredHome | 18:307303d9c8f6 | 50 | { |
WiredHome | 18:307303d9c8f6 | 51 | static FILE * fh = NULL; |
WiredHome | 18:307303d9c8f6 | 52 | static unsigned int bytesDone = 0; |
WiredHome | 18:307303d9c8f6 | 53 | static unsigned int totalBytes = 0; |
WiredHome | 18:307303d9c8f6 | 54 | |
WiredHome | 18:307303d9c8f6 | 55 | switch(cmd) { |
WiredHome | 18:307303d9c8f6 | 56 | case RA8875::OPEN: |
WiredHome | 18:307303d9c8f6 | 57 | bytesDone = 0; |
WiredHome | 18:307303d9c8f6 | 58 | totalBytes = *(uint32_t *)buffer; |
WiredHome | 18:307303d9c8f6 | 59 | pc.printf("PrintScreen callback to write %u bytes\r\n", totalBytes); |
WiredHome | 18:307303d9c8f6 | 60 | fh = fopen("/local/file.bmp", "w+b"); |
WiredHome | 18:307303d9c8f6 | 61 | if (!fh) |
WiredHome | 18:307303d9c8f6 | 62 | return(file_not_found); |
WiredHome | 18:307303d9c8f6 | 63 | break; |
WiredHome | 18:307303d9c8f6 | 64 | case RA8875::WRITE: |
WiredHome | 18:307303d9c8f6 | 65 | bytesDone += size; |
WiredHome | 18:307303d9c8f6 | 66 | pc.printf(" Write %d bytes => %d of %d\r\n", size, bytesDone, totalBytes); |
WiredHome | 18:307303d9c8f6 | 67 | fwrite(buffer, 1, size, fh); |
WiredHome | 18:307303d9c8f6 | 68 | pc.printf(" %3d %% complete\r\n", ((100 * bytesDone)/totalBytes)); |
WiredHome | 18:307303d9c8f6 | 69 | break; |
WiredHome | 18:307303d9c8f6 | 70 | case RA8875::CLOSE: |
WiredHome | 18:307303d9c8f6 | 71 | fclose(fh); |
WiredHome | 18:307303d9c8f6 | 72 | pc.printf("PrintScreen Closed.\r\n"); |
WiredHome | 18:307303d9c8f6 | 73 | break; |
WiredHome | 18:307303d9c8f6 | 74 | default: |
WiredHome | 18:307303d9c8f6 | 75 | pc.printf("Unexpected callback %d\r\n", cmd); |
WiredHome | 18:307303d9c8f6 | 76 | break; |
WiredHome | 18:307303d9c8f6 | 77 | } |
WiredHome | 18:307303d9c8f6 | 78 | return noerror; |
WiredHome | 18:307303d9c8f6 | 79 | } |
WiredHome | 18:307303d9c8f6 | 80 | |
WiredHome | 18:307303d9c8f6 | 81 | |
WiredHome | 0:037b95a5cc85 | 82 | int main() |
WiredHome | 0:037b95a5cc85 | 83 | { |
WiredHome | 5:bb970d40cd7d | 84 | pc.baud(460800); // I like a snappy terminal, so crank it up! |
WiredHome | 5:bb970d40cd7d | 85 | pc.printf("\r\nRA8875 Soft Fonts - Build " __DATE__ " " __TIME__ "\r\n"); |
WiredHome | 2:2076d9cc6db9 | 86 | |
WiredHome | 13:43cc0a997c53 | 87 | measurement.start(); |
WiredHome | 18:307303d9c8f6 | 88 | lcd.frequency(500000); |
WiredHome | 18:307303d9c8f6 | 89 | lcd.Reset(); |
WiredHome | 18:307303d9c8f6 | 90 | lcd.init(LCD_W, LCD_H, LCD_C, 40); |
lizard753 | 19:fee3f71fab2d | 91 | lcd.Backlight(.9); |
WiredHome | 6:8e392d0ff74a | 92 | // ************************** |
WiredHome | 9:02c622fa4969 | 93 | //RunTestSet(lcd, pc); // If the library was compiled for test mode... |
WiredHome | 18:307303d9c8f6 | 94 | |
WiredHome | 9:02c622fa4969 | 95 | lcd.foreground(RGB(255,255,0)); |
WiredHome | 18:307303d9c8f6 | 96 | lcd.puts(0,100, "RA8875 Soft Fonts - Build " __DATE__ " " __TIME__ "\r\n"); |
WiredHome | 0:037b95a5cc85 | 97 | |
WiredHome | 5:bb970d40cd7d | 98 | lcd.SelectUserFont(Dave_Smart18x32); |
WiredHome | 5:bb970d40cd7d | 99 | lcd.puts("**** ! Soft Fonts ! **** 0123456789\r\n"); |
WiredHome | 5:bb970d40cd7d | 100 | lcd.puts("ABCDEFGHIJKLMNOPQRSTUVWXYZ\r\n"); |
WiredHome | 9:02c622fa4969 | 101 | //lcd.puts("abcdefghijklmnopqrstuvwxyz\r\n"); |
WiredHome | 5:bb970d40cd7d | 102 | lcd.SelectUserFont(); |
WiredHome | 5:bb970d40cd7d | 103 | lcd.puts("Back to normal\r\n"); |
WiredHome | 5:bb970d40cd7d | 104 | lcd.SelectUserFont(BPG_Arial08x08); |
WiredHome | 5:bb970d40cd7d | 105 | lcd.puts("BPG_Arial08x08 ABCDEFGHIJKLMNOPQRSTUVWXYZ\r\n"); |
WiredHome | 18:307303d9c8f6 | 106 | //lcd.puts("BPG_Arial08x08 abcdefghijklmnopqrstuvwxyz\r\n"); |
WiredHome | 5:bb970d40cd7d | 107 | lcd.SelectUserFont(BPG_Arial10x10); |
WiredHome | 5:bb970d40cd7d | 108 | lcd.puts("BPG_Arial10x10 ABCDEFGHIJKLMNOPQRSTUVWXYZ\r\n"); |
WiredHome | 9:02c622fa4969 | 109 | //lcd.puts("BPG_Arial10x10 abcdefghijklmnopqrstuvwxyz\r\n"); |
WiredHome | 5:bb970d40cd7d | 110 | lcd.SelectUserFont(BPG_Arial20x20); |
WiredHome | 9:02c622fa4969 | 111 | lcd.puts("BPG_Arial20x20 "); |
WiredHome | 5:bb970d40cd7d | 112 | lcd.SelectUserFont(BPG_Arial31x32); |
WiredHome | 9:02c622fa4969 | 113 | lcd.puts("BPG_Arial31x32\r\n"); |
WiredHome | 5:bb970d40cd7d | 114 | lcd.SelectUserFont(BPG_Arial63x63); |
WiredHome | 9:02c622fa4969 | 115 | lcd.puts("BPG_Arial63x63"); |
WiredHome | 13:43cc0a997c53 | 116 | pc.printf("Time trial completed in %d uSec\r\n", measurement.read_us()); |
WiredHome | 5:bb970d40cd7d | 117 | |
WiredHome | 18:307303d9c8f6 | 118 | lcd.rect(0,0, 10,10, BrightRed); |
WiredHome | 18:307303d9c8f6 | 119 | |
WiredHome | 9:02c622fa4969 | 120 | pc.printf("PrintScreen activated ...\r\n"); |
WiredHome | 18:307303d9c8f6 | 121 | RetCode_t r = lcd.PrintScreen(0,0,LCD_W,LCD_H,"/local/file.bmp", 8); |
WiredHome | 18:307303d9c8f6 | 122 | pc.printf(" PrintScreen returned %d - %s\r\n", r, lcd.GetErrorMessage(r)); |
WiredHome | 18:307303d9c8f6 | 123 | |
WiredHome | 18:307303d9c8f6 | 124 | //lcd.AttachPrintHandler(callback); |
WiredHome | 18:307303d9c8f6 | 125 | //lcd.PrintScreen(0,0,LCD_W,LCD_H,8); |
lizard753 | 19:fee3f71fab2d | 126 | button_calibration.draw(); |
WiredHome | 18:307303d9c8f6 | 127 | |
lizard753 | 19:fee3f71fab2d | 128 | while(1) |
lizard753 | 19:fee3f71fab2d | 129 | { |
lizard753 | 19:fee3f71fab2d | 130 | TouchCode_t touch; |
lizard753 | 19:fee3f71fab2d | 131 | |
lizard753 | 19:fee3f71fab2d | 132 | touch = lcd.TouchPanelReadable(); |
lizard753 | 19:fee3f71fab2d | 133 | if(touch) |
lizard753 | 19:fee3f71fab2d | 134 | { |
lizard753 | 19:fee3f71fab2d | 135 | for(int i = 0; i < lcd.TouchChannels(); i++) |
lizard753 | 19:fee3f71fab2d | 136 | { |
lizard753 | 19:fee3f71fab2d | 137 | point_t xy = lcd.TouchCoordinates(i); |
lizard753 | 19:fee3f71fab2d | 138 | if(button_calibration.isPressed(xy.x, xy.y)) |
lizard753 | 19:fee3f71fab2d | 139 | { |
lizard753 | 19:fee3f71fab2d | 140 | lcd.rect(0,0, LCD_W,LCD_H, BrightCyan); |
lizard753 | 19:fee3f71fab2d | 141 | }; // end |
lizard753 | 19:fee3f71fab2d | 142 | } |
lizard753 | 19:fee3f71fab2d | 143 | } |
WiredHome | 3:ca6a1026c28e | 144 | } |
lizard753 | 19:fee3f71fab2d | 145 | } |