Tedd OKANO / Mbed 2 deprecated MARY_CAMERA_Hello

Dependencies:   MARY_CAMERA NokiaLCD mbed

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers main.cpp Source File

main.cpp

00001 #include "mbed.h"
00002 #include "MARMEX_OB_oled.h"
00003 #include "MARY_CAMERA.h"
00004 
00005 #if defined( TARGET_MBED_LPC1768 ) || defined( TARGET_LPC11U24_401 ) || defined( TARGET_LPC11XX )
00006 MARMEX_OB_oled  oled1( p5, p7,  p20, p16, p15 ); // mosi, sclk, cs, rst, power_control     -- maple-mini-type-b-slot1
00007 MARY_CAMERA     camera( p5, p6, p7, p22, p26, p28, p27 ); // mosi, miso, sclk, cs, reset, I2C_SDA, I2C_SCL
00008 #endif
00009 
00010 #if defined( TARGET_LPC11U35_401 )
00011 MARMEX_OB_oled  oled1( P0_9, P0_10,  P0_16, P0_12, P0_11 ); // mosi, sclk, cs, rst, power_control     -- maple-mini-type-b-slot1
00012 MARY_CAMERA     camera( P0_9, P0_8, P0_10, P0_2, P1_15, P0_5, P0_4 ); // mosi, miso, sclk, cs, reset, I2C_SDA, I2C_SCL
00013 #endif
00014 
00015 BusOut          led( LED4, LED3, LED2, LED1 );
00016 
00017 void test_camera_QCIF_video_with_colorbar( void );
00018 void test_camera_resolution_change( void );
00019 
00020 void copy_image_to_oled( void );
00021 void line_mirroring( short *buf );
00022 void save_still_image( char *file_name );
00023 void oled_test_screen( void );
00024 void capture_to_bmp( void );
00025 
00026 //#define     SAVE_EACH_SIZES_OF_STILL_IMAGE
00027 int read_order_change   = 0;
00028 
00029 int main()
00030 {
00031     printf( "\r\n\r\nMARY-CAMERA test program\r\n\r\n" );
00032 
00033     led    = 0x3;
00034 
00035     oled1.cls();
00036     oled_test_screen();
00037 
00038 #if defined( TARGET_MBED_LPC1768 )
00039 
00040 #ifdef  SAVE_EACH_SIZES_OF_STILL_IMAGE
00041     led    = 0x1;
00042     camera.resolution( MARY_CAMERA::QCIF );
00043     save_still_image( "i_qcif.bmp" );
00044 
00045     led    = 0x2;
00046     camera.resolution( MARY_CAMERA::QQVGA );
00047     save_still_image( "i_qqvga.bmp" );
00048 
00049     led    = 0x4;
00050     camera.resolution( MARY_CAMERA::QVGA );
00051     save_still_image( "i_qvga.bmp" );
00052 
00053     led    = 0x8;
00054     camera.resolution( MARY_CAMERA::VGA );
00055     save_still_image( "i_vga.bmp" );
00056 
00057     camera.resolution( MARY_CAMERA::QCIF );
00058 #endif
00059 
00060 #endif
00061     printf( "  camera operation started\r\n" );
00062     printf( "    hit key [c] for saving data into BMP\r\n" );
00063     printf( "    hit key [o] to change data reading order\r\n" );
00064     printf( "    hit key [1], [2], [3] or [4] to change resolution QCIF, QQVGA, QVGA, VGA\r\n" );
00065 
00066     test_camera_QCIF_video_with_colorbar();   //  doesn't return
00067 //    test_camera_resolution_change();   //  doesn't return
00068 }
00069 
00070 Serial      pc(USBTX, USBRX);    // tx, rx
00071 
00072 void test_camera_QCIF_video_with_colorbar( void )
00073 {
00074     while ( 1 ) {
00075         
00076         if ( pc.readable() ) {
00077             switch ( pc.getc() ) {
00078                 case 'c' :
00079                     capture_to_bmp();
00080                     printf( "  [c] : capture started\r\n" );
00081                     break;
00082                 case 'o' :
00083                     read_order_change   = read_order_change ? 0 : 1;
00084                     printf( "  [o] read order change : %s\r\n", read_order_change ? "ENABLED" : "DISABLED" );
00085                     break;
00086                 case '1' :
00087                     printf( "  [1] resolution change : QCIF\r\n" );
00088                     camera.init( MARY_CAMERA::QCIF );
00089                     break;
00090                 case '2' :
00091                     printf( "  [2] resolution change : QQVGA\r\n" );
00092                     camera.init( MARY_CAMERA::QQVGA );
00093                     break;
00094                 case '3' :
00095                     printf( "  [3] resolution change : QVGA\r\n" );
00096                     camera.init( MARY_CAMERA::QVGA );
00097                     break;
00098                 case '4' :
00099                     printf( "  [4] resolution change : VGA\r\n" );
00100                     camera.init( MARY_CAMERA::VGA );
00101                     break;
00102             }
00103         }
00104 
00105 
00106         led    = 0x1;
00107         copy_image_to_oled();
00108 //        camera.colorbar( ((count++ >> 2) & 0x1) ? MARY_CAMERA::ON : MARY_CAMERA::OFF );
00109         led    = 0x2;
00110     }
00111 }
00112 
00113 
00114 void test_camera_resolution_change( void )
00115 {
00116     int     count   = (3 << 3);
00117     int     setting;
00118 
00119     while ( 1 ) {
00120 
00121         if ( !(count & 0x7) ) {
00122             setting     = (count >> 3) & 0x3;
00123             camera.init( (MARY_CAMERA::CameraResolution)(setting + 1) );
00124             led    = 0x1 << setting;
00125         }
00126 
00127         count++;
00128 
00129         copy_image_to_oled();
00130     }
00131 }
00132 
00133 
00134 void copy_image_to_oled( void )
00135 {
00136     short   buf[ MARMEX_OB_oled::WIDTH ];
00137 
00138     camera.open_transfer();
00139 
00140     for ( int line = 0; line < MARMEX_OB_oled::HEIGHT; line++  ) {
00141         camera.transfer_a_line( buf, line + (camera.vertical_size() - (int)MARMEX_OB_oled::HEIGHT) / 2, (camera.horizontal_size() - (int)MARMEX_OB_oled::WIDTH ) / 2, MARMEX_OB_oled::WIDTH );
00142         line_mirroring( buf );
00143         oled1.blit565( 0, line, MARMEX_OB_oled::WIDTH, 1, buf );
00144     }
00145 
00146     camera.close_transfer();
00147 }
00148 
00149 
00150 void line_mirroring( short *buf )
00151 {
00152     short   tmp;
00153 
00154     for ( int i = 0; i < (MARMEX_OB_oled::WIDTH / 2); i++ ) {
00155         tmp         = buf[ i ];
00156         buf[ i ]    = buf[ (MARMEX_OB_oled::WIDTH - 1) - i ];
00157         buf[ (MARMEX_OB_oled::WIDTH - 1) - i ]  = tmp;
00158     }
00159 }
00160 
00161 
00162 void oled_test_screen( void )
00163 {
00164     oled1.background( 0x000000 );
00165     oled1.cls();
00166 
00167     int colorbar_width  = MARMEX_OB_oled::WIDTH / 8;
00168 
00169     for ( int i = 0; i < 8; i++ )
00170         oled1.fill( colorbar_width * i, 0, colorbar_width, MARMEX_OB_oled::HEIGHT, ((i & 0x4) ? 0xFF0000 : 0x000000) | ((i & 0x2) ? 0x00FF00 : 0x000000) | ((i & 0x1) ? 0x0000FF : 0x000000) );
00171 
00172     oled1.fill(  50,  50,  64,  64, 0xCCCCCC );;
00173 
00174     oled1.locate( 0, 2 );
00175     oled1.printf( "MaryCemara test" );
00176     oled1.locate( 0, 3 );
00177     oled1.printf( "%s", (MARY_CAMERA::NO_ERROR == camera.ready()) ? "Camera is ready" : "No Camera found" );
00178     oled1.locate( 0, 4 );
00179     oled1.printf( "%s", "saving into BMP" );
00180     oled1.locate( 0, 5 );
00181     oled1.printf( "%d", camera.horizontal_size() );
00182     oled1.locate( 0, 6 );
00183     oled1.printf( "%d", camera.vertical_size() );
00184 
00185 
00186     for (int i = 0; i < MARMEX_OB_oled::WIDTH; i++ )
00187         oled1.pixel( i, 80 + sin( (float)i / 5.0 ) * 10, 0x000000 );
00188 }
00189 
00190 
00191 #include    "bmp_handler.h"
00192 
00193 void save_still_image( char *file_name )
00194 {
00195     short   buf[ camera.horizontal_size() ];
00196 
00197     if ( open_BMP( file_name, camera.horizontal_size(), camera.vertical_size() ) )
00198         return;
00199 
00200     camera.open_transfer();
00201 
00202     for ( int line = (camera.vertical_size() - 1); 0 <= line; line--  ) {
00203         camera.transfer_a_line( buf, line, 0, camera.horizontal_size() );
00204         write_BMP( buf, camera.horizontal_size() );
00205     }
00206     camera.close_transfer();
00207 
00208     close_BMP();
00209 }
00210 
00211 void capture_to_bmp( void )
00212 {
00213     short   buf[ camera.horizontal_size() ];
00214     camera.open_transfer();
00215 
00216 #if 0
00217     for ( int line = 0; line < MARMEX_OB_oled::HEIGHT; line++  ) {
00218         camera.transfer_a_line( buf, line + (camera.vertical_size() - (int)MARMEX_OB_oled::HEIGHT) / 2, (camera.horizontal_size() - (int)MARMEX_OB_oled::WIDTH ) / 2, MARMEX_OB_oled::WIDTH );
00219         line_mirroring( buf );
00220         oled1.blit565( 0, line, MARMEX_OB_oled::WIDTH, 1, buf );
00221     }
00222 #endif
00223 
00224     if ( open_BMP( "RGB.bmp", camera.horizontal_size(), camera.vertical_size() ) )
00225         return;
00226 
00227     for ( int line = (camera.vertical_size() - 1); 0 <= line; line--  ) {
00228         camera.transfer_a_line( buf, line, 0, camera.horizontal_size() );
00229         write_BMP( buf, camera.horizontal_size(), 0x7 );
00230     }
00231 
00232     close_BMP();
00233 
00234 #if 0
00235 
00236     if ( open_BMP( "R.bmp", camera.horizontal_size(), camera.vertical_size() ) )
00237         return;
00238 
00239     for ( int line = (camera.vertical_size() - 1); 0 <= line; line--  ) {
00240         camera.transfer_a_line( buf, line, 0, camera.horizontal_size() );
00241         write_BMP( buf, camera.horizontal_size(), 0x4 );
00242     }
00243 
00244     close_BMP();
00245 
00246 
00247     if ( open_BMP( "G.bmp", camera.horizontal_size(), camera.vertical_size() ) )
00248         return;
00249 
00250     for ( int line = (camera.vertical_size() - 1); 0 <= line; line--  ) {
00251         camera.transfer_a_line( buf, line, 0, camera.horizontal_size() );
00252         write_BMP( buf, camera.horizontal_size(), 0x2 );
00253     }
00254 
00255     close_BMP();
00256 
00257 
00258     if ( open_BMP( "B.bmp", camera.horizontal_size(), camera.vertical_size() ) )
00259         return;
00260 
00261     for ( int line = (camera.vertical_size() - 1); 0 <= line; line--  ) {
00262         camera.transfer_a_line( buf, line, 0, camera.horizontal_size() );
00263         write_BMP( buf, camera.horizontal_size(), 0x1 );
00264     }
00265 
00266     close_BMP();
00267 
00268 #endif
00269     camera.close_transfer();
00270 }