DisplayApp-Base

Dependencies:   mbed-os-lychee DisplayApp_Base

Files at this revision

API Documentation at this revision

Comitter:
yagyag
Date:
Fri Nov 09 04:32:15 2018 +0000
Parent:
1:0756c0a63a4b
Child:
3:6289f0adb6c9
Commit message:
DsiplayApp??

Changed in this revision

DisplayApp.lib Show annotated file Show diff for this revision Revisions of this file
main.cpp Show annotated file Show diff for this revision Revisions of this file
--- a/DisplayApp.lib	Fri Feb 02 05:59:59 2018 +0000
+++ b/DisplayApp.lib	Fri Nov 09 04:32:15 2018 +0000
@@ -1,1 +1,1 @@
-https://os.mbed.com/users/dkato/code/DisplayApp/#3c46efbe6d21
+https://os.mbed.com/users/yagyag/code/DisplayApp/#3bb202b0ce01
--- a/main.cpp	Fri Feb 02 05:59:59 2018 +0000
+++ b/main.cpp	Fri Nov 09 04:32:15 2018 +0000
@@ -3,11 +3,12 @@
 #include "JPEG_Converter.h"
 #include "dcache-control.h"
 #include "DisplayApp.h"
+#include "FATFileSystem.h"
 
 /**** User Selection *********/
 /** JPEG out setting **/
-#define JPEG_ENCODE_QUALITY    (75)    /* JPEG encode quality (min:1, max:75 (Considering the size of JpegBuffer, about 75 is the upper limit.)) */
-#define VFIELD_INT_SKIP_CNT    (0)     /* A guide for GR-LYCHEE.  0:60fps, 1:30fps, 2:20fps, 3:15fps, 4:12fps, 5:10fps */
+#define JPEG_ENCODE_QUALITY    (55)    /* JPEG encode quality (min:1, max:75 (Considering the size of JpegBuffer, about 75 is the upper limit.)) */
+#define VFIELD_INT_SKIP_CNT    (1)     /* A guide for GR-LYCHEE.  0:60fps, 1:30fps, 2:20fps, 3:15fps, 4:12fps, 5:10fps */
 /*****************************/
 
 /*! Frame buffer stride: Frame buffer stride should be set to a multiple of 32 or 128
@@ -25,9 +26,11 @@
 static uint8_t user_frame_buffer0[FRAME_BUFFER_STRIDE * FRAME_BUFFER_HEIGHT]@ ".mirrorram";
 #pragma data_alignment=32
 static uint8_t JpegBuffer[2][1024 * 64];
+static uint8_t JpegBuffer_Send[1024 * 64];
 #else
 static uint8_t user_frame_buffer0[FRAME_BUFFER_STRIDE * FRAME_BUFFER_HEIGHT]__attribute((section("NC_BSS"),aligned(32)));
 static uint8_t JpegBuffer[2][1024 * 64]__attribute((aligned(32)));
+static uint8_t JpegBuffer_Send[1024 * 64]__attribute((aligned(32)));
 #endif
 static size_t jcu_encode_size[2];
 static JPEG_Converter Jcu;
@@ -39,7 +42,21 @@
 static DisplayApp  display_app;
 static int Vfield_Int_Cnt = 0;
 
-static void JcuEncodeCallBackFunc(JPEG_Converter::jpeg_conv_error_t err_code) {
+Ticker flipper;
+static int interCnt = 0;    //割り込み発生回数
+static int sendCnt = 0;     //画像データを送信した回数
+DigitalOut led1(LED1);
+DigitalOut led2(LED2);
+FATFileSystem Lf("storage");
+
+
+static void incrementInterCnt()
+{
+    interCnt++;
+}
+
+static void JcuEncodeCallBackFunc(JPEG_Converter::jpeg_conv_error_t err_code)
+{
     if (err_code == JPEG_Converter::JPEG_CONV_OK) {
         jcu_buf_index_write_done = jcu_buf_index_write;
         image_change = 1;
@@ -47,16 +64,29 @@
     jcu_encoding = 0;
 }
 
-static void snapshot(void) {
+static void snapshot(void)
+{
+    //JPEGにエンコード中 or エンコード未完了
     while ((jcu_encoding == 1) || (image_change == 0)) {
         Thread::wait(1);
     }
     jcu_buf_index_read = jcu_buf_index_write_done;
+    //画像データをコピー(JpegBufferは他から書き換えられる可能性があるため)
+    memcpy(JpegBuffer_Send, JpegBuffer[jcu_buf_index_read],1024 * 64);
     image_change = 0;
-    display_app.SendJpeg(JpegBuffer[jcu_buf_index_read], (int)jcu_encode_size[jcu_buf_index_read]);
+
+    if(interCnt != sendCnt) {
+        led2 = !led2;
+        sendCnt = interCnt;
+        //撮影した画像データ(JPEG)をPCにUSBシリアル通信で転送
+        display_app.SendJpeg(JpegBuffer_Send, (uint32_t)jcu_encode_size[jcu_buf_index_read]);
+        //display_app.SendJpeg(JpegBuffer[jcu_buf_index_read], (int)jcu_encode_size[jcu_buf_index_read]);
+        led2 = !led2;
+    }
 }
 
-static void IntCallbackFunc_Vfield(DisplayBase::int_type_t int_type) {
+static void IntCallbackFunc_Vfield(DisplayBase::int_type_t int_type)
+{
     if (Vfield_Int_Cnt < VFIELD_INT_SKIP_CNT) {
         Vfield_Int_Cnt++;
         return;
@@ -84,14 +114,15 @@
         jcu_encode_size[jcu_buf_index_write] = 0;
         dcache_invalid(JpegBuffer[jcu_buf_index_write], sizeof(JpegBuffer[0]));
         if (Jcu.encode(&bitmap_buff_info, JpegBuffer[jcu_buf_index_write],
-            &jcu_encode_size[jcu_buf_index_write], &encode_options) != JPEG_Converter::JPEG_CONV_OK) {
+                       &jcu_encode_size[jcu_buf_index_write], &encode_options) != JPEG_Converter::JPEG_CONV_OK) {
             jcu_encode_size[jcu_buf_index_write] = 0;
             jcu_encoding = 0;
         }
     }
 }
 
-static void Start_Video_Camera(void) {
+static void Start_Video_Camera(void)
+{
     // Initialize the background to black
     for (uint32_t i = 0; i < sizeof(user_frame_buffer0); i += 2) {
         user_frame_buffer0[i + 0] = 0x10;
@@ -115,11 +146,18 @@
     EasyAttach_CameraStart(Display, DisplayBase::VIDEO_INPUT_CHANNEL_0);
 }
 
-int main(void) {
+int main(void)
+{
+    led1 = !led1;
+    //JPEGのエンコード設定
     Jcu.SetQuality(JPEG_ENCODE_QUALITY);
 
+    //カメラの初期化処理
     EasyAttach_Init(Display);
+    //カメラ画像 取得開始
     Start_Video_Camera();
+    //割り込み処理※デバッグの為、5秒
+    flipper.attach(&incrementInterCnt, 5.0);
 
     while (1) {
         snapshot();