メインClass導入前

Files at this revision

API Documentation at this revision

Comitter:
YUPPY
Date:
Wed Nov 20 08:04:40 2019 +0000
Parent:
2:c799e2dde99f
Commit message:
class_dounyuumae;

Changed in this revision

JPEGCamera.cpp Show diff for this revision Revisions of this file
JPEGCamera.h Show diff for this revision Revisions of this file
main.cpp Show diff for this revision Revisions of this file
mbed.bld Show diff for this revision Revisions of this file
us015.cpp Show diff for this revision Revisions of this file
us015.h Show diff for this revision Revisions of this file
diff -r c799e2dde99f -r 5f9c4d16acf6 JPEGCamera.cpp
--- a/JPEGCamera.cpp	Sun Nov 17 10:08:05 2019 +0000
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,144 +0,0 @@
-/* Arduino JPEGCamera Library
- * Copyright 2010 SparkFun Electronic
- * Written by Ryan Owens
- * Modified by arms22
- * Ported to mbed by yamaguch
- */
-
-#include "JPEGCamera.h"
-
-#define min(x, y) ((x) < (y)) ? (x) : (y)
-
-const int RESPONSE_TIMEOUT = 500;
-const int DATA_TIMEOUT = 1000;
-
-JPEGCamera::JPEGCamera(PinName tx, PinName rx) : Serial(tx, rx) {
-    printf("AA\r\n");
-    baud(38400);
-    state = READY;
-}
-
-bool JPEGCamera::setPictureSize(JPEGCamera::PictureSize size, bool doReset) {
-    char buf[9] = {0x56, 0x00, 0x31, 0x05, 0x04, 0x01, 0x00, 0x19, (char) size};
-    int ret = sendReceive(buf, sizeof buf, 5);
-
-    if (ret == 5 && buf[0] == 0x76) {
-        if (doReset)
-            reset();
-        return true;
-    } else
-        return false;
-}
-
-bool JPEGCamera::isReady() {
-    return state == READY;
-}
-
-bool JPEGCamera::isProcessing() {
-    return state == PROCESSING;
-}
-
-bool JPEGCamera::takePicture(char *filename) {
-    if (state == READY) {
-        fp = fopen(filename, "wb");
-        if (fp != 0) {
-            if (takePicture()) {
-                imageSize = getImageSize();
-                address = 0;
-                state = PROCESSING;
-            } else {
-                fclose(fp);
-                printf("takePicture(%s) failed", filename);
-                state = ERROR;
-            }
-        } else {
-            printf("fopen() failed");
-            state = ERROR;
-        }
-    }
-    return state != ERROR;
-}
-
-bool JPEGCamera::processPicture() {
-    if (state == PROCESSING) {
-        if (address < imageSize) {
-            char data[1024];
-            int size = readData(data, min(sizeof(data), imageSize - address), address);
-            int ret = fwrite(data, size, 1, fp);
-            if (ret > 0)
-                address += size;
-            if (ret == 0 || address >= imageSize) {
-                stopPictures();
-                fclose(fp);
-                wait(0.1); // ????
-                state = ret > 0 ? READY : ERROR;
-            }
-        }
-    }
-
-    return state == PROCESSING || state == READY;
-}
-
-bool JPEGCamera::reset() {
-    char buf[4] = {0x56, 0x00, 0x26, 0x00};
-    int ret = sendReceive(buf, sizeof buf, 4);
-    if (ret == 4 && buf[0] == 0x76) {
-        wait(4.0);
-        state = READY;
-    } else {
-        state = ERROR;
-    }
-    return state == READY;
-}
-
-bool JPEGCamera::takePicture() {
-    char buf[5] = {0x56, 0x00, 0x36, 0x01, 0x00};
-    int ret = sendReceive(buf, sizeof buf, 5);
-
-    return ret == 5 && buf[0] == 0x76;
-}
-
-bool JPEGCamera::stopPictures() {
-    char buf[5] = {0x56, 0x00, 0x36, 0x01, 0x03};
-    int ret = sendReceive(buf, sizeof buf, 5);
-
-    return ret == 4 && buf[0] == 0x76;
-}
-
-int JPEGCamera::getImageSize() {
-    char buf[9] = {0x56, 0x00, 0x34, 0x01, 0x00};
-    int ret = sendReceive(buf, sizeof buf, 9);
-
-    //The size is in the last 2 characters of the response.
-    return (ret == 9 && buf[0] == 0x76) ? (buf[7] << 8 | buf[8]) : 0;
-}
-
-int JPEGCamera::readData(char *dataBuf, int size, int address) {
-    char buf[16] = {0x56, 0x00, 0x32, 0x0C, 0x00, 0x0A, 0x00, 0x00,
-                    address >> 8, address & 255, 0x00, 0x00, size >> 8, size & 255, 0x00, 0x0A
-                   };
-    int ret = sendReceive(buf, sizeof buf, 5);
-
-    return (ret == 5 && buf[0] == 0x76) ? receive(dataBuf, size, DATA_TIMEOUT) : 0;
-}
-
-int JPEGCamera::sendReceive(char *buf, int sendSize, int receiveSize) {
-    while (readable()) getc();
-
-    for (int i = 0; i < sendSize; i++) putc(buf[i]);
-
-    return receive(buf, receiveSize, RESPONSE_TIMEOUT);
-}
-
-int JPEGCamera::receive(char *buf, int size, int timeout) {
-    timer.start();
-    timer.reset();
-
-    int i = 0;
-    while (i < size && timer.read_ms() < timeout) {
-        if (readable())
-            buf[i++] = getc();
-    }
-
-    return i;
-}
\ No newline at end of file
diff -r c799e2dde99f -r 5f9c4d16acf6 JPEGCamera.h
--- a/JPEGCamera.h	Sun Nov 17 10:08:05 2019 +0000
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,122 +0,0 @@
-
-/* Arduino JPEGCamera Library
- * Copyright 2010 SparkFun Electronics
- * Written by Ryan Owens
- * Modified by arms22
- * Ported to mbed by yamaguch
- */
-
-#ifndef JPEG_CAMERA_H
-#define JPEG_CAMERA_H
-
-#include "mbed.h"
-
-/**
- * Interface for LinkSprite JPEG Camera module LS-Y201
- */
-class JPEGCamera : public Serial {
-public:
-    /***/
-    enum PictureSize {
-        SIZE160x120 = 0x22,
-        SIZE320x240 = 0x11,
-        SIZE640x480 = 0x00,
-    };
-
-    /**
-     * Create JPEG Camera
-     *
-     * @param tx tx pin
-     * @param rx rx pin
-     */
-    JPEGCamera(PinName tx, PinName rx);
-
-    /**
-     * Set picture size
-     *
-     * @param size picture size (available sizes are SIZE160x120, SIZE320x240, SIZE640x480)
-     * @param doReset flag to perform reset operation after changing size
-     *
-     * @returns true if succeeded, false otherwise
-     */
-    bool setPictureSize(JPEGCamera::PictureSize size, bool doReset = true);
-
-    /**
-     * Return whether camera is ready or not
-     *
-     * @returns true if ready, false otherwise
-     */
-    bool isReady();
-
-    /**
-     * Return whether camera is processing the taken picture or not
-     *
-     * @returns true if the camera is in processing, false otherwise
-     */
-    bool isProcessing();
-
-    /**
-     * Take a picture
-     *
-     * @param filename filename to store the picture data
-     * @returns true if succeeded, false otherwise
-     */
-    bool takePicture(char *filename);
-    /**
-     * Process picture (writing the file)
-     *
-     * @returns true if no error in processing, false otherwise
-     */
-    bool processPicture();
-
-    /**
-     * Perform reset oepration (it takes 4 seconds)
-     *
-     * @returns true if succeeded, false otherwise
-     */
-    bool reset();
-
-    /**
-     * Send a picture command to the camera module
-     *
-     *  @returns true if succeeded, false otherwise
-     */
-    bool takePicture(void);
-
-    /**
-     * Send a stop pictures command to the camera module
-     *
-     *  @returns true if succeeded, false otherwise
-     */
-    bool stopPictures(void);
-
-    /**
-     * Get the picture image size
-     *
-     * @returns the actual image size in bytes
-     */
-    int getImageSize();
-
-    /**
-     * Read the picture data to the buffer
-     *
-     * @param dataBuf data buffer address to store the received data
-     * @param size data size to read
-     * @param address the address of the picture data to read
-     *
-     * @returns the size of the data read
-     */
-    int readData(char *dataBuf, int size, int address);
-
-//private:
-    Timer timer;
-    FILE *fp;
-    int imageSize;
-    int address;
-    enum State {UNKNOWN, READY, PROCESSING, ERROR = -1} state;
-    
-    int sendReceive(char *buf, int sendSize, int receiveSize);
-    int receive(char *buf, int size, int timeout);
-};
-
-#endif
diff -r c799e2dde99f -r 5f9c4d16acf6 main.cpp
--- a/main.cpp	Sun Nov 17 10:08:05 2019 +0000
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,75 +0,0 @@
-#include "mbed.h"
-#include "JPEGCamera.h"
-#include "us015.h"
-DigitalOut myled(LED1);
-US015 hs(p12,p11);
-DigitalOut thermo(p20);
-DigitalOut Ultra(p12);
-Serial pc(USBTX,USBRX); // tx, rx
-JPEGCamera camera(p9, p10); // TX, RX
-int main(){
-  int i=1;
-  float th;
-  Timer tm;
-  for(i=0;i<3;i++){
-  pc.printf("start\r\n");
-
-  bool detected=false;
-    thermo=0; //焦電off
-    Ultra=1;//超音波on
-    printf("超音波on 焦電off" )  ;
-    while(1) {
-         hs.TrigerOut();
-         wait(1);
-         int distance;
-         distance = hs.GetDistance();
-         printf("%d\r\n",distance);//距離出力
-        
-        if(distance<2000){//超音波反応
-         Ultra=0;//超音波off
-         thermo=1;//焦電on
-          printf("音波off焦電on  ");
-          if(true)
-             th = thermo;
-             if(th=1 && !detected) {//焦電反応ありの場合
-              i++; 
-               detected=true;
-             pc.printf("human\r\n");
-             tm.reset();
-             tm.start();
-          
-           LocalFileSystem local("local");
-           Timer timer;
-           timer.start();
-           camera.setPictureSize(JPEGCamera::SIZE320x240);
-
-            
-              if (camera.isReady()) {
-               char filename[32];
-               sprintf(filename, "/local/pict%03d.jpg",i);
-               printf("Picture: %s ", filename);
-                if (camera.takePicture(filename)) {
-                 while (camera.isProcessing()) {
-                    camera.processPicture();
-                    printf("take pictuer!");
-                  }
-               } else {
-                 printf("take picture failed\r\n");
-                }
-               } else {
-               printf("camera is not ready\r\n");
-               }
-               
-              printf("time = %f\n", timer.read());
-            }
-          
-          
-          
-        }else{//焦電反応なしの場合
-             detected=false;
-             }           
-}
- 
-  }
-  }
-   
\ No newline at end of file
diff -r c799e2dde99f -r 5f9c4d16acf6 mbed.bld
--- a/mbed.bld	Sun Nov 17 10:08:05 2019 +0000
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,1 +0,0 @@
-https://os.mbed.com/users/mbed_official/code/mbed/builds/65be27845400
\ No newline at end of file
diff -r c799e2dde99f -r 5f9c4d16acf6 us015.cpp
--- a/us015.cpp	Sun Nov 17 10:08:05 2019 +0000
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,75 +0,0 @@
-//**************************************************
-//
-// us015.cpp
-// 概要:超音波距離センサ US-015
-//
-//**************************************************
-#include "mbed.h"
-#include "us015.h"
-
-
-
-//*********************************
-// コンストラクタ
-//*********************************
-US015::US015(PinName trg, PinName ech)
-    :_trigerOut(trg),_interruptEcho(ech)
-{
-    // タイマーの開始
-    timer.start();
-    // トリガー信号の定期出力を行う
-    //tk.attach_us(this,&US015::TrigerOut,US015_PERIODIC_TRIGER);
-    // エコーバック信号の立ち上がり・立ち下がり処置の割り込み
-    _interruptEcho.fall(this,&US015::EchoFall);
-    _interruptEcho.rise(this,&US015::EchoRise);
-}
-// End of Constructor
-
-
-//*********************************
-//  トリガー信号を出力する
-//*********************************
-void US015::TrigerOut()
-{
-    // トリガー出力として10[us]のパルス信号を出す
-    _trigerOut = US015_TRIGER_ON;
-    wait_us(US015_TRIGER_PALUSE_WIDTH);    
-    _trigerOut = US015_TRIGER_OFF;
-}
-// End of TrigerOut
-
-
-//*********************************
-// 距離情報の取得
-//*********************************
-float US015::GetDistance()
-{
-    return distance;    
-}
-// End of GetDistance
-
-
-//*********************************
-// エコーの信号の立ち下がり
-//*********************************
-void US015::EchoFall()
-{   
-    //エコー信号の立ち下がり時間を取得
-    tmEnd=timer.read_us();
-
-    // 反射面距離の計算(往復の距離を音速と経過時間から求め、その半分を片道の距離とする)
-    // (エコー受信時間 - トリガー発信時間)* 音速0.340[mm/us]/2
-    distance = ((tmEnd-tmBegin)*(0.340))/2;
-}
-// End of EchoFall
-
-
-//*********************************
-// エコーの信号の立ち上がり処理
-//*********************************
-void US015::EchoRise()
-{
-    //エコー信号の立ち上がり時間を記録
-    tmBegin=timer.read_us();
-}
-// End of EchoRise
diff -r c799e2dde99f -r 5f9c4d16acf6 us015.h
--- a/us015.h	Sun Nov 17 10:08:05 2019 +0000
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,40 +0,0 @@
-#ifndef __US015_H
-#define __US015_H
-
-#include "mbed.h"
-
-
-//====================================
-// define定義
-//====================================
-#define US015_TRIGER_ON             1    // トリガーON
-#define US015_TRIGER_OFF            0    // トリガーOFF
-#define US015_TRIGER_PALUSE_WIDTH   10   // トリガーの幅
-#define US015_PERIODIC_TRIGER 100000    // 音響測距トリガー
-#define US015_SOUND_OF_SPEED  0.340           // 音速[mm/us]
-
-
-//====================================
-// 音響測距センサ(US015)の制御クラス
-//====================================
-class US015
-{
-    public:
-        US015(PinName trg, PinName ech);
-        US015(PinName trg, PinName ech, float tkTime);
-        float GetDistance();
-        void TrigerOut();                       // トリガー出力
-        
-    private:
-        DigitalOut _trigerOut;                  // U015トリガー出力
-        InterruptIn _interruptEcho;             // U015エコー入力
-        Timer timer;                            // 時間計測用のタイマ
-        Ticker tk;                              // 周期処理用のチッカー
-        float tmBegin;                          // エコーの立ち上がり時間
-        float tmEnd;                            // エコーの立ち下がり時間
-        float distance;                         // 距離測定
-        void EchoFall();                        // エコーの立ち下がり処理
-        void EchoRise();                        // エコーの立ち上がり処理
-};
-
-#endif
\ No newline at end of file