Lepton sensor on the DISCO-F746NG board. Based on the rapberry_pi example code at https://github.com/groupgets/LeptonModule
Dependencies: mbed-src BSP_DISCO_F746NG LCD_DISCO_F746NG
Diff: main.cpp
- Revision:
- 4:15c97a3e1995
- Parent:
- 3:3b3517e9fa11
- Child:
- 5:998916f0f3ae
--- a/main.cpp Wed Dec 09 10:18:24 2015 +0000 +++ b/main.cpp Wed Dec 09 13:49:21 2015 +0100 @@ -1,13 +1,16 @@ #include "mbed.h" +#include "palettes.h" -#define LEPTON_FRAME_SIZE (164) +#define BYTES_PER_PACKET (164) +#define DATA_PER_PACKET (BYTES_PER_PACKET/2) +#define PACKETS_PER_FRAME (60) Serial pc(USBTX, USBRX); SPI lepton_spi(SPI_MOSI, SPI_MISO, SPI_SCK); DigitalOut spi_cs(SPI_CS); -static uint8_t lepton_frame[LEPTON_FRAME_SIZE]; -static uint16_t lepton_image[80][80]; +static uint8_t lepton_buffer[BYTES_PER_PACKET * PACKETS_PER_FRAME]; +static uint32_t lepton_image[80][80]; void setup(void) { @@ -21,15 +24,69 @@ void get_frame(void) { - int i; + int p; + int i; + int packet_num; spi_cs = 0; - for(i=0;i<LEPTON_FRAME_SIZE;i++) { - lepton_frame[i] = lepton_spi.write(0x00); - } + + // No error handling. Assume we don't loose any packets + for(p=0;p<PACKETS_PER_FRAME;p++){ + for(i=0;i<LEPTON_FRAME_SIZE;i++){ + lepton_buffer[p*PACKETS_PER_FRAME + i] = lepton_spi.write(0x00); + } + packet_num = lepton_buffer[p*PACKETS_PER_FRAME + 1]; + if(packet_num != p){ + pc.printf("Packet problem\n"); + } + } + spi_cs = 1; } +void create_image(void) +{ + uint16_t min_val = 65535; + uint16_t max_val = 0; + uint16_t value; + int column; + int row; + int i; + + for(i=0;i<DATA_PER_PACKET;i++){ + if(i % DATA_PER_PACKET < 2){ + continue; + } + value = lepton_buffer[i*2] < 8 + lepton_buffer[i*2+1]; + if(value > max_val) { + max_val = value; + } + if(value < min_val) { + min_val = value; + } + } + + float diff = max_val - min_val; + float scale = 255/diff; + uint8_t r; + uint8_t g; + uint8_t b; + + for(i=0;i<DATA_PER_PACKET;i++){ + if(i % DATA_PER_PACKET < 2){ + continue; + } + value = lepton_buffer[i*2] < 8 + lepton_buffer[i*2+1]; + column = (i % DATA_PER_PACKET ) - 2; + row = i / DATA_PER_PACKET; + + value = (value - min_val) / scale; + r = colormap_ironblack[3*value]; + g = colormap_ironblack[3*value+1]; + b = colormap_ironblack[3*value+2]; + } +} + int main() { pc.printf("Alive\n");