Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
DisplayApp.cpp
00001 #include "EasyAttach_CameraAndLCD.h" 00002 #include "JPEG_Converter.h" 00003 #include "dcache-control.h" 00004 #include "DisplayApp.h" 00005 #include "FATFileSystem.h" 00006 #include "mbed.h" 00007 #include "DisplayApp.h" 00008 00009 void DisplayApp::display_app_process() { 00010 int data; 00011 int pos_x_wk; 00012 int pos_wk; 00013 00014 while (!PcApp.configured()) { 00015 Thread::wait(100); 00016 } 00017 00018 while (1) { 00019 if (PcApp.readable()) { 00020 data = PcApp.getc(); 00021 if (data == '{') { 00022 pos_seq = POS_SEQ_START; 00023 } else if (data == 'X') { 00024 if (pos_seq == POS_SEQ_START) { 00025 pos_seq = POS_SEQ_X; 00026 } else { 00027 pos_seq = POS_SEQ_INIT; 00028 } 00029 } else if (data == 'Y') { 00030 if (pos_seq == POS_SEQ_C) { 00031 pos_seq = POS_SEQ_Y; 00032 } else { 00033 pos_seq = POS_SEQ_INIT; 00034 } 00035 } else if (data == '=') { 00036 if (pos_seq == POS_SEQ_X) { 00037 pos_seq = POS_SEQ_X_POS; 00038 pos_wk = 0; 00039 } else if (pos_seq == POS_SEQ_Y) { 00040 pos_seq = POS_SEQ_Y_POS; 00041 pos_wk = 0; 00042 } else { 00043 pos_seq = POS_SEQ_INIT; 00044 } 00045 } else if (data == '-') { 00046 if (pos_seq == POS_SEQ_X_POS) { 00047 pos_seq = POS_SEQ_X_M; 00048 } else if (pos_seq == POS_SEQ_Y_POS) { 00049 pos_seq = POS_SEQ_Y_M; 00050 } else { 00051 pos_seq = POS_SEQ_INIT; 00052 } 00053 } else if ((data >= '0') && (data <= '9')) { 00054 if ((pos_seq == POS_SEQ_X_POS) || (pos_seq == POS_SEQ_Y_POS)) { 00055 pos_wk = (pos_wk * 10) + (data - '0'); 00056 } else if ((pos_seq == POS_SEQ_X_M) && (data == '1')) { 00057 pos_wk = -1; 00058 } else if ((pos_seq == POS_SEQ_Y_M) && (data == '1')) { 00059 pos_wk = -1; 00060 } else { 00061 pos_seq = POS_SEQ_INIT; 00062 } 00063 } else if (data == ',') { 00064 if ((pos_seq == POS_SEQ_X_POS) || (pos_seq == POS_SEQ_X_M)) { 00065 pos_x_wk = pos_wk; 00066 pos_seq = POS_SEQ_C; 00067 } else { 00068 pos_seq = POS_SEQ_INIT; 00069 } 00070 } else if (data == '}') { 00071 if ((pos_seq == POS_SEQ_Y_POS) || (pos_seq == POS_SEQ_Y_M)) { 00072 pos_seq = POS_SEQ_END; 00073 if ((pos_x != pos_x_wk) || (pos_y != pos_wk)) { 00074 pos_x = pos_x_wk; 00075 pos_y = pos_wk; 00076 if (event) { 00077 event.call(); 00078 } 00079 } 00080 } else { 00081 pos_seq = POS_SEQ_INIT; 00082 } 00083 } else { 00084 pos_seq = POS_SEQ_INIT; 00085 } 00086 } else { 00087 Thread::wait(10); 00088 } 00089 } 00090 } 00091 00092 void DisplayApp::DisplayApp(osPriority tsk_pri, uint32_t stack_size) : 00093 PcApp(0x1f00, 0x2012, 0x0001, false), displayThread(tsk_pri, stack_size) { 00094 displayThread.start(callback(this, &DisplayApp::display_app_process)); 00095 } 00096 00097 void DisplayApp::SendHeader(uint32_t size) { 00098 uint8_t headder_data[12] = {0xFF,0xFF,0xAA,0x55,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00}; 00099 00100 headder_data[8] = (uint8_t)((uint32_t)size >> 0); 00101 headder_data[9] = (uint8_t)((uint32_t)size >> 8); 00102 headder_data[10] = (uint8_t)((uint32_t)size >> 16); 00103 headder_data[11] = (uint8_t)((uint32_t)size >> 24); 00104 PcApp.writeBlock((uint8_t *)headder_data, sizeof(headder_data)); 00105 } 00106 00107 void DisplayApp::SendData(uint8_t * buf, uint32_t size) { 00108 int send_size; 00109 int send_index = 0; 00110 00111 while (size > 0) { 00112 if (size > MAX_PACKET_SIZE_EPBULK) { 00113 send_size = MAX_PACKET_SIZE_EPBULK; 00114 } else { 00115 send_size = size; 00116 } 00117 PcApp.writeBlock(&buf[send_index], send_size); 00118 send_index += send_size; 00119 size -= send_size; 00120 } 00121 } 00122 00123 int DisplayApp::SendRgb888(uint8_t * buf, uint32_t pic_width, uint32_t pic_height) { 00124 uint32_t offset_size = 54; 00125 uint32_t buf_stride = (((pic_width * 4u) + 31u) & ~31u); 00126 uint32_t pic_size = buf_stride * pic_height; 00127 uint32_t total_size = pic_size + offset_size; 00128 uint8_t wk_bitmap_buf[54]; 00129 int wk_idx = 0; 00130 00131 if (!PcApp.configured()) { 00132 return 0; 00133 } 00134 if (PcApp._putc(0) == 0) { // terminal connect check 00135 return 0; 00136 } 00137 SendHeader(total_size); 00138 00139 /* BITMAPFILEHEADER */ 00140 wk_bitmap_buf[wk_idx++] = 'B'; 00141 wk_bitmap_buf[wk_idx++] = 'M'; 00142 wk_bitmap_buf[wk_idx++] = (uint8_t)(total_size >> 0); /* bfSize */ 00143 wk_bitmap_buf[wk_idx++] = (uint8_t)(total_size >> 8); /* bfSize */ 00144 wk_bitmap_buf[wk_idx++] = (uint8_t)(total_size >> 16); /* bfSize */ 00145 wk_bitmap_buf[wk_idx++] = (uint8_t)(total_size >> 24); /* bfSize */ 00146 wk_bitmap_buf[wk_idx++] = 0; /* bfReserved1 */ 00147 wk_bitmap_buf[wk_idx++] = 0; /* bfReserved1 */ 00148 wk_bitmap_buf[wk_idx++] = 0; /* bfReserved2 */ 00149 wk_bitmap_buf[wk_idx++] = 0; /* bfReserved2 */ 00150 wk_bitmap_buf[wk_idx++] = (uint8_t)(offset_size >> 0); /* bfOffBits */ 00151 wk_bitmap_buf[wk_idx++] = (uint8_t)(offset_size >> 8); /* bfOffBits */ 00152 wk_bitmap_buf[wk_idx++] = (uint8_t)(offset_size >> 16); /* bfOffBits */ 00153 wk_bitmap_buf[wk_idx++] = (uint8_t)(offset_size >> 24); /* bfOffBits */ 00154 00155 /* BITMAPINFOHEADER */ 00156 wk_bitmap_buf[wk_idx++] = 40; /* biSize */ 00157 wk_bitmap_buf[wk_idx++] = 0; /* biSize */ 00158 wk_bitmap_buf[wk_idx++] = 0; /* biSize */ 00159 wk_bitmap_buf[wk_idx++] = 0; /* biSize */ 00160 wk_bitmap_buf[wk_idx++] = (uint8_t)(pic_width >> 0); /* biWidth */ 00161 wk_bitmap_buf[wk_idx++] = (uint8_t)(pic_width >> 8); /* biWidth */ 00162 wk_bitmap_buf[wk_idx++] = (uint8_t)(pic_width >> 16); /* biWidth */ 00163 wk_bitmap_buf[wk_idx++] = (uint8_t)(pic_width >> 24); /* biWidth */ 00164 wk_bitmap_buf[wk_idx++] = (uint8_t)((-(long)pic_height) >> 0); /* biHeight */ 00165 wk_bitmap_buf[wk_idx++] = (uint8_t)((-(long)pic_height) >> 8); /* biHeight */ 00166 wk_bitmap_buf[wk_idx++] = (uint8_t)((-(long)pic_height) >> 16); /* biHeight */ 00167 wk_bitmap_buf[wk_idx++] = (uint8_t)((-(long)pic_height) >> 24); /* biHeight */ 00168 wk_bitmap_buf[wk_idx++] = 1; /* biPlanes */ 00169 wk_bitmap_buf[wk_idx++] = 0; /* biPlanes */ 00170 wk_bitmap_buf[wk_idx++] = 32; /* biBitCount */ 00171 wk_bitmap_buf[wk_idx++] = 0; /* biBitCount */ 00172 00173 wk_bitmap_buf[wk_idx++] = 0; /* biCopmression */ 00174 wk_bitmap_buf[wk_idx++] = 0; /* biCopmression */ 00175 wk_bitmap_buf[wk_idx++] = 0; /* biCopmression */ 00176 wk_bitmap_buf[wk_idx++] = 0; /* biCopmression */ 00177 wk_bitmap_buf[wk_idx++] = (uint8_t)(pic_size >> 0); /* biSizeImage */ 00178 wk_bitmap_buf[wk_idx++] = (uint8_t)(pic_size >> 8); /* biSizeImage */ 00179 wk_bitmap_buf[wk_idx++] = (uint8_t)(pic_size >> 16); /* biSizeImage */ 00180 wk_bitmap_buf[wk_idx++] = (uint8_t)(pic_size >> 24); /* biSizeImage */ 00181 wk_bitmap_buf[wk_idx++] = 0; /* biXPixPerMeter */ 00182 wk_bitmap_buf[wk_idx++] = 0; /* biXPixPerMeter */ 00183 wk_bitmap_buf[wk_idx++] = 0; /* biXPixPerMeter */ 00184 wk_bitmap_buf[wk_idx++] = 0; /* biXPixPerMeter */ 00185 wk_bitmap_buf[wk_idx++] = 0; /* biYPixPerMeter */ 00186 wk_bitmap_buf[wk_idx++] = 0; /* biYPixPerMeter */ 00187 wk_bitmap_buf[wk_idx++] = 0; /* biYPixPerMeter */ 00188 wk_bitmap_buf[wk_idx++] = 0; /* biYPixPerMeter */ 00189 00190 wk_bitmap_buf[wk_idx++] = 0; /* biClrUsed */ 00191 wk_bitmap_buf[wk_idx++] = 0; /* biClrUsed */ 00192 wk_bitmap_buf[wk_idx++] = 0; /* biClrUsed */ 00193 wk_bitmap_buf[wk_idx++] = 0; /* biClrUsed */ 00194 wk_bitmap_buf[wk_idx++] = 0; /* biCirImportant */ 00195 wk_bitmap_buf[wk_idx++] = 0; /* biCirImportant */ 00196 wk_bitmap_buf[wk_idx++] = 0; /* biCirImportant */ 00197 wk_bitmap_buf[wk_idx++] = 0; /* biCirImportant */ 00198 PcApp.writeBlock(wk_bitmap_buf, wk_idx); 00199 00200 SendData(buf, pic_size); 00201 wk_idx += pic_size; 00202 00203 return wk_idx; 00204 }; 00205 00206 void DisplayApp::SetCallback(Callback<void()> func) { 00207 event = func; 00208 } 00209 00210 int DisplayApp::SendJpeg(uint8_t * buf, uint32_t size) { 00211 if (!PcApp.configured()) { 00212 return 0; 00213 } 00214 if (PcApp._putc(0) == 0) { // terminal connect check 00215 return 0; 00216 } 00217 00218 SendHeader(size); 00219 SendData(buf, size); 00220 00221 return size; 00222 } 00223 00224 int DisplayApp::GetMaxTouchNum(void) { 00225 return 1; 00226 } 00227 00228 int DisplayApp::GetCoordinates(int touch_buff_num, touch_pos_t * p_touch) { 00229 touch_pos_t * wk_touch; 00230 int count = 0; 00231 int x = pos_x; 00232 int y = pos_y; 00233 00234 if (touch_buff_num > 0) { 00235 count = 0; 00236 wk_touch = &p_touch[0]; 00237 wk_touch->valid = false; 00238 wk_touch->x = 0; 00239 wk_touch->y = 0; 00240 if (x >= 0) { 00241 count = 1; 00242 wk_touch->valid = true; 00243 wk_touch->x = (uint32_t)x; 00244 } 00245 if (y >= 0) { 00246 count = 1; 00247 wk_touch->valid = true; 00248 wk_touch->y = (uint32_t)y; 00249 } 00250 } 00251 00252 return count; 00253 } 00254 00255 char DisplayApp::Getgetc() 00256 { 00257 return PcApp.getc(); 00258 }
Generated on Thu Jul 14 2022 08:20:55 by
1.7.2