Web Camera for mbed-os. This sample works on GR-LYCHEE besides GR-PEACH. When you use this program, we judge you have agreed to the following contents. https://developer.mbed.org/teams/Renesas/wiki/About-LICENSE

Dependencies:   HttpServer_snapshot_mbed-os

License

When you use this program, we judge you have agreed to the following contents.
本プログラムを使用する際は、以下の内容に合意した事になります。

https://developer.mbed.org/teams/Renesas/wiki/About-LICENSE

Information

Japanese version is available in lower part of this page.
このページの後半に日本語版が用意されています.

Video Links on how to setup and run WebCamera Application:

Your video will be live at:

Overview

This is a sample program that works on GR-PEACH or GR-LYCHEE.
This is a web camera sample program. When accessing from the Web browser, the following will be displayed.

  • Camera input picture
  • Control screen of devices connected to the I2C bus
  • LED control screen

Requirements

For GR-PEACH (via Wi-Fi):

  • GR-PEACH
  • GR-PEACH Wireless CAMERA Shield : OV7725

For GR-PEACH (via Ether):

  • GR-PEACH
  • One of the following
    • GR-PEACH Wireless CAMERA Shield : OV7725
    • NTSC analog camera
    • MT9V111 and GR-PEACH AUDIO CAMERA Shield
    • OV5642 and GR-PEACH AUDIO CAMERA Shield

For GR-LYCHEE (via Wi-Fi):

  • GR-LYCHEE

How to use

Turn on the power to the GR-Board and start the terminal software.
The default value of the bow rate with mbed is 9600, and in this sample we use the baud rate 9600.

When you press the reset button of GR-Board, the scan result of Wifi will be output on Terminal. Please refer to the following link for usage of Terminal.

********* PROGRAM START ***********
Network Setting up...
Scan:
No.0 Network: SSID_1 secured:WPA/WPA2 BSSID: xx:xx:xx:xx:xx:xx RSSI: -52 Ch: 1
No.1 Network: SSID_2 secured: Unknown BSSID: xx:xx:xx:xx:xx:xx RSSI: -67 Ch: 2
2 networks available.

Please enter the number of the network you want to connect.
Enter key:[0]-[1], (If inputting the other key, it's scanned again.)

Enter the number of the network you want to connect from the keyboard. To select SSID_1, press "0" on the keyboard.

[SSID_1] is selected.
please enter the PSK.

Finally, enter the password to connect to the network.

If the connection is successful, the IP address is output on Terminal.

connecting...
MAC Address is xx:xx:xx:xx:xx:xx
IP Address is 192.168.0.2
NetMask is 255.255.255.240
Gateway Address is 192.168.0.1
Network Setup OK

When you open IP Address ("192.168.0.2" in the above example) by a Web browser, top screen is indicated. The configuration of the top screen is a menu screen on the left side, a description screen of the sample program on the right side. If you click on each menu on the left side of the screen, the screen along the menu is indicated on the right screen.

Page Top

/media/uploads/1050186/web_top2.jpg

Web Camera

/media/uploads/1050186/camera3.jpg
When you click the "Web camera" in the menu screen, the pictures of a camera is indicated. It can be changed at a slider bar in "Wait time" at the timing of a renewal of a camera picture. (Defaults are 500ms.)

Setting by I2C

/media/uploads/1050186/setting_i2c3.jpg
When you click the "Setting by I2C" of the menu screen, the control screen of the device connected to the I2C bus is indicated. By sending a command of a format listed below("Format of the device set by I2C") in Direct input or File reference, data transmission and reception is possible with respect to devices connected to I2C_SDA and I2C_SCL terminals of I2C. The communication log of transmission and reception by "Format of the device set by I2C" is displayed in the log window. When you press the "Clear" button, the log is cleared. When you press the "Save" button, the log is saved.

Format of the device set by I2C

Method:I2C addr,data length,data1,data2,data3,...

The details of each parameter is shown below.
For specific settings, check on the specifications of the connected device, you must create a command along the format.

MethodPlease specify one of the following:
"Wr" ・・・ Write functions in I2C
"Rd" ・・・ Read functions in I2C
"WrNoP" ・・・ Write functions in I2C(No STOP condition)
"RdNoP" ・・・ Read functions in I2C(No STOP condition)
I2C addrSet the I2C address of device in hexadecimal.
Ex: If the address is 0x90, set the "90"
data lengthIf Method is "Wr" or "WrNoP", set write size(the size of the data portion) in hexadecimal.
Ex: If the write size is 2 byte(data1, data2), set the "02".
If Method is "Rd" or "RdNoP", set read size in hexadecimal.
Ex: If the read size is 10 byte, set the "0A".
dataIf Method is "Wr" or "WrNoP", set write data in 1 byte unit in hexadecimal.
Ex: If the write data is 0x01 0x02, set "01" in the data1 and "02" in the data2.
If Method is "Rd" or "RdNoP", this parameter is omitted.

An example of the format is shown below.

Wr:90,03,25,45,14

To the device of the I2C address 0x90, the data write of 3Byte(0x25 0x45 0x14)

Rd:90,02

To the device of the I2C address 0x90, the data read of 2Byte

LED On/Off

/media/uploads/1050186/led2.jpg
When you click the "LED On/Off" of the menu screen, the LED control screen is indicated. Each switch switches of GR-Boards to ON or OFF. Each switch indicates the current LED state. When the LED is On, the color of switch will change the LED color.

Switch to web page in SD card

Web pages displayed on the Web browser are located in the built-in ROM. file_table_peach.h is saved as table information for GR-PEACH and file_table_lychee.h is saved as table information for GR-LYCHEE. The contents of the saved file are as follows.

When connecting the SD card, SDBlockDevice will be displayed on the terminal and the web page displayed in the web browser will switch from the built-in ROM to the SD card. The top page is index.htm.

Change network connection

You can change the network connection by changing the following macro in main.cpp.

/**** User Selection *********/
#define NETWORK_TYPE           (2)                 /* Select  0(Ethernet), 1(BP3595), 2(ESP32 STA) ,3(ESP32 AP) */
#if (NETWORK_TYPE >= 1)
  #define SCAN_NETWORK         (1)                 /* Select  0(Use WLAN_SSID, WLAN_PSK, WLAN_SECURITY) or 1(To select a network using the terminal.) */
  #define WLAN_SSID            ("SSIDofYourAP")    /* SSID */
  #define WLAN_PSK             ("PSKofYourAP")     /* PSK(Pre-Shared Key) */
  #define WLAN_SECURITY        NSAPI_SECURITY_WPA_WPA2 /* NSAPI_SECURITY_NONE, NSAPI_SECURITY_WEP, NSAPI_SECURITY_WPA, NSAPI_SECURITY_WPA2 or NSAPI_SECURITY_WPA_WPA2 */
#endif

Depending on the value set for NETWORK_TYPE, the connection method changes as follows.

NumberConnectionDescription
0EthernetGR-PEACH only
1reservedIt can not be selected.
2ESP32 STAUse ESP32 in STA mode.
3ESP32 APUse ESP32 in AP mode.

When using GR-LYCHEE, NETWORK_TYPE 2 and 3 can be selected.
GR-PEACH Wireless CAMERA Shield is required separately when using ESP32 with GR-PEACH.

When using Ethernet, the user must provide the MAC address.
To specify MAC address, add fllowing function to main.cpp.

Specify MAC address

// set mac address
void mbed_mac_address(char *mac) {
    mac[0] = 0x00;
    mac[1] = 0x02;
    mac[2] = 0xF7;
    mac[3] = 0xF0;
    mac[4] = 0x00;
    mac[5] = 0x00;
}

Camera selection

To select the Camera, add camera-type to mbed_app.json.
See here for details.

mbed_app.json

{
    "config": {
        "camera":{
            "help": "0:disable 1:enable",
            "value": "1"
        },
        "camera-type":{
            "help": "Please see EasyAttach_CameraAndLCD/README.md",
            "value": null
        },
        "lcd":{
            "help": "0:disable 1:enable",
            "value": "0"
        },
        "lcd-type":{
            "help": "Please see EasyAttach_CameraAndLCD/README.md",
            "value": null
        }
    },
    "target_overrides": {
        "RZ_A1H": {
            "camera-type" : "CAMERA_WIRELESS_CAMERA"
        }
    }
}

Appendix


概要

GR-PEACH、および、GR-LYCHEEで動作するサンプルプログラムです。
Webカメラのサンプルです。Webブラウザからアクセスすると以下が表示されます。

  • Camera入力画像
  • I2Cバスに繋がっているデバイスの制御画面
  • LED操作画面

構成

GR-PEACH (Wi-Fi経由)の場合:

  • GR-PEACH
  • GR-PEACH Wireless CAMERA Shield : OV7725

GR-PEACH (Ether経由)の場合:

  • GR-PEACH
  • 以下のいずれか
    • GR-PEACH Wireless CAMERA Shield : OV7725
    • NTSCアナログカメラ
    • MT9V111 and GR-PEACH AUDIO CAMERA Shield
    • OV5642 and GR-PEACH AUDIO CAMERA Shield

GR-LYCHEE(Wi-Fi経由)の場合:

  • GR-LYCHEE

使い方

GR-Boardに電源を入れ、Terminalソフトを立ち上げます。
Mbedでのボーレートのデフォルト値は9600で、このサンプルではボーレート9600を使います。

GR-Boardのリセットボタンを押すと、Terminal上にWifiのスキャン結果が出力されます。

********* PROGRAM START ***********
Network Setting up...
Scan:
No.0 Network: SSID_1 secured:WPA/WPA2 BSSID: xx:xx:xx:xx:xx:xx RSSI: -52 Ch: 1
No.1 Network: SSID_2 secured: Unknown BSSID: xx:xx:xx:xx:xx:xx RSSI: -67 Ch: 2
2 networks available.

Please enter the number of the network you want to connect.
Enter key:[0]-[1], (If inputting the other key, it's scanned again.)

接続したいネットワークの番号をキーボードから入力します。0番のSSID_1を選択する場合はキーボードの "0" を押します。

[SSID_1] is selected.
please enter the PSK.

最後にネットワークに接続するためのパスワードを入力します。

接続に成功すると、Terminal上にIPアドレスが出力されます。

connecting...
MAC Address is xx:xx:xx:xx:xx:xx
IP Address is 192.168.0.2
NetMask is 255.255.255.240
Gateway Address is 192.168.0.1
Network Setup OK

PCのWebブラウザで Terminalに表示された IP Address (上記例では 192.168.0.2)を開くと、トップ画面が表示されます。トップ画面は、左側にメニュー画面、右側にサンプルプログラムの説明画面という構成になっており、左画面の各メニューをクリックすると、メニューに沿った画面が右画面に表示されます。

Page Top 画面

/media/uploads/1050186/web_top2.jpg

Web Camera 画面

/media/uploads/1050186/camera3.jpg
メニュー画面の”Web Camera”をクリックすると、Camera画像が表示されます。
"Wait time"のスライダーバーでCamera画像の更新タイミングが変更できます。(初期値は500msです)

Setting by I2C 画面

/media/uploads/1050186/setting_i2c3.jpg

メニュー画面の"Setting by I2C"をクリックすると、I2Cバスに繋がっているデバイスの制御画面が表示されます。直接入力(Direct input)欄又はファイル参照(File reference)欄にて、下記("I2Cによるデバイス設定のフォーマット")に記載されているフォーマットのコマンドを送信する事で、I2CのI2C_SDA,I2C_SCL端子に繋がっているデバイスに対して、データの送受信が可能です。"I2Cによるデバイス設定のフォーマット"による送受信の通信ログは、ログウィンドウに表示されます。"Clear"ボタンを押すとログのクリア、"Save"ボタンを押すとログの保存ができます。

I2Cによるデバイス設定のフォーマット

Method:I2C addr,data length,data1,data2,data3,...

各パラメータの詳細を以下に示します。
具体的な設定値については、接続先のデバイスの仕様をご確認のうえ、フォーマットに沿ってコマンドを作成して下さい。

Method以下のいづれかを指定して下さい
"Wr" ・・・ I2Cでの書き込み
"Rd" ・・・ I2Cでの読み出し
"WrNoP" ・・・ I2Cでの書き込み(STOPコンディション省略)
"RdNoP" ・・・ I2Cでの読み出し(STOPコンディション省略)
I2C addr接続先デバイスのI2Cアドレスを16進数で設定して下さい。
(例) アドレスが0x90の場合、"90"を設定
data lengthMethodが"Wr"又は"WrNoP"の場合、書き込むサイズ(data部分のサイズ)を16進数で設定して下さい。
(例) 書き込むサイズが2Byte(data1,data2)の場合、"02"を設定
Methodが"Rd"又は"RdNoP"の場合は読み取るサイズを16進数で設定して下さい。
(例) 読み取りサイズが10Byteの場合、"0A"を設定
dataMethodが"Wr"又は"WrNoP"の場合、書き込むデータを16進数で1Byte単位で設定して下さい。
(例) 書き込みデータが0x01,0x02の場合、data1に"01"、data2に"02"を設定
"Rd"又は"RdNoP"の場合は省略して下さい。

フォーマットの例を以下に示します。

Wr:90,03,25,45,14

I2Cアドレス0x90のデバイスに対して0x25 0x45 0x14の計3Byteのデータ書き込み

Rd:90,02

I2Cアドレス0x90のデバイスに対して2Byteのデータ読み出し

LED On/Off 画面

/media/uploads/1050186/led2.jpg
メニュー画面の"LED On/Off"をクリックすると、LED操作画面が表示されます。各スイッチはGR-BoardのLED ON/OFFを切り替えます。スイッチはそれぞれGR-BoardのLEDの現在の状態を表しており、ONにすると対応するLEDの色になります。

SDカード内のWebページに切り替える

Webブラウザで表示されるWebページは内蔵ROMに配置されています。file_table_peach.h はGR-PEACH用、 file_table_lychee.h はGR-LYCHEE用のWebページがテーブル情報として保存されています。保存されているファイルの内容は下記の通りです。

SDカードを接続するとTerminal上に SDBlockDevice と表示され、Webブラウザで表示されるWebページが内蔵ROMからSDカードに切り替わります。トップページは index.htm となります。

ネットワークの接続方法を変更する

main.cppの下記マクロを変更することでネットワークの接続方法を変更できます。

/**** User Selection *********/
#define NETWORK_TYPE           (2)                 /* Select  0(Ethernet), 1(BP3595), 2(ESP32 STA) ,3(ESP32 AP) */
#if (NETWORK_TYPE >= 1)
  #define SCAN_NETWORK         (1)                 /* Select  0(Use WLAN_SSID, WLAN_PSK, WLAN_SECURITY) or 1(To select a network using the terminal.) */
  #define WLAN_SSID            ("SSIDofYourAP")    /* SSID */
  #define WLAN_PSK             ("PSKofYourAP")     /* PSK(Pre-Shared Key) */
  #define WLAN_SECURITY        NSAPI_SECURITY_WPA_WPA2 /* NSAPI_SECURITY_NONE, NSAPI_SECURITY_WEP, NSAPI_SECURITY_WPA, NSAPI_SECURITY_WPA2 or NSAPI_SECURITY_WPA_WPA2 */
#endif

NETWORK_TYPE に設定する値により、以下の接続方法に切り替わります。

番号接続方法説明
0EthernetGR-PEACHのみ。
1reserved選択できません。
2ESP32 STAESP32をSTAモードで使用します。
3ESP32 APESP32をAPモードで使用します。

GR-LYCHEEを使用する場合はNETWORK_TYPE 2と3が選択できます。
GR-PEACHでNETWORK_TYPE 2と3を使用する場合は別途GR-PEACH Wireless/Cameraシールドが必要です。

NETWORK_TYPE 1のEthernetを使う場合はMACアドレスをユーザが用意する必要があります。
"main.cpp"の最後にの下記のように関数を追加し、用意したMACアドレスを設定してください。

Specify MAC address

// set mac address
void mbed_mac_address(char *mac) {
    mac[0] = 0x00;
    mac[1] = 0x02;
    mac[2] = 0xF7;
    mac[3] = 0xF0;
    mac[4] = 0x00;
    mac[5] = 0x00;
}

カメラの設定

カメラの指定を行う場合はmbed_app.jsonにcamera-typeを変更して追加してください。
詳細はこちらを参照ください。

mbed_app.json

{
    "config": {
        "camera":{
            "help": "0:disable 1:enable",
            "value": "1"
        },
        "camera-type":{
            "help": "Please see EasyAttach_CameraAndLCD/README.md",
            "value": null
        },
        "lcd":{
            "help": "0:disable 1:enable",
            "value": "0"
        },
        "lcd-type":{
            "help": "Please see EasyAttach_CameraAndLCD/README.md",
            "value": null
        }
    },
    "target_overrides": {
        "RZ_A1H": {
            "camera-type" : "CAMERA_WIRELESS_CAMERA"
        }
    }
}

付録

Committer:
dkato
Date:
Fri Oct 28 06:33:08 2016 +0000
Revision:
17:2648bcf3f2cc
Parent:
16:b5469a6226c7
Child:
18:0461a79ced71
Change for the mbed-os.

Who changed what in which revision?

UserRevisionLine numberNew contents of line
dkato 0:c5448e500c90 1 #include "mbed.h"
dkato 0:c5448e500c90 2 #include "DisplayBace.h"
dkato 0:c5448e500c90 3 #include "rtos.h"
dkato 0:c5448e500c90 4 #include "JPEG_Converter.h"
dkato 0:c5448e500c90 5 #include "HTTPServer.h"
dkato 0:c5448e500c90 6 #include "mbed_rpc.h"
dkato 0:c5448e500c90 7 #include "RomRamFileSystem.h"
dkato 0:c5448e500c90 8 #include "file_table.h" //Binary data of web pages
1050186 5:34d84609dd60 9 #include "i2c_setting.h"
dkato 0:c5448e500c90 10
dkato 0:c5448e500c90 11 #define VIDEO_CVBS (0) /* Analog Video Signal */
dkato 0:c5448e500c90 12 #define VIDEO_CMOS_CAMERA (1) /* Digital Video Signal */
dkato 0:c5448e500c90 13 #define VIDEO_YCBCR422 (0)
dkato 0:c5448e500c90 14 #define VIDEO_RGB888 (1)
dkato 0:c5448e500c90 15 #define VIDEO_RGB565 (2)
dkato 0:c5448e500c90 16
dkato 0:c5448e500c90 17 /**** User Selection *********/
dkato 11:ad8ff26679bb 18 /** Network setting **/
dkato 11:ad8ff26679bb 19 #define USE_DHCP (1) /* Select 0(static configuration) or 1(use DHCP) */
dkato 11:ad8ff26679bb 20 #if (USE_DHCP == 0)
dkato 11:ad8ff26679bb 21 #define IP_ADDRESS ("192.168.0.2") /* IP address */
dkato 11:ad8ff26679bb 22 #define SUBNET_MASK ("255.255.255.0") /* Subnet mask */
dkato 11:ad8ff26679bb 23 #define DEFAULT_GATEWAY ("192.168.0.3") /* Default gateway */
dkato 11:ad8ff26679bb 24 #endif
dkato 15:eac4c3711aab 25 #define NETWORK_TYPE (0) /* Select 0(EthernetInterface) or 1(GR_PEACH_WlanBP3595) */
dkato 15:eac4c3711aab 26 #if (NETWORK_TYPE == 1)
dkato 17:2648bcf3f2cc 27 #define SCAN_NETWORK (1) /* Select 0(Use WLAN_SSID, WLAN_PSK, WLAN_SECURITY) or 1(To select a network using the terminal.) */
dkato 15:eac4c3711aab 28 #define WLAN_SSID ("SSIDofYourAP") /* SSID */
dkato 15:eac4c3711aab 29 #define WLAN_PSK ("PSKofYourAP") /* PSK(Pre-Shared Key) */
dkato 17:2648bcf3f2cc 30 #define WLAN_SECURITY NSAPI_SECURITY_WPA_WPA2 /* NSAPI_SECURITY_NONE, NSAPI_SECURITY_WEP, NSAPI_SECURITY_WPA, NSAPI_SECURITY_WPA2 or NSAPI_SECURITY_WPA_WPA2 */
dkato 15:eac4c3711aab 31 #endif
dkato 11:ad8ff26679bb 32 /** Camera setting **/
dkato 0:c5448e500c90 33 #define VIDEO_INPUT_METHOD (VIDEO_CMOS_CAMERA) /* Select VIDEO_CVBS or VIDEO_CMOS_CAMERA */
dkato 0:c5448e500c90 34 #define VIDEO_INPUT_FORMAT (VIDEO_YCBCR422) /* Select VIDEO_YCBCR422 or VIDEO_RGB888 or VIDEO_RGB565 */
dkato 0:c5448e500c90 35 #define USE_VIDEO_CH (0) /* Select 0 or 1 If selecting VIDEO_CMOS_CAMERA, should be 0.) */
dkato 0:c5448e500c90 36 #define VIDEO_PAL (0) /* Select 0(NTSC) or 1(PAL) If selecting VIDEO_CVBS, this parameter is not referenced.) */
dkato 0:c5448e500c90 37 /*****************************/
dkato 0:c5448e500c90 38
dkato 0:c5448e500c90 39 #if USE_VIDEO_CH == (0)
dkato 0:c5448e500c90 40 #define VIDEO_INPUT_CH (DisplayBase::VIDEO_INPUT_CHANNEL_0)
dkato 0:c5448e500c90 41 #define VIDEO_INT_TYPE (DisplayBase::INT_TYPE_S0_VFIELD)
dkato 0:c5448e500c90 42 #else
dkato 0:c5448e500c90 43 #define VIDEO_INPUT_CH (DisplayBase::VIDEO_INPUT_CHANNEL_1)
dkato 0:c5448e500c90 44 #define VIDEO_INT_TYPE (DisplayBase::INT_TYPE_S1_VFIELD)
dkato 0:c5448e500c90 45 #endif
dkato 0:c5448e500c90 46
dkato 0:c5448e500c90 47 #if ( VIDEO_INPUT_FORMAT == VIDEO_YCBCR422 || VIDEO_INPUT_FORMAT == VIDEO_RGB565 )
dkato 0:c5448e500c90 48 #define DATA_SIZE_PER_PIC (2u)
dkato 0:c5448e500c90 49 #else
dkato 0:c5448e500c90 50 #define DATA_SIZE_PER_PIC (4u)
dkato 0:c5448e500c90 51 #endif
dkato 0:c5448e500c90 52
dkato 0:c5448e500c90 53 /*! Frame buffer stride: Frame buffer stride should be set to a multiple of 32 or 128
dkato 0:c5448e500c90 54 in accordance with the frame buffer burst transfer mode. */
dkato 0:c5448e500c90 55 #define PIXEL_HW (320u) /* QVGA */
dkato 0:c5448e500c90 56 #define PIXEL_VW (240u) /* QVGA */
dkato 0:c5448e500c90 57
dkato 0:c5448e500c90 58 #define VIDEO_BUFFER_STRIDE (((PIXEL_HW * DATA_SIZE_PER_PIC) + 31u) & ~31u)
dkato 0:c5448e500c90 59 #define VIDEO_BUFFER_HEIGHT (PIXEL_VW)
dkato 0:c5448e500c90 60
dkato 15:eac4c3711aab 61 #if (NETWORK_TYPE == 0)
dkato 15:eac4c3711aab 62 #include "EthernetInterface.h"
dkato 15:eac4c3711aab 63 EthernetInterface network;
dkato 15:eac4c3711aab 64 #elif (NETWORK_TYPE == 1)
dkato 17:2648bcf3f2cc 65 #include "LWIPBP3595Interface.h"
dkato 17:2648bcf3f2cc 66 LWIPBP3595Interface network;
dkato 15:eac4c3711aab 67 DigitalOut usb1en(P3_8);
dkato 15:eac4c3711aab 68 #else
dkato 15:eac4c3711aab 69 #error NETWORK_TYPE error
dkato 15:eac4c3711aab 70 #endif /* NETWORK_TYPE */
dkato 11:ad8ff26679bb 71 RomRamFileSystem romramfs("romram");
dkato 17:2648bcf3f2cc 72 Serial pc(USBTX, USBRX);
dkato 0:c5448e500c90 73
dkato 14:212f66386982 74 #if defined(__ICCARM__)
dkato 14:212f66386982 75 #pragma data_alignment=16
dkato 14:212f66386982 76 static uint8_t FrameBuffer_Video[VIDEO_BUFFER_STRIDE * VIDEO_BUFFER_HEIGHT]@ ".mirrorram"; //16 bytes aligned!;
dkato 14:212f66386982 77 #pragma data_alignment=4
dkato 14:212f66386982 78 #else
dkato 0:c5448e500c90 79 static uint8_t FrameBuffer_Video[VIDEO_BUFFER_STRIDE * VIDEO_BUFFER_HEIGHT]__attribute((section("NC_BSS"),aligned(16))); //16 bytes aligned!;
dkato 14:212f66386982 80 #endif
dkato 0:c5448e500c90 81 static volatile int32_t vsync_count = 0;
dkato 0:c5448e500c90 82 static volatile int32_t vfield_count = 1;
dkato 14:212f66386982 83 #if defined(__ICCARM__)
dkato 14:212f66386982 84 #pragma data_alignment=8
dkato 14:212f66386982 85 static uint8_t JpegBuffer[2][1024 * 50]@ ".mirrorram"; //8 bytes aligned!;
dkato 14:212f66386982 86 #pragma data_alignment=4
dkato 14:212f66386982 87 #else
dkato 1:ebff3aeb40a0 88 static uint8_t JpegBuffer[2][1024 * 50]__attribute((section("NC_BSS"),aligned(8))); //8 bytes aligned!;
dkato 14:212f66386982 89 #endif
dkato 1:ebff3aeb40a0 90 static size_t jcu_encode_size[2];
dkato 0:c5448e500c90 91 static int image_change = 0;
dkato 1:ebff3aeb40a0 92 JPEG_Converter Jcu;
dkato 1:ebff3aeb40a0 93 static int jcu_buf_index_write = 0;
dkato 1:ebff3aeb40a0 94 static int jcu_buf_index_write_done = 0;
dkato 1:ebff3aeb40a0 95 static int jcu_buf_index_read = 0;
dkato 1:ebff3aeb40a0 96 static int jcu_encoding = 0;
dkato 7:c45ecff1b44d 97 static char i2c_setting_str_buf[I2C_SETTING_STR_BUF_SIZE];
dkato 1:ebff3aeb40a0 98
dkato 1:ebff3aeb40a0 99 static void JcuEncodeCallBackFunc(JPEG_Converter::jpeg_conv_error_t err_code) {
dkato 1:ebff3aeb40a0 100 jcu_buf_index_write_done = jcu_buf_index_write;
dkato 1:ebff3aeb40a0 101 image_change = 1;
dkato 1:ebff3aeb40a0 102 jcu_encoding = 0;
dkato 1:ebff3aeb40a0 103 }
dkato 0:c5448e500c90 104
dkato 0:c5448e500c90 105 static void IntCallbackFunc_Vfield(DisplayBase::int_type_t int_type) {
dkato 0:c5448e500c90 106 //Interrupt callback function
dkato 0:c5448e500c90 107 if (vfield_count != 0) {
dkato 0:c5448e500c90 108 vfield_count = 0;
dkato 0:c5448e500c90 109 } else {
dkato 0:c5448e500c90 110 vfield_count = 1;
dkato 1:ebff3aeb40a0 111
dkato 1:ebff3aeb40a0 112 JPEG_Converter::bitmap_buff_info_t bitmap_buff_info;
dkato 1:ebff3aeb40a0 113 JPEG_Converter::encode_options_t encode_options;
dkato 1:ebff3aeb40a0 114
dkato 1:ebff3aeb40a0 115 bitmap_buff_info.width = PIXEL_HW;
dkato 1:ebff3aeb40a0 116 bitmap_buff_info.height = PIXEL_VW;
dkato 1:ebff3aeb40a0 117 bitmap_buff_info.format = JPEG_Converter::WR_RD_YCbCr422;
dkato 1:ebff3aeb40a0 118 bitmap_buff_info.buffer_address = (void *)FrameBuffer_Video;
dkato 1:ebff3aeb40a0 119
dkato 1:ebff3aeb40a0 120 encode_options.encode_buff_size = sizeof(JpegBuffer[0]);
dkato 1:ebff3aeb40a0 121 encode_options.p_EncodeCallBackFunc = &JcuEncodeCallBackFunc;
dkato 1:ebff3aeb40a0 122
dkato 1:ebff3aeb40a0 123 jcu_encoding = 1;
dkato 1:ebff3aeb40a0 124 if (jcu_buf_index_read == jcu_buf_index_write) {
dkato 1:ebff3aeb40a0 125 if (jcu_buf_index_write != 0) {
dkato 1:ebff3aeb40a0 126 jcu_buf_index_write = 0;
dkato 1:ebff3aeb40a0 127 } else {
dkato 1:ebff3aeb40a0 128 jcu_buf_index_write = 1;
dkato 1:ebff3aeb40a0 129 }
dkato 1:ebff3aeb40a0 130 }
dkato 1:ebff3aeb40a0 131 jcu_encode_size[jcu_buf_index_write] = 0;
dkato 1:ebff3aeb40a0 132 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) {
dkato 1:ebff3aeb40a0 133 jcu_encode_size[jcu_buf_index_write] = 0;
dkato 1:ebff3aeb40a0 134 jcu_encoding = 0;
dkato 1:ebff3aeb40a0 135 }
dkato 0:c5448e500c90 136 }
dkato 0:c5448e500c90 137 }
dkato 0:c5448e500c90 138
dkato 0:c5448e500c90 139 static void IntCallbackFunc_Vsync(DisplayBase::int_type_t int_type) {
dkato 0:c5448e500c90 140 //Interrupt callback function for Vsync interruption
dkato 0:c5448e500c90 141 if (vsync_count > 0) {
dkato 0:c5448e500c90 142 vsync_count--;
dkato 0:c5448e500c90 143 }
dkato 0:c5448e500c90 144 }
dkato 0:c5448e500c90 145
dkato 0:c5448e500c90 146 static void WaitVsync(const int32_t wait_count) {
dkato 0:c5448e500c90 147 //Wait for the specified number of times Vsync occurs
dkato 0:c5448e500c90 148 vsync_count = wait_count;
dkato 0:c5448e500c90 149 while (vsync_count > 0) {
dkato 0:c5448e500c90 150 /* Do nothing */
dkato 0:c5448e500c90 151 }
dkato 0:c5448e500c90 152 }
dkato 0:c5448e500c90 153
dkato 0:c5448e500c90 154 static void camera_start(void) {
dkato 0:c5448e500c90 155 DisplayBase::graphics_error_t error;
dkato 0:c5448e500c90 156
dkato 0:c5448e500c90 157 #if VIDEO_INPUT_METHOD == VIDEO_CMOS_CAMERA
dkato 0:c5448e500c90 158 DisplayBase::video_ext_in_config_t ext_in_config;
dkato 0:c5448e500c90 159 PinName cmos_camera_pin[11] = {
dkato 0:c5448e500c90 160 /* data pin */
dkato 0:c5448e500c90 161 P2_7, P2_6, P2_5, P2_4, P2_3, P2_2, P2_1, P2_0,
dkato 0:c5448e500c90 162 /* control pin */
dkato 0:c5448e500c90 163 P10_0, /* DV0_CLK */
dkato 0:c5448e500c90 164 P1_0, /* DV0_Vsync */
dkato 0:c5448e500c90 165 P1_1 /* DV0_Hsync */
dkato 0:c5448e500c90 166 };
dkato 0:c5448e500c90 167 #endif
dkato 0:c5448e500c90 168
dkato 0:c5448e500c90 169 /* Create DisplayBase object */
dkato 0:c5448e500c90 170 DisplayBase Display;
dkato 0:c5448e500c90 171
dkato 0:c5448e500c90 172 /* Graphics initialization process */
dkato 0:c5448e500c90 173 error = Display.Graphics_init(NULL);
dkato 0:c5448e500c90 174 if (error != DisplayBase::GRAPHICS_OK) {
dkato 0:c5448e500c90 175 printf("Line %d, error %d\n", __LINE__, error);
dkato 0:c5448e500c90 176 while (1);
dkato 0:c5448e500c90 177 }
dkato 0:c5448e500c90 178
dkato 0:c5448e500c90 179 #if VIDEO_INPUT_METHOD == VIDEO_CVBS
dkato 0:c5448e500c90 180 error = Display.Graphics_Video_init( DisplayBase::INPUT_SEL_VDEC, NULL);
dkato 0:c5448e500c90 181 if( error != DisplayBase::GRAPHICS_OK ) {
dkato 0:c5448e500c90 182 printf("Line %d, error %d\n", __LINE__, error);
dkato 0:c5448e500c90 183 while(1);
dkato 0:c5448e500c90 184 }
dkato 0:c5448e500c90 185
dkato 0:c5448e500c90 186 #elif VIDEO_INPUT_METHOD == VIDEO_CMOS_CAMERA
dkato 0:c5448e500c90 187 /* MT9V111 camera input config */
dkato 0:c5448e500c90 188 ext_in_config.inp_format = DisplayBase::VIDEO_EXTIN_FORMAT_BT601; /* BT601 8bit YCbCr format */
dkato 0:c5448e500c90 189 ext_in_config.inp_pxd_edge = DisplayBase::EDGE_RISING; /* Clock edge select for capturing data */
dkato 0:c5448e500c90 190 ext_in_config.inp_vs_edge = DisplayBase::EDGE_RISING; /* Clock edge select for capturing Vsync signals */
dkato 0:c5448e500c90 191 ext_in_config.inp_hs_edge = DisplayBase::EDGE_RISING; /* Clock edge select for capturing Hsync signals */
dkato 0:c5448e500c90 192 ext_in_config.inp_endian_on = DisplayBase::OFF; /* External input bit endian change on/off */
dkato 0:c5448e500c90 193 ext_in_config.inp_swap_on = DisplayBase::OFF; /* External input B/R signal swap on/off */
dkato 0:c5448e500c90 194 ext_in_config.inp_vs_inv = DisplayBase::SIG_POL_NOT_INVERTED; /* External input DV_VSYNC inversion control */
dkato 0:c5448e500c90 195 ext_in_config.inp_hs_inv = DisplayBase::SIG_POL_INVERTED; /* External input DV_HSYNC inversion control */
dkato 0:c5448e500c90 196 ext_in_config.inp_f525_625 = DisplayBase::EXTIN_LINE_525; /* Number of lines for BT.656 external input */
dkato 0:c5448e500c90 197 ext_in_config.inp_h_pos = DisplayBase::EXTIN_H_POS_CRYCBY; /* Y/Cb/Y/Cr data string start timing to Hsync reference */
dkato 0:c5448e500c90 198 ext_in_config.cap_vs_pos = 6; /* Capture start position from Vsync */
dkato 0:c5448e500c90 199 ext_in_config.cap_hs_pos = 150; /* Capture start position form Hsync */
dkato 0:c5448e500c90 200 ext_in_config.cap_width = 640; /* Capture width */
dkato 0:c5448e500c90 201 ext_in_config.cap_height = 468u; /* Capture height Max 468[line]
dkato 0:c5448e500c90 202 Due to CMOS(MT9V111) output signal timing and VDC5 specification */
dkato 0:c5448e500c90 203 error = Display.Graphics_Video_init( DisplayBase::INPUT_SEL_EXT, &ext_in_config);
dkato 0:c5448e500c90 204 if( error != DisplayBase::GRAPHICS_OK ) {
dkato 0:c5448e500c90 205 printf("Line %d, error %d\n", __LINE__, error);
dkato 0:c5448e500c90 206 while(1);
dkato 0:c5448e500c90 207 }
dkato 0:c5448e500c90 208
dkato 0:c5448e500c90 209 /* MT9V111 camera input port setting */
dkato 0:c5448e500c90 210 error = Display.Graphics_Dvinput_Port_Init(cmos_camera_pin, 11);
dkato 0:c5448e500c90 211 if( error != DisplayBase::GRAPHICS_OK ) {
dkato 0:c5448e500c90 212 printf("Line %d, error %d\n", __LINE__, error);
dkato 0:c5448e500c90 213 while (1);
dkato 0:c5448e500c90 214 }
dkato 0:c5448e500c90 215 #endif
dkato 0:c5448e500c90 216
dkato 0:c5448e500c90 217 /* Interrupt callback function setting (Vsync signal input to scaler 0) */
dkato 0:c5448e500c90 218 error = Display.Graphics_Irq_Handler_Set(DisplayBase::INT_TYPE_S0_VI_VSYNC, 0, IntCallbackFunc_Vsync);
dkato 0:c5448e500c90 219 if (error != DisplayBase::GRAPHICS_OK) {
dkato 0:c5448e500c90 220 printf("Line %d, error %d\n", __LINE__, error);
dkato 0:c5448e500c90 221 while (1);
dkato 0:c5448e500c90 222 }
dkato 0:c5448e500c90 223 /* Video capture setting (progressive form fixed) */
dkato 0:c5448e500c90 224 error = Display.Video_Write_Setting(
dkato 0:c5448e500c90 225 VIDEO_INPUT_CH,
dkato 0:c5448e500c90 226 #if VIDEO_PAL == 0
dkato 0:c5448e500c90 227 DisplayBase::COL_SYS_NTSC_358,
dkato 0:c5448e500c90 228 #else
dkato 0:c5448e500c90 229 DisplayBase::COL_SYS_PAL_443,
dkato 0:c5448e500c90 230 #endif
dkato 0:c5448e500c90 231 FrameBuffer_Video,
dkato 0:c5448e500c90 232 VIDEO_BUFFER_STRIDE,
dkato 0:c5448e500c90 233 #if VIDEO_INPUT_FORMAT == VIDEO_YCBCR422
dkato 0:c5448e500c90 234 DisplayBase::VIDEO_FORMAT_YCBCR422,
dkato 0:c5448e500c90 235 DisplayBase::WR_RD_WRSWA_NON,
dkato 0:c5448e500c90 236 #elif VIDEO_INPUT_FORMAT == VIDEO_RGB565
dkato 0:c5448e500c90 237 DisplayBase::VIDEO_FORMAT_RGB565,
dkato 0:c5448e500c90 238 DisplayBase::WR_RD_WRSWA_32_16BIT,
dkato 0:c5448e500c90 239 #else
dkato 0:c5448e500c90 240 DisplayBase::VIDEO_FORMAT_RGB888,
dkato 0:c5448e500c90 241 DisplayBase::WR_RD_WRSWA_32BIT,
dkato 0:c5448e500c90 242 #endif
dkato 0:c5448e500c90 243 PIXEL_VW,
dkato 0:c5448e500c90 244 PIXEL_HW
dkato 0:c5448e500c90 245 );
dkato 0:c5448e500c90 246 if (error != DisplayBase::GRAPHICS_OK) {
dkato 0:c5448e500c90 247 printf("Line %d, error %d\n", __LINE__, error);
dkato 0:c5448e500c90 248 while (1);
dkato 0:c5448e500c90 249 }
dkato 0:c5448e500c90 250
dkato 0:c5448e500c90 251 /* Interrupt callback function setting (Field end signal for recording function in scaler 0) */
dkato 0:c5448e500c90 252 error = Display.Graphics_Irq_Handler_Set(VIDEO_INT_TYPE, 0, IntCallbackFunc_Vfield);
dkato 0:c5448e500c90 253 if (error != DisplayBase::GRAPHICS_OK) {
dkato 0:c5448e500c90 254 printf("Line %d, error %d\n", __LINE__, error);
dkato 0:c5448e500c90 255 while (1);
dkato 0:c5448e500c90 256 }
dkato 0:c5448e500c90 257
dkato 0:c5448e500c90 258 /* Video write process start */
dkato 0:c5448e500c90 259 error = Display.Video_Start (VIDEO_INPUT_CH);
dkato 0:c5448e500c90 260 if (error != DisplayBase::GRAPHICS_OK) {
dkato 0:c5448e500c90 261 printf("Line %d, error %d\n", __LINE__, error);
dkato 0:c5448e500c90 262 while (1);
dkato 0:c5448e500c90 263 }
dkato 0:c5448e500c90 264
dkato 0:c5448e500c90 265 /* Video write process stop */
dkato 0:c5448e500c90 266 error = Display.Video_Stop (VIDEO_INPUT_CH);
dkato 0:c5448e500c90 267 if (error != DisplayBase::GRAPHICS_OK) {
dkato 0:c5448e500c90 268 printf("Line %d, error %d\n", __LINE__, error);
dkato 0:c5448e500c90 269 while (1);
dkato 0:c5448e500c90 270 }
dkato 0:c5448e500c90 271
dkato 0:c5448e500c90 272 /* Video write process start */
dkato 0:c5448e500c90 273 error = Display.Video_Start (VIDEO_INPUT_CH);
dkato 0:c5448e500c90 274 if (error != DisplayBase::GRAPHICS_OK) {
dkato 0:c5448e500c90 275 printf("Line %d, error %d\n", __LINE__, error);
dkato 0:c5448e500c90 276 while (1);
dkato 0:c5448e500c90 277 }
dkato 0:c5448e500c90 278
dkato 0:c5448e500c90 279 /* Wait vsync to update resister */
dkato 0:c5448e500c90 280 WaitVsync(1);
dkato 0:c5448e500c90 281 }
dkato 0:c5448e500c90 282
dkato 0:c5448e500c90 283 static int snapshot_req(const char ** pp_data) {
dkato 1:ebff3aeb40a0 284 int encode_size;
dkato 0:c5448e500c90 285
dkato 1:ebff3aeb40a0 286 while ((jcu_encoding == 1) || (image_change == 0)) {
dkato 0:c5448e500c90 287 Thread::wait(1);
dkato 0:c5448e500c90 288 }
dkato 1:ebff3aeb40a0 289 jcu_buf_index_read = jcu_buf_index_write_done;
dkato 0:c5448e500c90 290 image_change = 0;
dkato 0:c5448e500c90 291
dkato 1:ebff3aeb40a0 292 *pp_data = (const char *)JpegBuffer[jcu_buf_index_read];
dkato 1:ebff3aeb40a0 293 encode_size = (int)jcu_encode_size[jcu_buf_index_read];
dkato 0:c5448e500c90 294
dkato 1:ebff3aeb40a0 295 return encode_size;
dkato 0:c5448e500c90 296 }
dkato 0:c5448e500c90 297
dkato 0:c5448e500c90 298 static void TerminalWrite(Arguments* arg, Reply* r) {
dkato 16:b5469a6226c7 299 if ((arg != NULL) && (r != NULL)) {
dkato 16:b5469a6226c7 300 for (int i = 0; i < arg->argc; i++) {
dkato 16:b5469a6226c7 301 if (arg->argv[i] != NULL) {
dkato 16:b5469a6226c7 302 printf("%s", arg->argv[i]);
dkato 16:b5469a6226c7 303 }
dkato 16:b5469a6226c7 304 }
dkato 16:b5469a6226c7 305 printf("\n");
dkato 16:b5469a6226c7 306 r->putData<const char*>("ok");
dkato 16:b5469a6226c7 307 }
dkato 0:c5448e500c90 308 }
dkato 0:c5448e500c90 309
dkato 0:c5448e500c90 310 static void mount_romramfs(void) {
dkato 0:c5448e500c90 311 FILE * fp;
dkato 0:c5448e500c90 312
dkato 0:c5448e500c90 313 romramfs.format();
dkato 0:c5448e500c90 314
dkato 12:6c002b871c4d 315 //index.htm
dkato 12:6c002b871c4d 316 fp = fopen("/romram/index.htm", "w");
dkato 12:6c002b871c4d 317 fwrite(index_htm_tbl, sizeof(char), sizeof(index_htm_tbl), fp);
dkato 12:6c002b871c4d 318 fclose(fp);
dkato 12:6c002b871c4d 319
dkato 0:c5448e500c90 320 //camera.js
dkato 0:c5448e500c90 321 fp = fopen("/romram/camera.js", "w");
dkato 0:c5448e500c90 322 fwrite(camaera_js_tbl, sizeof(char), sizeof(camaera_js_tbl), fp);
dkato 0:c5448e500c90 323 fclose(fp);
dkato 0:c5448e500c90 324
dkato 0:c5448e500c90 325 //camera.htm
dkato 0:c5448e500c90 326 fp = fopen("/romram/camera.htm", "w");
dkato 0:c5448e500c90 327 fwrite(camera_htm_tbl, sizeof(char), sizeof(camera_htm_tbl), fp);
dkato 0:c5448e500c90 328 fclose(fp);
dkato 0:c5448e500c90 329
dkato 0:c5448e500c90 330 //mbedrpc.js
dkato 0:c5448e500c90 331 fp = fopen("/romram/mbedrpc.js", "w");
dkato 0:c5448e500c90 332 fwrite(mbedrpc_js_tbl, sizeof(char), sizeof(mbedrpc_js_tbl), fp);
dkato 0:c5448e500c90 333 fclose(fp);
dkato 0:c5448e500c90 334
dkato 0:c5448e500c90 335 //led.htm
dkato 0:c5448e500c90 336 fp = fopen("/romram/led.htm", "w");
dkato 0:c5448e500c90 337 fwrite(led_htm_tbl, sizeof(char), sizeof(led_htm_tbl), fp);
dkato 0:c5448e500c90 338 fclose(fp);
1050186 5:34d84609dd60 339
1050186 5:34d84609dd60 340 //i2c_set.htm
1050186 5:34d84609dd60 341 fp = fopen("/romram/i2c_set.htm", "w");
1050186 5:34d84609dd60 342 fwrite(i2c_set_htm_tbl, sizeof(char), sizeof(i2c_set_htm_tbl), fp);
1050186 5:34d84609dd60 343 fclose(fp);
1050186 5:34d84609dd60 344
1050186 5:34d84609dd60 345 //web_top.htm
1050186 5:34d84609dd60 346 fp = fopen("/romram/web_top.htm", "w");
1050186 5:34d84609dd60 347 fwrite(web_top_htm_tbl, sizeof(char), sizeof(web_top_htm_tbl), fp);
1050186 5:34d84609dd60 348 fclose(fp);
1050186 5:34d84609dd60 349
1050186 5:34d84609dd60 350 //menu.htm
1050186 5:34d84609dd60 351 fp = fopen("/romram/menu.htm", "w");
1050186 5:34d84609dd60 352 fwrite(menu_htm_tbl, sizeof(char), sizeof(menu_htm_tbl), fp);
1050186 5:34d84609dd60 353 fclose(fp);
1050186 5:34d84609dd60 354
1050186 5:34d84609dd60 355 //window.htm
1050186 5:34d84609dd60 356 fp = fopen("/romram/window.htm", "w");
1050186 5:34d84609dd60 357 fwrite(window_htm_tbl, sizeof(char), sizeof(window_htm_tbl), fp);
1050186 5:34d84609dd60 358 fclose(fp);
1050186 5:34d84609dd60 359 }
1050186 5:34d84609dd60 360
1050186 5:34d84609dd60 361 static void SetI2CfromWeb(Arguments* arg, Reply* r) {
1050186 10:3a176dc33f74 362 int result = 0;
1050186 10:3a176dc33f74 363
1050186 10:3a176dc33f74 364 if (arg != NULL) {
1050186 10:3a176dc33f74 365 if (arg->argc >= 2) {
1050186 10:3a176dc33f74 366 if ((arg->argv[0] != NULL) && (arg->argv[1] != NULL)) {
1050186 10:3a176dc33f74 367 sprintf(i2c_setting_str_buf, "%s,%s", arg->argv[0], arg->argv[1]);
1050186 10:3a176dc33f74 368 result = 1;
1050186 10:3a176dc33f74 369 }
1050186 10:3a176dc33f74 370 } else if (arg->argc == 1) {
1050186 10:3a176dc33f74 371 if (arg->argv[0] != NULL) {
1050186 10:3a176dc33f74 372 sprintf(i2c_setting_str_buf, "%s", arg->argv[0]);
1050186 10:3a176dc33f74 373 result = 1;
1050186 10:3a176dc33f74 374 }
1050186 10:3a176dc33f74 375 } else {
1050186 10:3a176dc33f74 376 /* Do nothing */
1050186 10:3a176dc33f74 377 }
dkato 7:c45ecff1b44d 378 /* command analysis and execute */
1050186 10:3a176dc33f74 379 if (result != 0) {
1050186 10:3a176dc33f74 380 if (i2c_setting_exe(i2c_setting_str_buf) != false) {
1050186 10:3a176dc33f74 381 r->putData<const char*>(i2c_setting_str_buf);
1050186 10:3a176dc33f74 382 }
1050186 5:34d84609dd60 383 }
1050186 5:34d84609dd60 384 }
dkato 0:c5448e500c90 385 }
dkato 0:c5448e500c90 386
dkato 17:2648bcf3f2cc 387 #if (SCAN_NETWORK == 1)
dkato 17:2648bcf3f2cc 388 static void scan_network(void) {
dkato 17:2648bcf3f2cc 389 int num;
dkato 17:2648bcf3f2cc 390 int i;
dkato 17:2648bcf3f2cc 391 int select_no;
dkato 17:2648bcf3f2cc 392 bool loop_break;
dkato 17:2648bcf3f2cc 393 char ch;
dkato 17:2648bcf3f2cc 394 char pass[64];
dkato 17:2648bcf3f2cc 395 const uint8_t *wk_p;
dkato 17:2648bcf3f2cc 396 WiFiAccessPoint point[8];
dkato 17:2648bcf3f2cc 397
dkato 17:2648bcf3f2cc 398 while (1) {
dkato 17:2648bcf3f2cc 399 printf("scan...\n");
dkato 17:2648bcf3f2cc 400 num = network.scan(point, 8);
dkato 17:2648bcf3f2cc 401 for (i = 0; i < num; i++) {
dkato 17:2648bcf3f2cc 402 printf(" No.%d\n", i);
dkato 17:2648bcf3f2cc 403 printf(" ssid :%s\n", point[i].get_ssid());
dkato 17:2648bcf3f2cc 404 wk_p = point[i].get_bssid();
dkato 17:2648bcf3f2cc 405 printf(" bssid :0x%02x,0x%02x,0x%02x,0x%02x,0x%02x,0x%02x\n",
dkato 17:2648bcf3f2cc 406 wk_p[0],wk_p[1],wk_p[2],wk_p[3],wk_p[4],wk_p[5]);
dkato 17:2648bcf3f2cc 407 printf(" security:");
dkato 17:2648bcf3f2cc 408 switch (point[i].get_security()) {
dkato 17:2648bcf3f2cc 409 case NSAPI_SECURITY_NONE:
dkato 17:2648bcf3f2cc 410 printf("NONE\n");
dkato 17:2648bcf3f2cc 411 break;
dkato 17:2648bcf3f2cc 412 case NSAPI_SECURITY_WPA:
dkato 17:2648bcf3f2cc 413 printf("WPA\n");
dkato 17:2648bcf3f2cc 414 break;
dkato 17:2648bcf3f2cc 415 case NSAPI_SECURITY_WPA2:
dkato 17:2648bcf3f2cc 416 printf("WPA2\n");
dkato 17:2648bcf3f2cc 417 break;
dkato 17:2648bcf3f2cc 418 case NSAPI_SECURITY_WPA_WPA2:
dkato 17:2648bcf3f2cc 419 printf("WPA_WPA2\n");
dkato 17:2648bcf3f2cc 420 break;
dkato 17:2648bcf3f2cc 421 case NSAPI_SECURITY_UNKNOWN:
dkato 17:2648bcf3f2cc 422 default:
dkato 17:2648bcf3f2cc 423 printf("UNKNOWN\n");
dkato 17:2648bcf3f2cc 424 break;
dkato 17:2648bcf3f2cc 425 }
dkato 17:2648bcf3f2cc 426 printf(" rssi :%d\n", point[i].get_rssi());
dkato 17:2648bcf3f2cc 427 printf(" channel :%d\n", point[i].get_channel());
dkato 17:2648bcf3f2cc 428 }
dkato 17:2648bcf3f2cc 429 if (num > 0) {
dkato 17:2648bcf3f2cc 430 printf("\nPlease enter the number of the network you want to connect.\n");
dkato 17:2648bcf3f2cc 431 printf("Enter key:[0]-[%d], (If inputting the other key, it's scanned again.)\n", num - 1);
dkato 17:2648bcf3f2cc 432 ch = (uint8_t)pc.getc();
dkato 17:2648bcf3f2cc 433 select_no = ch - 0x30;
dkato 17:2648bcf3f2cc 434 if ((select_no >= 0) && (select_no < num)) {
dkato 17:2648bcf3f2cc 435 printf("[%s] is selected.\n", point[select_no].get_ssid());
dkato 17:2648bcf3f2cc 436 printf("Please enter the PSK.\n");
dkato 17:2648bcf3f2cc 437 loop_break = false;
dkato 17:2648bcf3f2cc 438 i = 0;
dkato 17:2648bcf3f2cc 439 while (loop_break == false) {
dkato 17:2648bcf3f2cc 440 ch = (uint8_t)pc.getc();
dkato 17:2648bcf3f2cc 441 switch (ch) {
dkato 17:2648bcf3f2cc 442 case 0x0D:
dkato 17:2648bcf3f2cc 443 pass[i] = '\0';
dkato 17:2648bcf3f2cc 444 pc.puts("\r\n");
dkato 17:2648bcf3f2cc 445 loop_break = true;
dkato 17:2648bcf3f2cc 446 break;
dkato 17:2648bcf3f2cc 447 case 0x08:
dkato 17:2648bcf3f2cc 448 if (i > 0) {
dkato 17:2648bcf3f2cc 449 pc.puts("\b \b");
dkato 17:2648bcf3f2cc 450 i--;
dkato 17:2648bcf3f2cc 451 }
dkato 17:2648bcf3f2cc 452 break;
dkato 17:2648bcf3f2cc 453 case 0x0A:
dkato 17:2648bcf3f2cc 454 break;
dkato 17:2648bcf3f2cc 455 default:
dkato 17:2648bcf3f2cc 456 if ((i + 1) < sizeof(pass)) {
dkato 17:2648bcf3f2cc 457 pass[i] = ch;
dkato 17:2648bcf3f2cc 458 i++;
dkato 17:2648bcf3f2cc 459 pc.putc(ch);
dkato 17:2648bcf3f2cc 460 }
dkato 17:2648bcf3f2cc 461 break;
dkato 17:2648bcf3f2cc 462 }
dkato 17:2648bcf3f2cc 463 }
dkato 17:2648bcf3f2cc 464 printf("connecting...\n");
dkato 17:2648bcf3f2cc 465 network.set_credentials(point[select_no].get_ssid(), pass, point[select_no].get_security());
dkato 17:2648bcf3f2cc 466 break;
dkato 17:2648bcf3f2cc 467 }
dkato 17:2648bcf3f2cc 468 }
dkato 17:2648bcf3f2cc 469 }
dkato 17:2648bcf3f2cc 470 }
dkato 17:2648bcf3f2cc 471 #endif
dkato 17:2648bcf3f2cc 472
dkato 0:c5448e500c90 473 int main(void) {
dkato 0:c5448e500c90 474 printf("********* PROGRAM START ***********\r\n");
dkato 0:c5448e500c90 475
1050186 5:34d84609dd60 476 /* Please enable this line when performing the setting from the Terminal side. */
1050186 5:34d84609dd60 477 // Thread thread(SetI2CfromTerm, NULL, osPriorityBelowNormal, DEFAULT_STACK_SIZE);
1050186 5:34d84609dd60 478
dkato 0:c5448e500c90 479 mount_romramfs(); //RomRamFileSystem Mount
dkato 0:c5448e500c90 480 camera_start(); //Camera Start
dkato 0:c5448e500c90 481
dkato 0:c5448e500c90 482 RPC::add_rpc_class<RpcDigitalOut>();
dkato 0:c5448e500c90 483 RPC::construct<RpcDigitalOut, PinName, const char*>(LED1, "led1");
dkato 0:c5448e500c90 484 RPC::construct<RpcDigitalOut, PinName, const char*>(LED2, "led2");
dkato 0:c5448e500c90 485 RPC::construct<RpcDigitalOut, PinName, const char*>(LED3, "led3");
dkato 0:c5448e500c90 486 RPCFunction rpcFunc(TerminalWrite, "TerminalWrite");
1050186 5:34d84609dd60 487 RPCFunction rpcSetI2C(SetI2CfromWeb, "SetI2CfromWeb");
dkato 0:c5448e500c90 488
dkato 15:eac4c3711aab 489 #if (NETWORK_TYPE == 1)
dkato 15:eac4c3711aab 490 //Audio Camera Shield USB1 enable for WlanBP3595
dkato 15:eac4c3711aab 491 usb1en = 1; //Outputs high level
dkato 15:eac4c3711aab 492 Thread::wait(5);
dkato 15:eac4c3711aab 493 usb1en = 0; //Outputs low level
dkato 15:eac4c3711aab 494 Thread::wait(5);
dkato 15:eac4c3711aab 495 #endif
dkato 15:eac4c3711aab 496
dkato 11:ad8ff26679bb 497 printf("Network Setting up...\r\n");
dkato 17:2648bcf3f2cc 498 #if (USE_DHCP == 0)
dkato 17:2648bcf3f2cc 499 network.set_dhcp(false);
dkato 17:2648bcf3f2cc 500 if (network.set_network(IP_ADDRESS, SUBNET_MASK, DEFAULT_GATEWAY) != 0) { //for Static IP Address (IPAddress, NetMasks, Gateway)
dkato 17:2648bcf3f2cc 501 printf("Network Set Network Error \r\n");
dkato 0:c5448e500c90 502 return -1;
dkato 0:c5448e500c90 503 }
dkato 17:2648bcf3f2cc 504 #endif
dkato 17:2648bcf3f2cc 505
dkato 17:2648bcf3f2cc 506 #if (NETWORK_TYPE == 1)
dkato 17:2648bcf3f2cc 507 #if (SCAN_NETWORK == 1)
dkato 17:2648bcf3f2cc 508 scan_network();
dkato 15:eac4c3711aab 509 #else
dkato 17:2648bcf3f2cc 510 network.set_credentials(WLAN_SSID, WLAN_PSK, WLAN_SECURITY);
dkato 17:2648bcf3f2cc 511 #endif
dkato 15:eac4c3711aab 512 #endif
dkato 17:2648bcf3f2cc 513
dkato 17:2648bcf3f2cc 514 if (network.connect() != 0) {
dkato 11:ad8ff26679bb 515 printf("Network Connect Error \r\n");
dkato 0:c5448e500c90 516 return -1;
dkato 0:c5448e500c90 517 }
dkato 17:2648bcf3f2cc 518
dkato 17:2648bcf3f2cc 519 printf("MbsAC Address is %s\r\n", network.get_mac_address());
dkato 17:2648bcf3f2cc 520 printf("IP Address is %s\r\n", network.get_ip_address());
dkato 17:2648bcf3f2cc 521 printf("NetMask is %s\r\n", network.get_netmask());
dkato 17:2648bcf3f2cc 522 printf("Gateway Address is %s\r\n", network.get_gateway());
dkato 11:ad8ff26679bb 523 printf("Network Setup OK\r\n");
dkato 0:c5448e500c90 524
dkato 0:c5448e500c90 525 SnapshotHandler::attach_req(&snapshot_req);
dkato 0:c5448e500c90 526 HTTPServerAddHandler<SnapshotHandler>("/camera"); //Camera
dkato 0:c5448e500c90 527 FSHandler::mount("/romram", "/");
dkato 0:c5448e500c90 528 HTTPServerAddHandler<FSHandler>("/");
dkato 0:c5448e500c90 529 HTTPServerAddHandler<RPCHandler>("/rpc");
dkato 17:2648bcf3f2cc 530 HTTPServerStart(&network, 80);
dkato 0:c5448e500c90 531 }