MARMEX_VB test application program. This application works on "mbed NXP LPC1768" only. This application expects to have the MARMEX_VB module on a "MAPLE mini type-B (MARM03-BASE)" baseboard (slot2) with MARMEX_OB module (on slot1)

Dependencies:   MARMEX_VB NokiaLCD mbed

This is the library test program.
The program can test features of the library (refer to MARMEX-VB's API document) and can save captured data into BMP file.

Warning!

This test program can run on "mbed NXP LPC1768" only.

/media/uploads/nxpfan/dsc_0506_-1-.jpg
Picture : sample of test program operation
The modules of MARMEX-VB and MARMEX-OB are set on the "MAPLE mini type-B (MARM03-BASE)" baseboard.
The image data from camera is mirrored and alpha graphics added by software.

Committer:
nxpfan
Date:
Thu Jun 19 12:21:50 2014 +0000
Revision:
7:125538c50c22
Parent:
6:b61b876d50a8
Child:
8:86aae677a68b
optimized SPI : FIFO

Who changed what in which revision?

UserRevisionLine numberNew contents of line
nxpfan 0:343c01965543 1 /** Test program for MARMEX_VB Camera control library
nxpfan 0:343c01965543 2 *
nxpfan 7:125538c50c22 3 * @version 0.3
nxpfan 7:125538c50c22 4 * @date 19-Jun-2014
nxpfan 0:343c01965543 5 *
nxpfan 0:343c01965543 6 * Released under the Apache License, Version 2.0 : http://mbed.org/handbook/Apache-Licence
nxpfan 0:343c01965543 7 *
nxpfan 0:343c01965543 8 * Test program for MARMEX_VB Camera control library
nxpfan 0:343c01965543 9 *
nxpfan 0:343c01965543 10 * ** This program runs on mbed_NXP_LPC1768 only **
nxpfan 0:343c01965543 11 */
nxpfan 0:343c01965543 12
nxpfan 0:343c01965543 13
nxpfan 0:343c01965543 14 #include "mbed.h"
nxpfan 0:343c01965543 15 #include "MARMEX_OB_oled.h"
nxpfan 0:343c01965543 16 #include "MARMEX_VB.h"
nxpfan 0:343c01965543 17 #include "bmp_handler.h"
nxpfan 0:343c01965543 18
nxpfan 6:b61b876d50a8 19 // Baseboard type selection
nxpfan 6:b61b876d50a8 20 #define BASEBOARD_MAPLE_MINI_TYPE_B
nxpfan 6:b61b876d50a8 21 //#define BASEBOARD_MAPLE_ORIGINAL
nxpfan 6:b61b876d50a8 22
nxpfan 6:b61b876d50a8 23 #ifdef BASEBOARD_MAPLE_MINI_TYPE_B
nxpfan 0:343c01965543 24 MARMEX_OB_oled oled1( p5, p7, p20, p16, p15 );
nxpfan 0:343c01965543 25 // mosi, sclk, cs, rst, power_control -- maple-mini-type-b-board-slot1
nxpfan 0:343c01965543 26 MARMEX_VB camera( p5, p6, p7, p22, p26, p28, p27 );
nxpfan 0:343c01965543 27 // mosi, miso, sclk, cs, reset, sda, scl -- maple-mini-type-b-board-slot2
nxpfan 6:b61b876d50a8 28 #endif
nxpfan 6:b61b876d50a8 29
nxpfan 6:b61b876d50a8 30 #ifdef BASEBOARD_MAPLE_ORIGINAL
nxpfan 6:b61b876d50a8 31 MARMEX_OB_oled oled1( p5, p7, p8, p30, p11 );
nxpfan 6:b61b876d50a8 32 // mosi, sclk, cs, rst, power_control -- maple-board-slot1
nxpfan 6:b61b876d50a8 33 MARMEX_VB camera( p5, p6, p7, p26, p17, p28, p27 );
nxpfan 6:b61b876d50a8 34 // mosi, miso, sclk, cs, reset, sda, scl -- maple-board-slot2
nxpfan 6:b61b876d50a8 35 #endif
nxpfan 0:343c01965543 36
nxpfan 0:343c01965543 37 BusOut led( LED4, LED3, LED2, LED1 );
nxpfan 0:343c01965543 38 Timer timer;
nxpfan 7:125538c50c22 39 Timer looptimer;
nxpfan 7:125538c50c22 40
nxpfan 0:343c01965543 41
nxpfan 0:343c01965543 42 void test_camera( void );
nxpfan 0:343c01965543 43 void test_camera_resolution_change( void );
nxpfan 0:343c01965543 44
nxpfan 0:343c01965543 45 void copy_image_from_camera_to_oled( void );
nxpfan 1:dbe2dc31542d 46 void copy_image_from_camera_to_oled_small( void );
nxpfan 0:343c01965543 47 void copy_image_from_camera_to_oled_interlaced( void );
nxpfan 0:343c01965543 48 void line_mirroring( short *buf );
nxpfan 0:343c01965543 49 void save_still_image( char *file_name );
nxpfan 0:343c01965543 50 void oled_test_screen( void );
nxpfan 0:343c01965543 51 void capture_to_bmp( void );
nxpfan 0:343c01965543 52
nxpfan 0:343c01965543 53 //#define SAVE_EACH_SIZES_OF_STILL_IMAGE
nxpfan 0:343c01965543 54
nxpfan 0:343c01965543 55 alpha_param ap;
nxpfan 0:343c01965543 56
nxpfan 0:343c01965543 57
nxpfan 0:343c01965543 58 int main()
nxpfan 0:343c01965543 59 {
nxpfan 0:343c01965543 60 printf( "\r\n\r\nMARY-CAMERA test program\r\n\r\n" );
nxpfan 0:343c01965543 61
nxpfan 0:343c01965543 62 read_alpha_BMP( "alpha.bmp", &ap );
nxpfan 0:343c01965543 63
nxpfan 0:343c01965543 64
nxpfan 0:343c01965543 65 led = 0x3;
nxpfan 0:343c01965543 66
nxpfan 0:343c01965543 67 oled1.cls();
nxpfan 0:343c01965543 68 oled_test_screen();
nxpfan 7:125538c50c22 69 oled1.cls();
nxpfan 0:343c01965543 70
nxpfan 0:343c01965543 71 #ifdef SAVE_EACH_SIZES_OF_STILL_IMAGE
nxpfan 0:343c01965543 72 led = 0x1;
nxpfan 0:343c01965543 73 camera.resolution( MARMEX_VB::QCIF );
nxpfan 0:343c01965543 74 save_still_image( "i_qcif.bmp" );
nxpfan 0:343c01965543 75
nxpfan 0:343c01965543 76 led = 0x2;
nxpfan 0:343c01965543 77 camera.resolution( MARMEX_VB::QQVGA );
nxpfan 0:343c01965543 78 save_still_image( "i_qqvga.bmp" );
nxpfan 0:343c01965543 79
nxpfan 0:343c01965543 80 led = 0x4;
nxpfan 0:343c01965543 81 camera.resolution( MARMEX_VB::QVGA );
nxpfan 0:343c01965543 82 save_still_image( "i_qvga.bmp" );
nxpfan 0:343c01965543 83
nxpfan 0:343c01965543 84 led = 0x8;
nxpfan 0:343c01965543 85 camera.resolution( MARMEX_VB::VGA );
nxpfan 0:343c01965543 86 save_still_image( "i_vga.bmp" );
nxpfan 0:343c01965543 87
nxpfan 0:343c01965543 88 camera.resolution( MARMEX_VB::QCIF );
nxpfan 0:343c01965543 89 #endif
nxpfan 0:343c01965543 90
nxpfan 0:343c01965543 91 printf( " camera operation started\r\n" );
nxpfan 0:343c01965543 92 printf( " hit key [c] for saving data into BMP (for blue-mbed only)\r\n" );
nxpfan 0:343c01965543 93 printf( " hit key [o] to change data reading order\r\n" );
nxpfan 0:343c01965543 94 printf( " hit key [i] to toggle interlace mode\r\n" );
nxpfan 0:343c01965543 95 printf( " hit key [1], [2], [3] or [4] to change resolution QCIF, QQVGA, QVGA, VGA\r\n" );
nxpfan 0:343c01965543 96
nxpfan 7:125538c50c22 97 looptimer.start();
nxpfan 7:125538c50c22 98
nxpfan 0:343c01965543 99 timer.start(); // timer for measureing frame rate
nxpfan 0:343c01965543 100 test_camera(); // this function doesn't return
nxpfan 0:343c01965543 101 }
nxpfan 0:343c01965543 102
nxpfan 7:125538c50c22 103 #if defined( TARGET_MBED_LPC1768 )
nxpfan 0:343c01965543 104 Serial pc(USBTX, USBRX); // tx, rx
nxpfan 0:343c01965543 105 #endif
nxpfan 0:343c01965543 106
nxpfan 7:125538c50c22 107 int disp = 1;
nxpfan 7:125538c50c22 108
nxpfan 0:343c01965543 109
nxpfan 0:343c01965543 110 void test_camera( void )
nxpfan 0:343c01965543 111 {
nxpfan 7:125538c50c22 112 int interlace = 1;
nxpfan 7:125538c50c22 113 int frame_count = 0;
nxpfan 7:125538c50c22 114
nxpfan 7:125538c50c22 115 float t;
nxpfan 0:343c01965543 116
nxpfan 0:343c01965543 117 while ( 1 ) {
nxpfan 7:125538c50c22 118
nxpfan 7:125538c50c22 119 #ifdef TARGET_MBED_LPC1768
nxpfan 0:343c01965543 120 if ( pc.readable() ) {
nxpfan 0:343c01965543 121 switch ( pc.getc() ) {
nxpfan 0:343c01965543 122 case 'c' :
nxpfan 0:343c01965543 123 capture_to_bmp();
nxpfan 0:343c01965543 124 printf( " [c] : capture started\r\n" );
nxpfan 0:343c01965543 125 break;
nxpfan 0:343c01965543 126 case 'o' :
nxpfan 0:343c01965543 127 printf( " [o] read order change : %s\r\n", camera.read_order_change() ? "ENABLED" : "DISABLED" );
nxpfan 0:343c01965543 128 break;
nxpfan 0:343c01965543 129 case 'i' :
nxpfan 0:343c01965543 130 interlace = !interlace;
nxpfan 0:343c01965543 131 printf( " [i] : interlace setting : %s\r\n", interlace ? "ENABLED" : "DISABLED" );
nxpfan 0:343c01965543 132 /* FALL THROUGH */
nxpfan 0:343c01965543 133 case 'f' :
nxpfan 0:343c01965543 134 if ( frame_count ) {
nxpfan 0:343c01965543 135 timer.stop();
nxpfan 7:125538c50c22 136 t = timer.read();
nxpfan 0:343c01965543 137 printf( " [f] : %s rate : %5.3f\r\n", interlace ? "field" : "frame", (float)frame_count / t );
nxpfan 0:343c01965543 138 frame_count = 0;
nxpfan 0:343c01965543 139 timer.reset();
nxpfan 0:343c01965543 140 timer.start();
nxpfan 0:343c01965543 141 } else {
nxpfan 0:343c01965543 142 printf( " [f] : no frame drawn yet. try again later\r\n" );
nxpfan 0:343c01965543 143 }
nxpfan 0:343c01965543 144 break;
nxpfan 0:343c01965543 145 case '1' :
nxpfan 0:343c01965543 146 printf( " [1] resolution change : QCIF\r\n" );
nxpfan 0:343c01965543 147 camera.init( MARMEX_VB::QCIF );
nxpfan 0:343c01965543 148 break;
nxpfan 0:343c01965543 149 case '2' :
nxpfan 0:343c01965543 150 printf( " [2] resolution change : QQVGA\r\n" );
nxpfan 0:343c01965543 151 camera.init( MARMEX_VB::QQVGA );
nxpfan 0:343c01965543 152 break;
nxpfan 0:343c01965543 153 case '3' :
nxpfan 0:343c01965543 154 printf( " [3] resolution change : QVGA\r\n" );
nxpfan 0:343c01965543 155 camera.init( MARMEX_VB::QVGA );
nxpfan 0:343c01965543 156 break;
nxpfan 0:343c01965543 157 case '4' :
nxpfan 0:343c01965543 158 printf( " [4] resolution change : VGA\r\n" );
nxpfan 0:343c01965543 159 camera.init( MARMEX_VB::VGA );
nxpfan 0:343c01965543 160 break;
nxpfan 0:343c01965543 161 }
nxpfan 0:343c01965543 162 }
nxpfan 7:125538c50c22 163 #endif
nxpfan 0:343c01965543 164
nxpfan 0:343c01965543 165 led = 0x1;
nxpfan 0:343c01965543 166
nxpfan 0:343c01965543 167 if ( interlace )
nxpfan 0:343c01965543 168 copy_image_from_camera_to_oled_interlaced();
nxpfan 0:343c01965543 169 else
nxpfan 0:343c01965543 170 copy_image_from_camera_to_oled();
nxpfan 0:343c01965543 171
nxpfan 0:343c01965543 172 // camera.colorbar( ((count++ >> 2) & 0x1) ? MARMEX_VB::ON : MARMEX_VB::OFF );
nxpfan 0:343c01965543 173
nxpfan 7:125538c50c22 174 t = looptimer.read();
nxpfan 7:125538c50c22 175 looptimer.reset();
nxpfan 7:125538c50c22 176 oled1.locate( 0, 0 );
nxpfan 7:125538c50c22 177 oled1.printf( " %.2f %s/s", 1.0 / t, interlace ? "field" : "frame" );
nxpfan 7:125538c50c22 178
nxpfan 0:343c01965543 179 led = 0x2;
nxpfan 0:343c01965543 180
nxpfan 0:343c01965543 181 frame_count++;
nxpfan 0:343c01965543 182 }
nxpfan 0:343c01965543 183 }
nxpfan 0:343c01965543 184
nxpfan 0:343c01965543 185
nxpfan 0:343c01965543 186 void test_camera_resolution_change( void )
nxpfan 0:343c01965543 187 {
nxpfan 0:343c01965543 188 int count = (3 << 3);
nxpfan 0:343c01965543 189 int setting;
nxpfan 0:343c01965543 190
nxpfan 0:343c01965543 191 while ( 1 ) {
nxpfan 0:343c01965543 192
nxpfan 0:343c01965543 193 if ( !(count & 0x7) ) {
nxpfan 0:343c01965543 194 setting = (count >> 3) & 0x3;
nxpfan 0:343c01965543 195 camera.init( (MARMEX_VB::CameraResolution)(setting + 1) );
nxpfan 0:343c01965543 196 led = 0x1 << setting;
nxpfan 0:343c01965543 197 }
nxpfan 0:343c01965543 198
nxpfan 0:343c01965543 199 count++;
nxpfan 0:343c01965543 200
nxpfan 0:343c01965543 201 copy_image_from_camera_to_oled();
nxpfan 0:343c01965543 202 }
nxpfan 0:343c01965543 203 }
nxpfan 0:343c01965543 204
nxpfan 0:343c01965543 205
nxpfan 0:343c01965543 206 void alpha( int line_num, short *bf, int offset_x, int offset_y, alpha_param *app )
nxpfan 0:343c01965543 207 {
nxpfan 0:343c01965543 208 short r, g, b;
nxpfan 0:343c01965543 209 int y_pos;
nxpfan 0:343c01965543 210
nxpfan 0:343c01965543 211 if ( (line_num < offset_y) || (offset_y + app->v) <= line_num || (app->buffer == NULL) )
nxpfan 0:343c01965543 212 return;
nxpfan 0:343c01965543 213
nxpfan 0:343c01965543 214 bf += offset_x;
nxpfan 0:343c01965543 215 y_pos = ((app->v - (line_num - offset_y + 1)) * (app->h * app->byte_per_pixel));
nxpfan 0:343c01965543 216
nxpfan 0:343c01965543 217 for ( int i = 0; i < 60; i++ ) {
nxpfan 0:343c01965543 218 r = ((*bf >> 1) & 0x0F) + (*(app->buffer + i * 3 + 0 + y_pos ) >> 4);
nxpfan 0:343c01965543 219 g = ((*bf >> 6) & 0x1F) + (*(app->buffer + i * 3 + 1 + y_pos ) >> 3);
nxpfan 0:343c01965543 220 b = ((*bf >> 12) & 0x0F) + (*(app->buffer + i * 3 + 2 + y_pos ) >> 4);
nxpfan 0:343c01965543 221
nxpfan 0:343c01965543 222 *bf++ = (b << 11) | (g << 5) | (r << 0);
nxpfan 0:343c01965543 223 }
nxpfan 0:343c01965543 224 }
nxpfan 0:343c01965543 225
nxpfan 0:343c01965543 226
nxpfan 7:125538c50c22 227 #define OPTIMIZATION_ENABLED
nxpfan 7:125538c50c22 228 #define SCREEN_TOP 9
nxpfan 7:125538c50c22 229
nxpfan 7:125538c50c22 230 #ifdef OPTIMIZATION_ENABLED
nxpfan 0:343c01965543 231 void copy_image_from_camera_to_oled( void )
nxpfan 0:343c01965543 232 {
nxpfan 1:dbe2dc31542d 233 short buf[ MARMEX_OB_oled::WIDTH ]; // array size should be multiple of 8 for "mbed LPC1768" optimization
nxpfan 0:343c01965543 234 static int count = 0;
nxpfan 0:343c01965543 235
nxpfan 0:343c01965543 236 camera.open_transfer();
nxpfan 0:343c01965543 237
nxpfan 7:125538c50c22 238 for ( int line = SCREEN_TOP; line < MARMEX_OB_oled::HEIGHT; line++ ) {
nxpfan 7:125538c50c22 239 camera.read_a_line_SPI_FIFO_READ( buf, line + (camera.get_vertical_size() - (int)MARMEX_OB_oled::HEIGHT) / 2, (camera.get_horizontal_size() - (int)MARMEX_OB_oled::WIDTH ) / 2, MARMEX_OB_oled::WIDTH );
nxpfan 7:125538c50c22 240 line_mirroring( buf );
nxpfan 7:125538c50c22 241 alpha( line, buf, ((count >> 4) & 1) ? 60 : 8, ((count >> 4) & 1) ^ ((count >> 3) & 1) ? ((int)MARMEX_OB_oled::HEIGHT - (ap.v + 4)) : 4 + SCREEN_TOP, &ap );
nxpfan 7:125538c50c22 242 oled1.blit565_SPI_FIFO_WRITE( 0, line, MARMEX_OB_oled::WIDTH, 1, buf );
nxpfan 7:125538c50c22 243 }
nxpfan 7:125538c50c22 244
nxpfan 7:125538c50c22 245 count++;
nxpfan 7:125538c50c22 246 camera.close_transfer();
nxpfan 7:125538c50c22 247 }
nxpfan 7:125538c50c22 248
nxpfan 7:125538c50c22 249
nxpfan 7:125538c50c22 250 void copy_image_from_camera_to_oled_interlaced( void )
nxpfan 7:125538c50c22 251 {
nxpfan 7:125538c50c22 252 short buf[ MARMEX_OB_oled::WIDTH ];
nxpfan 7:125538c50c22 253 static int count = 0;
nxpfan 7:125538c50c22 254
nxpfan 7:125538c50c22 255 camera.open_transfer();
nxpfan 7:125538c50c22 256
nxpfan 7:125538c50c22 257 for ( int line = ((count++) & 1) + SCREEN_TOP; line < MARMEX_OB_oled::HEIGHT; line += 2 ) {
nxpfan 7:125538c50c22 258 camera.read_a_line_SPI_FIFO_READ( buf, line + (camera.get_vertical_size() - (int)MARMEX_OB_oled::HEIGHT) / 2, (camera.get_horizontal_size() - (int)MARMEX_OB_oled::WIDTH ) / 2, MARMEX_OB_oled::WIDTH );
nxpfan 7:125538c50c22 259 line_mirroring( buf );
nxpfan 7:125538c50c22 260 alpha( line, buf, ((count >> 4) & 1) ? 60 : 8, ((count >> 4) & 1) ^ ((count >> 3) & 1) ? ((int)MARMEX_OB_oled::HEIGHT - (ap.v + 4)) : 4 + SCREEN_TOP, &ap );
nxpfan 7:125538c50c22 261 oled1.blit565_SPI_FIFO_WRITE( 0, line, MARMEX_OB_oled::WIDTH, 1, buf );
nxpfan 7:125538c50c22 262 }
nxpfan 7:125538c50c22 263
nxpfan 7:125538c50c22 264 camera.close_transfer();
nxpfan 7:125538c50c22 265 }
nxpfan 7:125538c50c22 266
nxpfan 7:125538c50c22 267 #else
nxpfan 7:125538c50c22 268 void copy_image_from_camera_to_oled( void )
nxpfan 7:125538c50c22 269 {
nxpfan 7:125538c50c22 270 short buf[ MARMEX_OB_oled::WIDTH ]; // array size should be multiple of 8 for "mbed LPC1768" optimization
nxpfan 7:125538c50c22 271 static int count = 0;
nxpfan 7:125538c50c22 272
nxpfan 7:125538c50c22 273 camera.open_transfer();
nxpfan 7:125538c50c22 274
nxpfan 7:125538c50c22 275 for ( int line = SCREEN_TOP; line < MARMEX_OB_oled::HEIGHT; line++ ) {
nxpfan 0:343c01965543 276 camera.read_a_line( buf, line + (camera.get_vertical_size() - (int)MARMEX_OB_oled::HEIGHT) / 2, (camera.get_horizontal_size() - (int)MARMEX_OB_oled::WIDTH ) / 2, MARMEX_OB_oled::WIDTH );
nxpfan 0:343c01965543 277 line_mirroring( buf );
nxpfan 7:125538c50c22 278 alpha( line, buf, ((count >> 4) & 1) ? 60 : 8, ((count >> 4) & 1) ^ ((count >> 3) & 1) ? ((int)MARMEX_OB_oled::HEIGHT - (ap.v + 4)) : 4 + SCREEN_TOP, &ap );
nxpfan 0:343c01965543 279 oled1.blit565( 0, line, MARMEX_OB_oled::WIDTH, 1, buf );
nxpfan 0:343c01965543 280 }
nxpfan 0:343c01965543 281
nxpfan 0:343c01965543 282 count++;
nxpfan 0:343c01965543 283 camera.close_transfer();
nxpfan 0:343c01965543 284 }
nxpfan 0:343c01965543 285
nxpfan 0:343c01965543 286
nxpfan 7:125538c50c22 287 void copy_image_from_camera_to_oled_interlaced( void )
nxpfan 7:125538c50c22 288 {
nxpfan 7:125538c50c22 289 short buf[ MARMEX_OB_oled::WIDTH ];
nxpfan 7:125538c50c22 290 static int count = 0;
nxpfan 7:125538c50c22 291
nxpfan 7:125538c50c22 292 camera.open_transfer();
nxpfan 7:125538c50c22 293
nxpfan 7:125538c50c22 294 for ( int line = ((count++) & 1) + SCREEN_TOP; line < MARMEX_OB_oled::HEIGHT; line += 2 ) {
nxpfan 7:125538c50c22 295 camera.read_a_line( buf, line + (camera.get_vertical_size() - (int)MARMEX_OB_oled::HEIGHT) / 2, (camera.get_horizontal_size() - (int)MARMEX_OB_oled::WIDTH ) / 2, MARMEX_OB_oled::WIDTH );
nxpfan 7:125538c50c22 296 line_mirroring( buf );
nxpfan 7:125538c50c22 297 alpha( line, buf, ((count >> 4) & 1) ? 60 : 8, ((count >> 4) & 1) ^ ((count >> 3) & 1) ? ((int)MARMEX_OB_oled::HEIGHT - (ap.v + 4)) : 4 + SCREEN_TOP, &ap );
nxpfan 7:125538c50c22 298 oled1.blit565( 0, line, MARMEX_OB_oled::WIDTH, 1, buf );
nxpfan 7:125538c50c22 299 }
nxpfan 7:125538c50c22 300
nxpfan 7:125538c50c22 301 camera.close_transfer();
nxpfan 7:125538c50c22 302 }
nxpfan 7:125538c50c22 303 #endif
nxpfan 7:125538c50c22 304
nxpfan 1:dbe2dc31542d 305 void copy_image_from_camera_to_oled_small( void )
nxpfan 1:dbe2dc31542d 306 {
nxpfan 1:dbe2dc31542d 307 short buf[ 64 ];
nxpfan 1:dbe2dc31542d 308 static int count = 0;
nxpfan 1:dbe2dc31542d 309
nxpfan 1:dbe2dc31542d 310 camera.open_transfer();
nxpfan 1:dbe2dc31542d 311
nxpfan 1:dbe2dc31542d 312 for ( int line = 0; line < 64; line++ ) {
nxpfan 1:dbe2dc31542d 313 camera.read_a_line( buf, line, 0, 64 );
nxpfan 1:dbe2dc31542d 314 oled1.blit565( 0, line, 64, 1, buf );
nxpfan 1:dbe2dc31542d 315 }
nxpfan 1:dbe2dc31542d 316
nxpfan 1:dbe2dc31542d 317 count++;
nxpfan 1:dbe2dc31542d 318 camera.close_transfer();
nxpfan 1:dbe2dc31542d 319 }
nxpfan 1:dbe2dc31542d 320
nxpfan 1:dbe2dc31542d 321
nxpfan 0:343c01965543 322 void line_mirroring( short *buf )
nxpfan 0:343c01965543 323 {
nxpfan 0:343c01965543 324 short tmp;
nxpfan 0:343c01965543 325
nxpfan 0:343c01965543 326 for ( int i = 0; i < (MARMEX_OB_oled::WIDTH / 2); i++ ) {
nxpfan 0:343c01965543 327 tmp = buf[ i ];
nxpfan 0:343c01965543 328 buf[ i ] = buf[ (MARMEX_OB_oled::WIDTH - 1) - i ];
nxpfan 0:343c01965543 329 buf[ (MARMEX_OB_oled::WIDTH - 1) - i ] = tmp;
nxpfan 0:343c01965543 330 }
nxpfan 0:343c01965543 331 }
nxpfan 0:343c01965543 332
nxpfan 0:343c01965543 333
nxpfan 0:343c01965543 334 void oled_test_screen( void )
nxpfan 0:343c01965543 335 {
nxpfan 0:343c01965543 336 oled1.background( 0x000000 );
nxpfan 0:343c01965543 337 oled1.cls();
nxpfan 0:343c01965543 338
nxpfan 0:343c01965543 339 int colorbar_width = MARMEX_OB_oled::WIDTH / 8;
nxpfan 0:343c01965543 340
nxpfan 0:343c01965543 341 for ( int i = 0; i < 8; i++ )
nxpfan 0:343c01965543 342 oled1.fill( colorbar_width * i, 0, colorbar_width, MARMEX_OB_oled::HEIGHT, ((i & 0x4) ? 0xFF0000 : 0x000000) | ((i & 0x2) ? 0x00FF00 : 0x000000) | ((i & 0x1) ? 0x0000FF : 0x000000) );
nxpfan 0:343c01965543 343
nxpfan 0:343c01965543 344 oled1.fill( 50, 50, 64, 64, 0xCCCCCC );;
nxpfan 0:343c01965543 345
nxpfan 0:343c01965543 346 oled1.locate( 0, 2 );
nxpfan 0:343c01965543 347 oled1.printf( "MaryCemara test" );
nxpfan 0:343c01965543 348 oled1.locate( 0, 3 );
nxpfan 0:343c01965543 349 oled1.printf( "%s", (MARMEX_VB::NO_ERROR == camera.ready()) ? "Camera is ready" : "No Camera found" );
nxpfan 0:343c01965543 350 oled1.locate( 0, 4 );
nxpfan 1:dbe2dc31542d 351 //oled1.printf( "%s", "saving into BMP" );
nxpfan 0:343c01965543 352 oled1.locate( 0, 5 );
nxpfan 0:343c01965543 353 oled1.printf( "%d", camera.get_horizontal_size() );
nxpfan 0:343c01965543 354 oled1.locate( 0, 6 );
nxpfan 0:343c01965543 355 oled1.printf( "%d", camera.get_vertical_size() );
nxpfan 0:343c01965543 356
nxpfan 0:343c01965543 357 for (int i = 0; i < MARMEX_OB_oled::WIDTH; i++ )
nxpfan 0:343c01965543 358 oled1.pixel( i, 80 + sin( (float)i / 5.0 ) * 10, 0x000000 );
nxpfan 0:343c01965543 359 }
nxpfan 0:343c01965543 360
nxpfan 0:343c01965543 361
nxpfan 0:343c01965543 362 #include "bmp_handler.h"
nxpfan 0:343c01965543 363
nxpfan 0:343c01965543 364 void save_still_image( char *file_name )
nxpfan 0:343c01965543 365 {
nxpfan 0:343c01965543 366 short buf[ camera.get_horizontal_size() ];
nxpfan 0:343c01965543 367
nxpfan 0:343c01965543 368 if ( open_BMP( file_name, camera.get_horizontal_size(), camera.get_vertical_size() ) )
nxpfan 0:343c01965543 369 return;
nxpfan 0:343c01965543 370
nxpfan 0:343c01965543 371 camera.open_transfer();
nxpfan 0:343c01965543 372
nxpfan 0:343c01965543 373 for ( int line = (camera.get_vertical_size() - 1); 0 <= line; line-- ) {
nxpfan 0:343c01965543 374 camera.read_a_line( buf, line, 0, camera.get_horizontal_size() );
nxpfan 0:343c01965543 375 write_BMP( buf, camera.get_horizontal_size() );
nxpfan 0:343c01965543 376 }
nxpfan 0:343c01965543 377 camera.close_transfer();
nxpfan 0:343c01965543 378
nxpfan 0:343c01965543 379 close_BMP();
nxpfan 0:343c01965543 380 }
nxpfan 0:343c01965543 381
nxpfan 0:343c01965543 382 void capture_to_bmp( void )
nxpfan 0:343c01965543 383 {
nxpfan 0:343c01965543 384 short buf[ camera.get_horizontal_size() ];
nxpfan 0:343c01965543 385 camera.open_transfer();
nxpfan 0:343c01965543 386
nxpfan 0:343c01965543 387 if ( open_BMP( "RGB.bmp", camera.get_horizontal_size(), camera.get_vertical_size() ) )
nxpfan 0:343c01965543 388 return;
nxpfan 0:343c01965543 389
nxpfan 0:343c01965543 390 for ( int line = (camera.get_vertical_size() - 1); 0 <= line; line-- ) {
nxpfan 0:343c01965543 391 camera.read_a_line( buf, line, 0, camera.get_horizontal_size() );
nxpfan 0:343c01965543 392 // write_BMP( buf, camera.get_horizontal_size(), 0x7 );
nxpfan 0:343c01965543 393 write_BMP( buf, camera.get_horizontal_size() );
nxpfan 0:343c01965543 394 }
nxpfan 0:343c01965543 395
nxpfan 0:343c01965543 396 close_BMP();
nxpfan 0:343c01965543 397
nxpfan 0:343c01965543 398 #if 0
nxpfan 0:343c01965543 399
nxpfan 0:343c01965543 400 if ( open_BMP( "R.bmp", camera.get_horizontal_size(), camera.get_vertical_size() ) )
nxpfan 0:343c01965543 401 return;
nxpfan 0:343c01965543 402
nxpfan 0:343c01965543 403 for ( int line = (camera.get_vertical_size() - 1); 0 <= line; line-- ) {
nxpfan 0:343c01965543 404 camera.read_a_line( buf, line, 0, camera.get_horizontal_size() );
nxpfan 0:343c01965543 405 write_BMP( buf, camera.get_horizontal_size(), 0x4 );
nxpfan 0:343c01965543 406 }
nxpfan 0:343c01965543 407
nxpfan 0:343c01965543 408 close_BMP();
nxpfan 0:343c01965543 409
nxpfan 0:343c01965543 410
nxpfan 0:343c01965543 411 if ( open_BMP( "G.bmp", camera.get_horizontal_size(), camera.get_vertical_size() ) )
nxpfan 0:343c01965543 412 return;
nxpfan 0:343c01965543 413
nxpfan 0:343c01965543 414 for ( int line = (camera.get_vertical_size() - 1); 0 <= line; line-- ) {
nxpfan 0:343c01965543 415 camera.read_a_line( buf, line, 0, camera.get_horizontal_size() );
nxpfan 0:343c01965543 416 write_BMP( buf, camera.get_horizontal_size(), 0x2 );
nxpfan 0:343c01965543 417 }
nxpfan 0:343c01965543 418
nxpfan 0:343c01965543 419 close_BMP();
nxpfan 0:343c01965543 420
nxpfan 0:343c01965543 421
nxpfan 0:343c01965543 422 if ( open_BMP( "B.bmp", camera.get_horizontal_size(), camera.get_vertical_size() ) )
nxpfan 0:343c01965543 423 return;
nxpfan 0:343c01965543 424
nxpfan 0:343c01965543 425 for ( int line = (camera.get_vertical_size() - 1); 0 <= line; line-- ) {
nxpfan 0:343c01965543 426 camera.read_a_line( buf, line, 0, camera.get_horizontal_size() );
nxpfan 0:343c01965543 427 write_BMP( buf, camera.get_horizontal_size(), 0x1 );
nxpfan 0:343c01965543 428 }
nxpfan 0:343c01965543 429
nxpfan 0:343c01965543 430 close_BMP();
nxpfan 0:343c01965543 431
nxpfan 0:343c01965543 432 #endif
nxpfan 0:343c01965543 433 camera.close_transfer();
nxpfan 0:343c01965543 434 }