テスト

Dependencies:   mbed-os-lychee DisplayApp

Revision:
0:d6604ad6185b
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/main.cpp	Tue Dec 04 00:32:52 2018 +0000
@@ -0,0 +1,285 @@
+
+#include "mbed.h"
+#include "DisplayApp.h"
+#include "EasyAttach_CameraAndLCD.h"
+#include "JPEG_Converter.h"
+#include "dcache-control.h"
+#include "DisplayApp.h"
+#include "FATFileSystem.h"
+
+DigitalOut led1(LED1);
+DigitalOut led2(LED2);
+DigitalOut led3(LED3);
+DigitalOut led4(LED4);
+
+void DisplayApp::display_app_process() {
+    int data;
+    int pos_x_wk;
+    int pos_wk;
+    int flag;
+    
+    int blink_on = 0;
+    int blink_flag = 0;
+    
+    while (!PcApp.configured()) {
+        Thread::wait(100);
+    }
+
+    while (1) {
+        
+        /*受信処理/**/
+        if (PcApp.readable()) {
+            data = PcApp.getc();
+            if (data == '4' or data == '5') {                
+                flag = 1;   //走行処理
+                blink_on = 1;
+             
+             /*   
+            } else if (data == '1') {
+                flag = 3;   //撮影処理
+                                
+            } else if (data == '3') {
+                flag = 4;   //音声出力処理
+                               
+            } else if (data == '2') {
+                flag = 5;   //ライト点灯処理                
+            }
+            */
+            
+        /*走行処理*/
+            if(data == '4'){
+                    led1 = !led1;
+            }else if (data == '5'){
+                    blink_flag = 1;
+                if(blink_on == 1 and blink_flag == 1){
+                    led2 = !led2;
+                }
+                wait(0.3);
+        }
+            
+                
+                
+#if 0            
+        } else if (pos_seq == POS_SEQ_Y) {
+            pos_seq = POS_SEQ_Y_POS;
+            pos_wk = 0;
+        } else {
+            pos_seq = POS_SEQ_INIT;
+        }
+    } 
+    
+    else if (data == '-') {
+        if (pos_seq == POS_SEQ_X_POS) {
+            pos_seq = POS_SEQ_X_M;
+        } else if (pos_seq == POS_SEQ_Y_POS) {
+            pos_seq = POS_SEQ_Y_M;
+        } else {
+            pos_seq = POS_SEQ_INIT;
+        }
+            } else if ((data >= '0') && (data <= '9')) {
+                if ((pos_seq == POS_SEQ_X_POS) || (pos_seq == POS_SEQ_Y_POS)) {
+                    pos_wk = (pos_wk * 10) + (data - '0');
+                } else if ((pos_seq == POS_SEQ_X_M) && (data == '1')) {
+                    pos_wk = -1;
+                } else if ((pos_seq == POS_SEQ_Y_M) && (data == '1')) {
+                    pos_wk = -1;
+                } else {
+                    pos_seq = POS_SEQ_INIT;
+                }
+            } else if (data == ',') {
+                if ((pos_seq == POS_SEQ_X_POS) || (pos_seq == POS_SEQ_X_M)) {
+                    pos_x_wk = pos_wk;
+                    pos_seq = POS_SEQ_C;
+                } else {
+                    pos_seq = POS_SEQ_INIT;
+                }
+            } else if (data == '}') {
+                if ((pos_seq == POS_SEQ_Y_POS) || (pos_seq == POS_SEQ_Y_M)) {
+                    pos_seq = POS_SEQ_END;
+                    if ((pos_x != pos_x_wk) || (pos_y != pos_wk)) {
+                        pos_x = pos_x_wk;
+                        pos_y = pos_wk;
+                        if (event) {
+                            event.call();
+                        }
+                    }
+                } else {
+                    pos_seq = POS_SEQ_INIT;
+                }
+            } else {
+                pos_seq = POS_SEQ_INIT;
+            }
+        } else {
+            Thread::wait(10);
+        }
+    }
+#endif
+}
+
+void DisplayApp::DisplayApp(osPriority tsk_pri, uint32_t stack_size) : 
+  PcApp(0x1f00, 0x2012, 0x0001, false), displayThread(tsk_pri, stack_size) {
+    displayThread.start(callback(this, &DisplayApp::display_app_process));
+}
+
+void DisplayApp::SendHeader(uint32_t size) {
+    uint8_t headder_data[12] = {0xFF,0xFF,0xAA,0x55,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00};
+
+    headder_data[8]  = (uint8_t)((uint32_t)size >> 0);
+    headder_data[9]  = (uint8_t)((uint32_t)size >> 8);
+    headder_data[10] = (uint8_t)((uint32_t)size >> 16);
+    headder_data[11] = (uint8_t)((uint32_t)size >> 24);
+    PcApp.writeBlock((uint8_t *)headder_data, sizeof(headder_data));
+}
+
+void DisplayApp::SendData(uint8_t * buf, uint32_t size) {
+    int send_size;
+    int send_index = 0;
+
+    while (size > 0) {
+        if (size > MAX_PACKET_SIZE_EPBULK) {
+            send_size = MAX_PACKET_SIZE_EPBULK;
+        } else {
+            send_size = size;
+        }
+        PcApp.writeBlock(&buf[send_index], send_size);
+        send_index += send_size;
+        size -= send_size;
+    }
+}
+
+int DisplayApp::SendRgb888(uint8_t * buf, uint32_t pic_width, uint32_t pic_height) {
+    uint32_t offset_size = 54;
+    uint32_t buf_stride = (((pic_width * 4u) + 31u) & ~31u);
+    uint32_t pic_size = buf_stride * pic_height;
+    uint32_t total_size = pic_size + offset_size;
+    uint8_t wk_bitmap_buf[54];
+    int wk_idx = 0;
+
+    if (!PcApp.configured()) {
+        return 0;
+    }
+    if (PcApp._putc(0) == 0) {  // terminal connect check
+        return 0;
+    }
+    SendHeader(total_size);
+
+    /* BITMAPFILEHEADER */
+    wk_bitmap_buf[wk_idx++] = 'B';
+    wk_bitmap_buf[wk_idx++] = 'M';
+    wk_bitmap_buf[wk_idx++] = (uint8_t)(total_size >> 0);   /* bfSize */
+    wk_bitmap_buf[wk_idx++] = (uint8_t)(total_size >> 8);   /* bfSize */
+    wk_bitmap_buf[wk_idx++] = (uint8_t)(total_size >> 16);  /* bfSize */
+    wk_bitmap_buf[wk_idx++] = (uint8_t)(total_size >> 24);  /* bfSize */
+    wk_bitmap_buf[wk_idx++] = 0;  /* bfReserved1 */
+    wk_bitmap_buf[wk_idx++] = 0;  /* bfReserved1 */
+    wk_bitmap_buf[wk_idx++] = 0;  /* bfReserved2 */
+    wk_bitmap_buf[wk_idx++] = 0;  /* bfReserved2 */
+    wk_bitmap_buf[wk_idx++] = (uint8_t)(offset_size >> 0);   /* bfOffBits */
+    wk_bitmap_buf[wk_idx++] = (uint8_t)(offset_size >> 8);   /* bfOffBits */
+    wk_bitmap_buf[wk_idx++] = (uint8_t)(offset_size >> 16);  /* bfOffBits */
+    wk_bitmap_buf[wk_idx++] = (uint8_t)(offset_size >> 24);  /* bfOffBits */
+
+    /* BITMAPINFOHEADER */
+    wk_bitmap_buf[wk_idx++] = 40; /* biSize */
+    wk_bitmap_buf[wk_idx++] = 0;  /* biSize */
+    wk_bitmap_buf[wk_idx++] = 0;  /* biSize */
+    wk_bitmap_buf[wk_idx++] = 0;  /* biSize */
+    wk_bitmap_buf[wk_idx++] = (uint8_t)(pic_width >> 0);    /* biWidth */
+    wk_bitmap_buf[wk_idx++] = (uint8_t)(pic_width >> 8);    /* biWidth */
+    wk_bitmap_buf[wk_idx++] = (uint8_t)(pic_width >> 16);   /* biWidth */
+    wk_bitmap_buf[wk_idx++] = (uint8_t)(pic_width >> 24);   /* biWidth */
+    wk_bitmap_buf[wk_idx++] = (uint8_t)((-(long)pic_height) >> 0);   /* biHeight */
+    wk_bitmap_buf[wk_idx++] = (uint8_t)((-(long)pic_height) >> 8);   /* biHeight */
+    wk_bitmap_buf[wk_idx++] = (uint8_t)((-(long)pic_height) >> 16);  /* biHeight */
+    wk_bitmap_buf[wk_idx++] = (uint8_t)((-(long)pic_height) >> 24);  /* biHeight */
+    wk_bitmap_buf[wk_idx++] = 1;  /* biPlanes */
+    wk_bitmap_buf[wk_idx++] = 0;  /* biPlanes */
+    wk_bitmap_buf[wk_idx++] = 32; /* biBitCount */
+    wk_bitmap_buf[wk_idx++] = 0;  /* biBitCount */
+
+    wk_bitmap_buf[wk_idx++] = 0;  /* biCopmression */
+    wk_bitmap_buf[wk_idx++] = 0;  /* biCopmression */
+    wk_bitmap_buf[wk_idx++] = 0;  /* biCopmression */
+    wk_bitmap_buf[wk_idx++] = 0;  /* biCopmression */
+    wk_bitmap_buf[wk_idx++] = (uint8_t)(pic_size >> 0);   /* biSizeImage */
+    wk_bitmap_buf[wk_idx++] = (uint8_t)(pic_size >> 8);   /* biSizeImage */
+    wk_bitmap_buf[wk_idx++] = (uint8_t)(pic_size >> 16);  /* biSizeImage */
+    wk_bitmap_buf[wk_idx++] = (uint8_t)(pic_size >> 24);  /* biSizeImage */
+    wk_bitmap_buf[wk_idx++] = 0;  /* biXPixPerMeter */
+    wk_bitmap_buf[wk_idx++] = 0;  /* biXPixPerMeter */
+    wk_bitmap_buf[wk_idx++] = 0;  /* biXPixPerMeter */
+    wk_bitmap_buf[wk_idx++] = 0;  /* biXPixPerMeter */
+    wk_bitmap_buf[wk_idx++] = 0;  /* biYPixPerMeter */
+    wk_bitmap_buf[wk_idx++] = 0;  /* biYPixPerMeter */
+    wk_bitmap_buf[wk_idx++] = 0;  /* biYPixPerMeter */
+    wk_bitmap_buf[wk_idx++] = 0;  /* biYPixPerMeter */
+
+    wk_bitmap_buf[wk_idx++] = 0;  /* biClrUsed */
+    wk_bitmap_buf[wk_idx++] = 0;  /* biClrUsed */
+    wk_bitmap_buf[wk_idx++] = 0;  /* biClrUsed */
+    wk_bitmap_buf[wk_idx++] = 0;  /* biClrUsed */
+    wk_bitmap_buf[wk_idx++] = 0;  /* biCirImportant */
+    wk_bitmap_buf[wk_idx++] = 0;  /* biCirImportant */
+    wk_bitmap_buf[wk_idx++] = 0;  /* biCirImportant */
+    wk_bitmap_buf[wk_idx++] = 0;  /* biCirImportant */
+    PcApp.writeBlock(wk_bitmap_buf, wk_idx);
+
+    SendData(buf, pic_size);
+    wk_idx += pic_size;
+
+    return wk_idx;
+};
+
+void DisplayApp::SetCallback(Callback<void()> func) {
+    event = func;
+}
+
+int DisplayApp::SendJpeg(uint8_t * buf, uint32_t size) {
+    if (!PcApp.configured()) {
+        return 0;
+    }
+    if (PcApp._putc(0) == 0) {  // terminal connect check
+        return 0;
+    }
+    
+    SendHeader(size);
+    SendData(buf, size);
+
+    return size;
+}
+
+int DisplayApp::GetMaxTouchNum(void) {
+    return 1;
+}
+
+int DisplayApp::GetCoordinates(int touch_buff_num, touch_pos_t * p_touch) {
+    touch_pos_t * wk_touch;
+    int count = 0;
+    int x = pos_x;
+    int y = pos_y;
+
+    if (touch_buff_num > 0) {
+        count = 0;
+        wk_touch        = &p_touch[0];
+        wk_touch->valid = false;
+        wk_touch->x     = 0;
+        wk_touch->y     = 0;
+        if (x >= 0) {
+            count = 1;
+            wk_touch->valid = true;
+            wk_touch->x = (uint32_t)x;
+        }
+        if (y >= 0) {
+            count = 1;
+            wk_touch->valid = true;
+            wk_touch->y = (uint32_t)y;
+        }
+    }
+
+    return count;
+}
+
+char DisplayApp::Getgetc()
+{
+    return PcApp.getc();
+}