Change to wifi AP mode. SSID "GR-PEACH_1", PSK "12345"
Dependencies: DhcpServer EthernetInterface FATFileSystem GR-PEACH_WlanBP3595AP GR-PEACH_video GraphicsFramework HttpServer_snapshot R_BSP mbed-rpc mbed-rtos mbed
Fork of GR-Boards_WebCamera by
main.cpp@17:493d36f1febf, 2016-09-07 (annotated)
- Committer:
- dkato
- Date:
- Wed Sep 07 08:28:18 2016 +0000
- Revision:
- 17:493d36f1febf
- Parent:
- 16:b5469a6226c7
Change to wifi AP mode.
Who changed what in which revision?
User | Revision | Line number | New 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 | 17:493d36f1febf | 10 | #include "DhcpServer.h" |
dkato | 0:c5448e500c90 | 11 | |
dkato | 0:c5448e500c90 | 12 | #define VIDEO_CVBS (0) /* Analog Video Signal */ |
dkato | 0:c5448e500c90 | 13 | #define VIDEO_CMOS_CAMERA (1) /* Digital Video Signal */ |
dkato | 0:c5448e500c90 | 14 | #define VIDEO_YCBCR422 (0) |
dkato | 0:c5448e500c90 | 15 | #define VIDEO_RGB888 (1) |
dkato | 0:c5448e500c90 | 16 | #define VIDEO_RGB565 (2) |
dkato | 0:c5448e500c90 | 17 | |
dkato | 0:c5448e500c90 | 18 | /**** User Selection *********/ |
dkato | 11:ad8ff26679bb | 19 | /** Network setting **/ |
dkato | 17:493d36f1febf | 20 | #define USE_DHCP (0) /* Select 0(static configuration) or 1(use DHCP) */ |
dkato | 11:ad8ff26679bb | 21 | #if (USE_DHCP == 0) |
dkato | 11:ad8ff26679bb | 22 | #define IP_ADDRESS ("192.168.0.2") /* IP address */ |
dkato | 11:ad8ff26679bb | 23 | #define SUBNET_MASK ("255.255.255.0") /* Subnet mask */ |
dkato | 11:ad8ff26679bb | 24 | #define DEFAULT_GATEWAY ("192.168.0.3") /* Default gateway */ |
dkato | 11:ad8ff26679bb | 25 | #endif |
dkato | 17:493d36f1febf | 26 | #define NETWORK_TYPE (1) /* Select 0(EthernetInterface) or 1(GR_PEACH_WlanBP3595) */ |
dkato | 15:eac4c3711aab | 27 | #if (NETWORK_TYPE == 1) |
dkato | 17:493d36f1febf | 28 | #define WLAN_SSID ("GR-PEACH_1") /* SSID */ |
dkato | 17:493d36f1febf | 29 | #define WLAN_PSK ("12345") /* PSK(Pre-Shared Key) */ |
dkato | 17:493d36f1febf | 30 | #define WLAN_SECURITY NSAPI_SECURITY_WEP /* NSAPI_SECURITY_NONE, NSAPI_SECURITY_WEP, NSAPI_SECURITY_WPA or NSAPI_SECURITY_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 | 15:eac4c3711aab | 65 | #include "GR_PEACH_WlanBP3595.h" |
dkato | 15:eac4c3711aab | 66 | GR_PEACH_WlanBP3595 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 | 0:c5448e500c90 | 72 | |
dkato | 14:212f66386982 | 73 | #if defined(__ICCARM__) |
dkato | 14:212f66386982 | 74 | #pragma data_alignment=16 |
dkato | 14:212f66386982 | 75 | static uint8_t FrameBuffer_Video[VIDEO_BUFFER_STRIDE * VIDEO_BUFFER_HEIGHT]@ ".mirrorram"; //16 bytes aligned!; |
dkato | 14:212f66386982 | 76 | #pragma data_alignment=4 |
dkato | 14:212f66386982 | 77 | #else |
dkato | 0:c5448e500c90 | 78 | static uint8_t FrameBuffer_Video[VIDEO_BUFFER_STRIDE * VIDEO_BUFFER_HEIGHT]__attribute((section("NC_BSS"),aligned(16))); //16 bytes aligned!; |
dkato | 14:212f66386982 | 79 | #endif |
dkato | 0:c5448e500c90 | 80 | static volatile int32_t vsync_count = 0; |
dkato | 0:c5448e500c90 | 81 | static volatile int32_t vfield_count = 1; |
dkato | 14:212f66386982 | 82 | #if defined(__ICCARM__) |
dkato | 14:212f66386982 | 83 | #pragma data_alignment=8 |
dkato | 14:212f66386982 | 84 | static uint8_t JpegBuffer[2][1024 * 50]@ ".mirrorram"; //8 bytes aligned!; |
dkato | 14:212f66386982 | 85 | #pragma data_alignment=4 |
dkato | 14:212f66386982 | 86 | #else |
dkato | 1:ebff3aeb40a0 | 87 | static uint8_t JpegBuffer[2][1024 * 50]__attribute((section("NC_BSS"),aligned(8))); //8 bytes aligned!; |
dkato | 14:212f66386982 | 88 | #endif |
dkato | 1:ebff3aeb40a0 | 89 | static size_t jcu_encode_size[2]; |
dkato | 0:c5448e500c90 | 90 | static int image_change = 0; |
dkato | 1:ebff3aeb40a0 | 91 | JPEG_Converter Jcu; |
dkato | 1:ebff3aeb40a0 | 92 | static int jcu_buf_index_write = 0; |
dkato | 1:ebff3aeb40a0 | 93 | static int jcu_buf_index_write_done = 0; |
dkato | 1:ebff3aeb40a0 | 94 | static int jcu_buf_index_read = 0; |
dkato | 1:ebff3aeb40a0 | 95 | static int jcu_encoding = 0; |
dkato | 7:c45ecff1b44d | 96 | static char i2c_setting_str_buf[I2C_SETTING_STR_BUF_SIZE]; |
dkato | 1:ebff3aeb40a0 | 97 | |
dkato | 1:ebff3aeb40a0 | 98 | static void JcuEncodeCallBackFunc(JPEG_Converter::jpeg_conv_error_t err_code) { |
dkato | 1:ebff3aeb40a0 | 99 | jcu_buf_index_write_done = jcu_buf_index_write; |
dkato | 1:ebff3aeb40a0 | 100 | image_change = 1; |
dkato | 1:ebff3aeb40a0 | 101 | jcu_encoding = 0; |
dkato | 1:ebff3aeb40a0 | 102 | } |
dkato | 0:c5448e500c90 | 103 | |
dkato | 0:c5448e500c90 | 104 | static void IntCallbackFunc_Vfield(DisplayBase::int_type_t int_type) { |
dkato | 0:c5448e500c90 | 105 | //Interrupt callback function |
dkato | 0:c5448e500c90 | 106 | if (vfield_count != 0) { |
dkato | 0:c5448e500c90 | 107 | vfield_count = 0; |
dkato | 0:c5448e500c90 | 108 | } else { |
dkato | 0:c5448e500c90 | 109 | vfield_count = 1; |
dkato | 1:ebff3aeb40a0 | 110 | |
dkato | 1:ebff3aeb40a0 | 111 | JPEG_Converter::bitmap_buff_info_t bitmap_buff_info; |
dkato | 1:ebff3aeb40a0 | 112 | JPEG_Converter::encode_options_t encode_options; |
dkato | 1:ebff3aeb40a0 | 113 | |
dkato | 1:ebff3aeb40a0 | 114 | bitmap_buff_info.width = PIXEL_HW; |
dkato | 1:ebff3aeb40a0 | 115 | bitmap_buff_info.height = PIXEL_VW; |
dkato | 1:ebff3aeb40a0 | 116 | bitmap_buff_info.format = JPEG_Converter::WR_RD_YCbCr422; |
dkato | 1:ebff3aeb40a0 | 117 | bitmap_buff_info.buffer_address = (void *)FrameBuffer_Video; |
dkato | 1:ebff3aeb40a0 | 118 | |
dkato | 1:ebff3aeb40a0 | 119 | encode_options.encode_buff_size = sizeof(JpegBuffer[0]); |
dkato | 1:ebff3aeb40a0 | 120 | encode_options.p_EncodeCallBackFunc = &JcuEncodeCallBackFunc; |
dkato | 1:ebff3aeb40a0 | 121 | |
dkato | 1:ebff3aeb40a0 | 122 | jcu_encoding = 1; |
dkato | 1:ebff3aeb40a0 | 123 | if (jcu_buf_index_read == jcu_buf_index_write) { |
dkato | 1:ebff3aeb40a0 | 124 | if (jcu_buf_index_write != 0) { |
dkato | 1:ebff3aeb40a0 | 125 | jcu_buf_index_write = 0; |
dkato | 1:ebff3aeb40a0 | 126 | } else { |
dkato | 1:ebff3aeb40a0 | 127 | jcu_buf_index_write = 1; |
dkato | 1:ebff3aeb40a0 | 128 | } |
dkato | 1:ebff3aeb40a0 | 129 | } |
dkato | 1:ebff3aeb40a0 | 130 | jcu_encode_size[jcu_buf_index_write] = 0; |
dkato | 1:ebff3aeb40a0 | 131 | 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 | 132 | jcu_encode_size[jcu_buf_index_write] = 0; |
dkato | 1:ebff3aeb40a0 | 133 | jcu_encoding = 0; |
dkato | 1:ebff3aeb40a0 | 134 | } |
dkato | 0:c5448e500c90 | 135 | } |
dkato | 0:c5448e500c90 | 136 | } |
dkato | 0:c5448e500c90 | 137 | |
dkato | 0:c5448e500c90 | 138 | static void IntCallbackFunc_Vsync(DisplayBase::int_type_t int_type) { |
dkato | 0:c5448e500c90 | 139 | //Interrupt callback function for Vsync interruption |
dkato | 0:c5448e500c90 | 140 | if (vsync_count > 0) { |
dkato | 0:c5448e500c90 | 141 | vsync_count--; |
dkato | 0:c5448e500c90 | 142 | } |
dkato | 0:c5448e500c90 | 143 | } |
dkato | 0:c5448e500c90 | 144 | |
dkato | 0:c5448e500c90 | 145 | static void WaitVsync(const int32_t wait_count) { |
dkato | 0:c5448e500c90 | 146 | //Wait for the specified number of times Vsync occurs |
dkato | 0:c5448e500c90 | 147 | vsync_count = wait_count; |
dkato | 0:c5448e500c90 | 148 | while (vsync_count > 0) { |
dkato | 0:c5448e500c90 | 149 | /* Do nothing */ |
dkato | 0:c5448e500c90 | 150 | } |
dkato | 0:c5448e500c90 | 151 | } |
dkato | 0:c5448e500c90 | 152 | |
dkato | 0:c5448e500c90 | 153 | static void camera_start(void) { |
dkato | 0:c5448e500c90 | 154 | DisplayBase::graphics_error_t error; |
dkato | 0:c5448e500c90 | 155 | |
dkato | 0:c5448e500c90 | 156 | #if VIDEO_INPUT_METHOD == VIDEO_CMOS_CAMERA |
dkato | 0:c5448e500c90 | 157 | DisplayBase::video_ext_in_config_t ext_in_config; |
dkato | 0:c5448e500c90 | 158 | PinName cmos_camera_pin[11] = { |
dkato | 0:c5448e500c90 | 159 | /* data pin */ |
dkato | 0:c5448e500c90 | 160 | P2_7, P2_6, P2_5, P2_4, P2_3, P2_2, P2_1, P2_0, |
dkato | 0:c5448e500c90 | 161 | /* control pin */ |
dkato | 0:c5448e500c90 | 162 | P10_0, /* DV0_CLK */ |
dkato | 0:c5448e500c90 | 163 | P1_0, /* DV0_Vsync */ |
dkato | 0:c5448e500c90 | 164 | P1_1 /* DV0_Hsync */ |
dkato | 0:c5448e500c90 | 165 | }; |
dkato | 0:c5448e500c90 | 166 | #endif |
dkato | 0:c5448e500c90 | 167 | |
dkato | 0:c5448e500c90 | 168 | /* Create DisplayBase object */ |
dkato | 0:c5448e500c90 | 169 | DisplayBase Display; |
dkato | 0:c5448e500c90 | 170 | |
dkato | 0:c5448e500c90 | 171 | /* Graphics initialization process */ |
dkato | 0:c5448e500c90 | 172 | error = Display.Graphics_init(NULL); |
dkato | 0:c5448e500c90 | 173 | if (error != DisplayBase::GRAPHICS_OK) { |
dkato | 0:c5448e500c90 | 174 | printf("Line %d, error %d\n", __LINE__, error); |
dkato | 0:c5448e500c90 | 175 | while (1); |
dkato | 0:c5448e500c90 | 176 | } |
dkato | 0:c5448e500c90 | 177 | |
dkato | 0:c5448e500c90 | 178 | #if VIDEO_INPUT_METHOD == VIDEO_CVBS |
dkato | 0:c5448e500c90 | 179 | error = Display.Graphics_Video_init( DisplayBase::INPUT_SEL_VDEC, NULL); |
dkato | 0:c5448e500c90 | 180 | if( error != DisplayBase::GRAPHICS_OK ) { |
dkato | 0:c5448e500c90 | 181 | printf("Line %d, error %d\n", __LINE__, error); |
dkato | 0:c5448e500c90 | 182 | while(1); |
dkato | 0:c5448e500c90 | 183 | } |
dkato | 0:c5448e500c90 | 184 | |
dkato | 0:c5448e500c90 | 185 | #elif VIDEO_INPUT_METHOD == VIDEO_CMOS_CAMERA |
dkato | 0:c5448e500c90 | 186 | /* MT9V111 camera input config */ |
dkato | 0:c5448e500c90 | 187 | ext_in_config.inp_format = DisplayBase::VIDEO_EXTIN_FORMAT_BT601; /* BT601 8bit YCbCr format */ |
dkato | 0:c5448e500c90 | 188 | ext_in_config.inp_pxd_edge = DisplayBase::EDGE_RISING; /* Clock edge select for capturing data */ |
dkato | 0:c5448e500c90 | 189 | ext_in_config.inp_vs_edge = DisplayBase::EDGE_RISING; /* Clock edge select for capturing Vsync signals */ |
dkato | 0:c5448e500c90 | 190 | ext_in_config.inp_hs_edge = DisplayBase::EDGE_RISING; /* Clock edge select for capturing Hsync signals */ |
dkato | 0:c5448e500c90 | 191 | ext_in_config.inp_endian_on = DisplayBase::OFF; /* External input bit endian change on/off */ |
dkato | 0:c5448e500c90 | 192 | ext_in_config.inp_swap_on = DisplayBase::OFF; /* External input B/R signal swap on/off */ |
dkato | 0:c5448e500c90 | 193 | ext_in_config.inp_vs_inv = DisplayBase::SIG_POL_NOT_INVERTED; /* External input DV_VSYNC inversion control */ |
dkato | 0:c5448e500c90 | 194 | ext_in_config.inp_hs_inv = DisplayBase::SIG_POL_INVERTED; /* External input DV_HSYNC inversion control */ |
dkato | 0:c5448e500c90 | 195 | ext_in_config.inp_f525_625 = DisplayBase::EXTIN_LINE_525; /* Number of lines for BT.656 external input */ |
dkato | 0:c5448e500c90 | 196 | 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 | 197 | ext_in_config.cap_vs_pos = 6; /* Capture start position from Vsync */ |
dkato | 0:c5448e500c90 | 198 | ext_in_config.cap_hs_pos = 150; /* Capture start position form Hsync */ |
dkato | 0:c5448e500c90 | 199 | ext_in_config.cap_width = 640; /* Capture width */ |
dkato | 0:c5448e500c90 | 200 | ext_in_config.cap_height = 468u; /* Capture height Max 468[line] |
dkato | 0:c5448e500c90 | 201 | Due to CMOS(MT9V111) output signal timing and VDC5 specification */ |
dkato | 0:c5448e500c90 | 202 | error = Display.Graphics_Video_init( DisplayBase::INPUT_SEL_EXT, &ext_in_config); |
dkato | 0:c5448e500c90 | 203 | if( error != DisplayBase::GRAPHICS_OK ) { |
dkato | 0:c5448e500c90 | 204 | printf("Line %d, error %d\n", __LINE__, error); |
dkato | 0:c5448e500c90 | 205 | while(1); |
dkato | 0:c5448e500c90 | 206 | } |
dkato | 0:c5448e500c90 | 207 | |
dkato | 0:c5448e500c90 | 208 | /* MT9V111 camera input port setting */ |
dkato | 0:c5448e500c90 | 209 | error = Display.Graphics_Dvinput_Port_Init(cmos_camera_pin, 11); |
dkato | 0:c5448e500c90 | 210 | if( error != DisplayBase::GRAPHICS_OK ) { |
dkato | 0:c5448e500c90 | 211 | printf("Line %d, error %d\n", __LINE__, error); |
dkato | 0:c5448e500c90 | 212 | while (1); |
dkato | 0:c5448e500c90 | 213 | } |
dkato | 0:c5448e500c90 | 214 | #endif |
dkato | 0:c5448e500c90 | 215 | |
dkato | 0:c5448e500c90 | 216 | /* Interrupt callback function setting (Vsync signal input to scaler 0) */ |
dkato | 0:c5448e500c90 | 217 | error = Display.Graphics_Irq_Handler_Set(DisplayBase::INT_TYPE_S0_VI_VSYNC, 0, IntCallbackFunc_Vsync); |
dkato | 0:c5448e500c90 | 218 | if (error != DisplayBase::GRAPHICS_OK) { |
dkato | 0:c5448e500c90 | 219 | printf("Line %d, error %d\n", __LINE__, error); |
dkato | 0:c5448e500c90 | 220 | while (1); |
dkato | 0:c5448e500c90 | 221 | } |
dkato | 0:c5448e500c90 | 222 | /* Video capture setting (progressive form fixed) */ |
dkato | 0:c5448e500c90 | 223 | error = Display.Video_Write_Setting( |
dkato | 0:c5448e500c90 | 224 | VIDEO_INPUT_CH, |
dkato | 0:c5448e500c90 | 225 | #if VIDEO_PAL == 0 |
dkato | 0:c5448e500c90 | 226 | DisplayBase::COL_SYS_NTSC_358, |
dkato | 0:c5448e500c90 | 227 | #else |
dkato | 0:c5448e500c90 | 228 | DisplayBase::COL_SYS_PAL_443, |
dkato | 0:c5448e500c90 | 229 | #endif |
dkato | 0:c5448e500c90 | 230 | FrameBuffer_Video, |
dkato | 0:c5448e500c90 | 231 | VIDEO_BUFFER_STRIDE, |
dkato | 0:c5448e500c90 | 232 | #if VIDEO_INPUT_FORMAT == VIDEO_YCBCR422 |
dkato | 0:c5448e500c90 | 233 | DisplayBase::VIDEO_FORMAT_YCBCR422, |
dkato | 0:c5448e500c90 | 234 | DisplayBase::WR_RD_WRSWA_NON, |
dkato | 0:c5448e500c90 | 235 | #elif VIDEO_INPUT_FORMAT == VIDEO_RGB565 |
dkato | 0:c5448e500c90 | 236 | DisplayBase::VIDEO_FORMAT_RGB565, |
dkato | 0:c5448e500c90 | 237 | DisplayBase::WR_RD_WRSWA_32_16BIT, |
dkato | 0:c5448e500c90 | 238 | #else |
dkato | 0:c5448e500c90 | 239 | DisplayBase::VIDEO_FORMAT_RGB888, |
dkato | 0:c5448e500c90 | 240 | DisplayBase::WR_RD_WRSWA_32BIT, |
dkato | 0:c5448e500c90 | 241 | #endif |
dkato | 0:c5448e500c90 | 242 | PIXEL_VW, |
dkato | 0:c5448e500c90 | 243 | PIXEL_HW |
dkato | 0:c5448e500c90 | 244 | ); |
dkato | 0:c5448e500c90 | 245 | if (error != DisplayBase::GRAPHICS_OK) { |
dkato | 0:c5448e500c90 | 246 | printf("Line %d, error %d\n", __LINE__, error); |
dkato | 0:c5448e500c90 | 247 | while (1); |
dkato | 0:c5448e500c90 | 248 | } |
dkato | 0:c5448e500c90 | 249 | |
dkato | 0:c5448e500c90 | 250 | /* Interrupt callback function setting (Field end signal for recording function in scaler 0) */ |
dkato | 0:c5448e500c90 | 251 | error = Display.Graphics_Irq_Handler_Set(VIDEO_INT_TYPE, 0, IntCallbackFunc_Vfield); |
dkato | 0:c5448e500c90 | 252 | if (error != DisplayBase::GRAPHICS_OK) { |
dkato | 0:c5448e500c90 | 253 | printf("Line %d, error %d\n", __LINE__, error); |
dkato | 0:c5448e500c90 | 254 | while (1); |
dkato | 0:c5448e500c90 | 255 | } |
dkato | 0:c5448e500c90 | 256 | |
dkato | 0:c5448e500c90 | 257 | /* Video write process start */ |
dkato | 0:c5448e500c90 | 258 | error = Display.Video_Start (VIDEO_INPUT_CH); |
dkato | 0:c5448e500c90 | 259 | if (error != DisplayBase::GRAPHICS_OK) { |
dkato | 0:c5448e500c90 | 260 | printf("Line %d, error %d\n", __LINE__, error); |
dkato | 0:c5448e500c90 | 261 | while (1); |
dkato | 0:c5448e500c90 | 262 | } |
dkato | 0:c5448e500c90 | 263 | |
dkato | 0:c5448e500c90 | 264 | /* Video write process stop */ |
dkato | 0:c5448e500c90 | 265 | error = Display.Video_Stop (VIDEO_INPUT_CH); |
dkato | 0:c5448e500c90 | 266 | if (error != DisplayBase::GRAPHICS_OK) { |
dkato | 0:c5448e500c90 | 267 | printf("Line %d, error %d\n", __LINE__, error); |
dkato | 0:c5448e500c90 | 268 | while (1); |
dkato | 0:c5448e500c90 | 269 | } |
dkato | 0:c5448e500c90 | 270 | |
dkato | 0:c5448e500c90 | 271 | /* Video write process start */ |
dkato | 0:c5448e500c90 | 272 | error = Display.Video_Start (VIDEO_INPUT_CH); |
dkato | 0:c5448e500c90 | 273 | if (error != DisplayBase::GRAPHICS_OK) { |
dkato | 0:c5448e500c90 | 274 | printf("Line %d, error %d\n", __LINE__, error); |
dkato | 0:c5448e500c90 | 275 | while (1); |
dkato | 0:c5448e500c90 | 276 | } |
dkato | 0:c5448e500c90 | 277 | |
dkato | 0:c5448e500c90 | 278 | /* Wait vsync to update resister */ |
dkato | 0:c5448e500c90 | 279 | WaitVsync(1); |
dkato | 0:c5448e500c90 | 280 | } |
dkato | 0:c5448e500c90 | 281 | |
dkato | 0:c5448e500c90 | 282 | static int snapshot_req(const char ** pp_data) { |
dkato | 1:ebff3aeb40a0 | 283 | int encode_size; |
dkato | 0:c5448e500c90 | 284 | |
dkato | 1:ebff3aeb40a0 | 285 | while ((jcu_encoding == 1) || (image_change == 0)) { |
dkato | 0:c5448e500c90 | 286 | Thread::wait(1); |
dkato | 0:c5448e500c90 | 287 | } |
dkato | 1:ebff3aeb40a0 | 288 | jcu_buf_index_read = jcu_buf_index_write_done; |
dkato | 0:c5448e500c90 | 289 | image_change = 0; |
dkato | 0:c5448e500c90 | 290 | |
dkato | 1:ebff3aeb40a0 | 291 | *pp_data = (const char *)JpegBuffer[jcu_buf_index_read]; |
dkato | 1:ebff3aeb40a0 | 292 | encode_size = (int)jcu_encode_size[jcu_buf_index_read]; |
dkato | 0:c5448e500c90 | 293 | |
dkato | 1:ebff3aeb40a0 | 294 | return encode_size; |
dkato | 0:c5448e500c90 | 295 | } |
dkato | 0:c5448e500c90 | 296 | |
dkato | 0:c5448e500c90 | 297 | static void TerminalWrite(Arguments* arg, Reply* r) { |
dkato | 16:b5469a6226c7 | 298 | if ((arg != NULL) && (r != NULL)) { |
dkato | 16:b5469a6226c7 | 299 | for (int i = 0; i < arg->argc; i++) { |
dkato | 16:b5469a6226c7 | 300 | if (arg->argv[i] != NULL) { |
dkato | 16:b5469a6226c7 | 301 | printf("%s", arg->argv[i]); |
dkato | 16:b5469a6226c7 | 302 | } |
dkato | 16:b5469a6226c7 | 303 | } |
dkato | 16:b5469a6226c7 | 304 | printf("\n"); |
dkato | 16:b5469a6226c7 | 305 | r->putData<const char*>("ok"); |
dkato | 16:b5469a6226c7 | 306 | } |
dkato | 0:c5448e500c90 | 307 | } |
dkato | 0:c5448e500c90 | 308 | |
dkato | 0:c5448e500c90 | 309 | static void mount_romramfs(void) { |
dkato | 0:c5448e500c90 | 310 | FILE * fp; |
dkato | 0:c5448e500c90 | 311 | |
dkato | 0:c5448e500c90 | 312 | romramfs.format(); |
dkato | 0:c5448e500c90 | 313 | |
dkato | 12:6c002b871c4d | 314 | //index.htm |
dkato | 12:6c002b871c4d | 315 | fp = fopen("/romram/index.htm", "w"); |
dkato | 12:6c002b871c4d | 316 | fwrite(index_htm_tbl, sizeof(char), sizeof(index_htm_tbl), fp); |
dkato | 12:6c002b871c4d | 317 | fclose(fp); |
dkato | 12:6c002b871c4d | 318 | |
dkato | 0:c5448e500c90 | 319 | //camera.js |
dkato | 0:c5448e500c90 | 320 | fp = fopen("/romram/camera.js", "w"); |
dkato | 0:c5448e500c90 | 321 | fwrite(camaera_js_tbl, sizeof(char), sizeof(camaera_js_tbl), fp); |
dkato | 0:c5448e500c90 | 322 | fclose(fp); |
dkato | 0:c5448e500c90 | 323 | |
dkato | 0:c5448e500c90 | 324 | //camera.htm |
dkato | 0:c5448e500c90 | 325 | fp = fopen("/romram/camera.htm", "w"); |
dkato | 0:c5448e500c90 | 326 | fwrite(camera_htm_tbl, sizeof(char), sizeof(camera_htm_tbl), fp); |
dkato | 0:c5448e500c90 | 327 | fclose(fp); |
dkato | 0:c5448e500c90 | 328 | |
dkato | 0:c5448e500c90 | 329 | //mbedrpc.js |
dkato | 0:c5448e500c90 | 330 | fp = fopen("/romram/mbedrpc.js", "w"); |
dkato | 0:c5448e500c90 | 331 | fwrite(mbedrpc_js_tbl, sizeof(char), sizeof(mbedrpc_js_tbl), fp); |
dkato | 0:c5448e500c90 | 332 | fclose(fp); |
dkato | 0:c5448e500c90 | 333 | |
dkato | 0:c5448e500c90 | 334 | //led.htm |
dkato | 0:c5448e500c90 | 335 | fp = fopen("/romram/led.htm", "w"); |
dkato | 0:c5448e500c90 | 336 | fwrite(led_htm_tbl, sizeof(char), sizeof(led_htm_tbl), fp); |
dkato | 0:c5448e500c90 | 337 | fclose(fp); |
1050186 | 5:34d84609dd60 | 338 | |
1050186 | 5:34d84609dd60 | 339 | //i2c_set.htm |
1050186 | 5:34d84609dd60 | 340 | fp = fopen("/romram/i2c_set.htm", "w"); |
1050186 | 5:34d84609dd60 | 341 | fwrite(i2c_set_htm_tbl, sizeof(char), sizeof(i2c_set_htm_tbl), fp); |
1050186 | 5:34d84609dd60 | 342 | fclose(fp); |
1050186 | 5:34d84609dd60 | 343 | |
1050186 | 5:34d84609dd60 | 344 | //web_top.htm |
1050186 | 5:34d84609dd60 | 345 | fp = fopen("/romram/web_top.htm", "w"); |
1050186 | 5:34d84609dd60 | 346 | fwrite(web_top_htm_tbl, sizeof(char), sizeof(web_top_htm_tbl), fp); |
1050186 | 5:34d84609dd60 | 347 | fclose(fp); |
1050186 | 5:34d84609dd60 | 348 | |
1050186 | 5:34d84609dd60 | 349 | //menu.htm |
1050186 | 5:34d84609dd60 | 350 | fp = fopen("/romram/menu.htm", "w"); |
1050186 | 5:34d84609dd60 | 351 | fwrite(menu_htm_tbl, sizeof(char), sizeof(menu_htm_tbl), fp); |
1050186 | 5:34d84609dd60 | 352 | fclose(fp); |
1050186 | 5:34d84609dd60 | 353 | |
1050186 | 5:34d84609dd60 | 354 | //window.htm |
1050186 | 5:34d84609dd60 | 355 | fp = fopen("/romram/window.htm", "w"); |
1050186 | 5:34d84609dd60 | 356 | fwrite(window_htm_tbl, sizeof(char), sizeof(window_htm_tbl), fp); |
1050186 | 5:34d84609dd60 | 357 | fclose(fp); |
1050186 | 5:34d84609dd60 | 358 | } |
1050186 | 5:34d84609dd60 | 359 | |
1050186 | 5:34d84609dd60 | 360 | static void SetI2CfromWeb(Arguments* arg, Reply* r) { |
1050186 | 10:3a176dc33f74 | 361 | int result = 0; |
1050186 | 10:3a176dc33f74 | 362 | |
1050186 | 10:3a176dc33f74 | 363 | if (arg != NULL) { |
1050186 | 10:3a176dc33f74 | 364 | if (arg->argc >= 2) { |
1050186 | 10:3a176dc33f74 | 365 | if ((arg->argv[0] != NULL) && (arg->argv[1] != NULL)) { |
1050186 | 10:3a176dc33f74 | 366 | sprintf(i2c_setting_str_buf, "%s,%s", arg->argv[0], arg->argv[1]); |
1050186 | 10:3a176dc33f74 | 367 | result = 1; |
1050186 | 10:3a176dc33f74 | 368 | } |
1050186 | 10:3a176dc33f74 | 369 | } else if (arg->argc == 1) { |
1050186 | 10:3a176dc33f74 | 370 | if (arg->argv[0] != NULL) { |
1050186 | 10:3a176dc33f74 | 371 | sprintf(i2c_setting_str_buf, "%s", arg->argv[0]); |
1050186 | 10:3a176dc33f74 | 372 | result = 1; |
1050186 | 10:3a176dc33f74 | 373 | } |
1050186 | 10:3a176dc33f74 | 374 | } else { |
1050186 | 10:3a176dc33f74 | 375 | /* Do nothing */ |
1050186 | 10:3a176dc33f74 | 376 | } |
dkato | 7:c45ecff1b44d | 377 | /* command analysis and execute */ |
1050186 | 10:3a176dc33f74 | 378 | if (result != 0) { |
1050186 | 10:3a176dc33f74 | 379 | if (i2c_setting_exe(i2c_setting_str_buf) != false) { |
1050186 | 10:3a176dc33f74 | 380 | r->putData<const char*>(i2c_setting_str_buf); |
1050186 | 10:3a176dc33f74 | 381 | } |
1050186 | 5:34d84609dd60 | 382 | } |
1050186 | 5:34d84609dd60 | 383 | } |
dkato | 0:c5448e500c90 | 384 | } |
dkato | 0:c5448e500c90 | 385 | |
dkato | 0:c5448e500c90 | 386 | int main(void) { |
dkato | 0:c5448e500c90 | 387 | printf("********* PROGRAM START ***********\r\n"); |
dkato | 0:c5448e500c90 | 388 | |
1050186 | 5:34d84609dd60 | 389 | /* Please enable this line when performing the setting from the Terminal side. */ |
1050186 | 5:34d84609dd60 | 390 | // Thread thread(SetI2CfromTerm, NULL, osPriorityBelowNormal, DEFAULT_STACK_SIZE); |
1050186 | 5:34d84609dd60 | 391 | |
dkato | 0:c5448e500c90 | 392 | mount_romramfs(); //RomRamFileSystem Mount |
dkato | 0:c5448e500c90 | 393 | camera_start(); //Camera Start |
dkato | 0:c5448e500c90 | 394 | |
dkato | 0:c5448e500c90 | 395 | RPC::add_rpc_class<RpcDigitalOut>(); |
dkato | 0:c5448e500c90 | 396 | RPC::construct<RpcDigitalOut, PinName, const char*>(LED1, "led1"); |
dkato | 0:c5448e500c90 | 397 | RPC::construct<RpcDigitalOut, PinName, const char*>(LED2, "led2"); |
dkato | 0:c5448e500c90 | 398 | RPC::construct<RpcDigitalOut, PinName, const char*>(LED3, "led3"); |
dkato | 0:c5448e500c90 | 399 | RPCFunction rpcFunc(TerminalWrite, "TerminalWrite"); |
1050186 | 5:34d84609dd60 | 400 | RPCFunction rpcSetI2C(SetI2CfromWeb, "SetI2CfromWeb"); |
dkato | 0:c5448e500c90 | 401 | |
dkato | 15:eac4c3711aab | 402 | #if (NETWORK_TYPE == 1) |
dkato | 15:eac4c3711aab | 403 | //Audio Camera Shield USB1 enable for WlanBP3595 |
dkato | 15:eac4c3711aab | 404 | usb1en = 1; //Outputs high level |
dkato | 15:eac4c3711aab | 405 | Thread::wait(5); |
dkato | 15:eac4c3711aab | 406 | usb1en = 0; //Outputs low level |
dkato | 15:eac4c3711aab | 407 | Thread::wait(5); |
dkato | 15:eac4c3711aab | 408 | #endif |
dkato | 15:eac4c3711aab | 409 | |
dkato | 11:ad8ff26679bb | 410 | printf("Network Setting up...\r\n"); |
dkato | 11:ad8ff26679bb | 411 | #if (USE_DHCP == 1) |
dkato | 11:ad8ff26679bb | 412 | if (network.init() != 0) { //for DHCP Server |
dkato | 11:ad8ff26679bb | 413 | #else |
dkato | 11:ad8ff26679bb | 414 | if (network.init(IP_ADDRESS, SUBNET_MASK, DEFAULT_GATEWAY) != 0) { //for Static IP Address (IPAddress, NetMasks, Gateway) |
dkato | 11:ad8ff26679bb | 415 | #endif |
dkato | 11:ad8ff26679bb | 416 | printf("Network Initialize Error \r\n"); |
dkato | 0:c5448e500c90 | 417 | return -1; |
dkato | 0:c5448e500c90 | 418 | } |
dkato | 15:eac4c3711aab | 419 | #if (NETWORK_TYPE == 0) |
dkato | 11:ad8ff26679bb | 420 | if (network.connect() != 0) { |
dkato | 15:eac4c3711aab | 421 | #else |
dkato | 15:eac4c3711aab | 422 | if (network.connect(WLAN_SSID, WLAN_PSK, WLAN_SECURITY) != 0) { |
dkato | 15:eac4c3711aab | 423 | #endif |
dkato | 11:ad8ff26679bb | 424 | printf("Network Connect Error \r\n"); |
dkato | 0:c5448e500c90 | 425 | return -1; |
dkato | 0:c5448e500c90 | 426 | } |
dkato | 11:ad8ff26679bb | 427 | printf("MAC Address is %s\r\n", network.getMACAddress()); |
dkato | 11:ad8ff26679bb | 428 | printf("IP Address is %s\r\n", network.getIPAddress()); |
dkato | 11:ad8ff26679bb | 429 | printf("NetMask is %s\r\n", network.getNetworkMask()); |
dkato | 11:ad8ff26679bb | 430 | printf("Gateway Address is %s\r\n", network.getGateway()); |
dkato | 11:ad8ff26679bb | 431 | printf("Network Setup OK\r\n"); |
dkato | 17:493d36f1febf | 432 | DhcpServer dhcp_server("GR-PEACH_1", network.getIPAddress()); |
dkato | 0:c5448e500c90 | 433 | |
dkato | 0:c5448e500c90 | 434 | SnapshotHandler::attach_req(&snapshot_req); |
dkato | 0:c5448e500c90 | 435 | HTTPServerAddHandler<SnapshotHandler>("/camera"); //Camera |
dkato | 0:c5448e500c90 | 436 | FSHandler::mount("/romram", "/"); |
dkato | 0:c5448e500c90 | 437 | HTTPServerAddHandler<FSHandler>("/"); |
dkato | 0:c5448e500c90 | 438 | HTTPServerAddHandler<RPCHandler>("/rpc"); |
dkato | 0:c5448e500c90 | 439 | HTTPServerStart(80); |
dkato | 0:c5448e500c90 | 440 | } |