example for for using the flir lepton on the stm32nucleo_401re
Dependencies: mbed
Diff: main.cpp
- Revision:
- 1:dd6a90cf2191
- Parent:
- 0:4065e63beba6
- Child:
- 2:5daa51a2ce48
--- a/main.cpp Thu Sep 18 05:27:49 2014 +0000 +++ b/main.cpp Thu Sep 18 13:24:50 2014 +0000 @@ -3,8 +3,6 @@ Serial pc(SERIAL_TX, SERIAL_RX); SPI lepton_spi(SPI_MOSI, SPI_MISO, SPI_SCK); DigitalOut spi_cs(SPI_CS); - -//DigitalOut myled(LED1); #define VOSPI_FRAME_SIZE (164) uint8_t lepton_frame_packet[VOSPI_FRAME_SIZE]; @@ -28,11 +26,67 @@ pc.putc((lepton_image[i][j]>>8)&0xff); while(pc.writeable() == 0); pc.putc(lepton_image[i][j]&0xff); - wait_us(1); + //wait_us(1); } } } + +int print_image_binary_state =-1; +int print_image_binary_i; +int print_image_binary_j; + +static void print_image_binary_background(void) +{ + if( print_image_binary_state == -1) + { + return; + } + else if( print_image_binary_state == 0) + { + pc.putc(0xDE); + print_image_binary_state++; + } + else if( print_image_binary_state == 1) + { + pc.putc(0xAD); + print_image_binary_state++; + } + else if( print_image_binary_state == 2) + { + pc.putc(0xBE); + print_image_binary_state++; + } + else if( print_image_binary_state == 3) + { + pc.putc(0xEF); + print_image_binary_state++; + print_image_binary_i = 0; + print_image_binary_j = 0; + } + else if( print_image_binary_state == 4) + { + while(pc.writeable() == 0); + pc.putc((lepton_image[print_image_binary_i][print_image_binary_j]>>8)&0xff); + while(pc.writeable() == 0); + pc.putc(lepton_image[print_image_binary_i][print_image_binary_j]&0xff); + + print_image_binary_j++; + if(print_image_binary_j>=80) + { + print_image_binary_j=0; + print_image_binary_i++; + if(print_image_binary_i>=60) + { + print_image_binary_state = -1; + } + } + } + +} + + + int lost_frame_counter = 0; int last_frame_number; @@ -52,17 +106,10 @@ spi_cs = 0; for(i=0;i<VOSPI_FRAME_SIZE;i++) { - lepton_frame_packet[i] = lepton_spi.write(0x55); + lepton_frame_packet[i] = lepton_spi.write(0x00); } spi_cs = 1; - //pc.printf("%x %x \n\r",lepton_frame_packet[0], lepton_frame_packet[1]); - - //for(i=0;i<VOSPI_FRAME_SIZE;i++) - //{ - // pc.printf("%x,",lepton_frame_packet[i]); - // } - //pc.printf("\n\r"); if(((lepton_frame_packet[0]&0xf) != 0x0f)) { @@ -75,19 +122,22 @@ last_crc = lepton_frame_packet[3]<<8 | lepton_frame_packet[4]; } frame_number = lepton_frame_packet[1]; - if( (frame_number>0) && (frame_number<60)) - { - pc.printf("%d\n\r",frame_number); - } - + if(frame_number < 60 ) { lost_frame_counter = 0; - for(i=0;i<80;i++) + if(print_image_binary_state == -1) { - lepton_image[frame_number][i] = (lepton_frame_packet[2*i+4] << 8 | lepton_frame_packet[2*i+5]); + for(i=0;i<80;i++) + { + lepton_image[frame_number][i] = (lepton_frame_packet[2*i+4] << 8 | lepton_frame_packet[2*i+5]); + } } } + else + { + lost_frame_counter++; + } if( frame_number == 59) { frame_complete = 1; @@ -96,11 +146,15 @@ } else { - wait_us(10); + if(last_frame_number ==0) + { + //wait_us(10); + //pc.printf("."); + } } lost_frame_counter++; - if(lost_frame_counter>1000) + if(lost_frame_counter>100) { need_resync = 1; lost_frame_counter = 0; @@ -109,8 +163,7 @@ if(need_resync) { - pc.printf("resync\n\r"); - wait_us(185); + wait_ms(185); need_resync = 0; } @@ -121,15 +174,13 @@ { frame_counter++; { - if(frame_counter%9 ==0) + if(frame_counter%18 ==0) { - //print_image_binary(); + print_image_binary_state = 0; } - pc.printf("print_image_binary\n\r"); } new_frame = 0; } - frame_complete = 0; } } @@ -137,21 +188,19 @@ int main() { - - //pc.baud(9600); pc.baud(115200); - //pc.baud(1000000); - pc.printf("Hello World !\n"); lepton_spi.format(8,3); lepton_spi.frequency(20000000); spi_cs = 1; + spi_cs = 0; + spi_cs = 1; - wait_us(185); + wait_ms(185); while(1) { - //myled = !myled; transfer(); + print_image_binary_background(); } } \ No newline at end of file