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