diff --git a/software/raspberrypi_lepton3_video/.gitignore b/software/raspberrypi_lepton3_video/.gitignore new file mode 100644 index 0000000..b5e01e7 --- /dev/null +++ b/software/raspberrypi_lepton3_video/.gitignore @@ -0,0 +1,7 @@ +.DS_Store +Makefile +gen_objs +gen_mocs +*.o +raspberrypi_video + diff --git a/software/raspberrypi_lepton3_video/Grey.pal b/software/raspberrypi_lepton3_video/Grey.pal new file mode 100644 index 0000000..ee8b9e6 Binary files /dev/null and b/software/raspberrypi_lepton3_video/Grey.pal differ diff --git a/software/raspberrypi_lepton3_video/Iron.pal b/software/raspberrypi_lepton3_video/Iron.pal new file mode 100644 index 0000000..16d3804 Binary files /dev/null and b/software/raspberrypi_lepton3_video/Iron.pal differ diff --git a/software/raspberrypi_lepton3_video/LeptonThread.cpp b/software/raspberrypi_lepton3_video/LeptonThread.cpp new file mode 100644 index 0000000..2126890 --- /dev/null +++ b/software/raspberrypi_lepton3_video/LeptonThread.cpp @@ -0,0 +1,135 @@ +#include "LeptonThread.h" + +#include "Palettes.h" +#include "SPI.h" +#include "Lepton_I2C.h" +#include +#include + +#define FPS 27; + +#define SPI_PORT_INDEX 1 +#define SPI_PORT_HANDLE spi_cs1_fd +#define SPI_READ_VOSPI_AMOUNT 59 + +LeptonThread::LeptonThread():QThread() +{ + //ôîðìèðóåì ïàëèòðó ïî-óìîë÷àíèþ + for(long n=0;n<256;n++) + { + ColorMap_R[n]=n; + ColorMap_G[n]=n; + ColorMap_B[n]=n; + } +} + +LeptonThread::~LeptonThread() +{ +} + +//---------------------------------------------------------------------------------------------------- +//çàãðóçèòü ïàëèòðó +//---------------------------------------------------------------------------------------------------- +bool LeptonThread::LoadPalette(const char *file_name) +{ + FILE *file=fopen(file_name,"rb"); + if (file==NULL) return(false); + for(long n=0;n<256;n++) + { + unsigned char r; + unsigned char g; + unsigned char b; + if (fread(&r,sizeof(unsigned char),1,file)<=0) break; + if (fread(&g,sizeof(unsigned char),1,file)<=0) break; + if (fread(&b,sizeof(unsigned char),1,file)<=0) break; + ColorMap_R[n]=r; + ColorMap_G[n]=g; + ColorMap_B[n]=b; + } + fclose(file); + return(true); +} + +void LeptonThread::CreateImage(void) +{ + unsigned short *raw14_ptr=LEPTONCONTROL_GetRAW14Ptr(); + unsigned long min=0x10000; + unsigned long max=0; + unsigned long y; + unsigned long x; + unsigned short *raw14_local_ptr; + raw14_local_ptr=raw14_ptr; + unsigned long width=LEPTON_ORIGINAL_IMAGE_WIDTH; + unsigned long height=LEPTON_ORIGINAL_IMAGE_HEIGHT; + for(y=0;ymax) max=raw14; + if (raw14255) value=255; + if (value<0) value=0; + color=qRgb(ColorMap_R[value],ColorMap_G[value],ColorMap_B[value]); + myImage.setPixel(x,y,color); + } + } +} + +void LeptonThread::run() +{ + LEPTONCONTROL_Init(); + //çàãðóæàåì ïàëèòðó + LoadPalette("./Iron.pal"); + //create the initial image + myImage=QImage(LEPTON_ORIGINAL_IMAGE_WIDTH,LEPTON_ORIGINAL_IMAGE_HEIGHT,QImage::Format_RGB888); + unsigned char buffer[VOSPI_PACKAGE_SIZE*SPI_READ_VOSPI_AMOUNT]; + //open spi port + SpiOpenPort(SPI_PORT_INDEX); + while(1) + { + while(1) + { + read(SPI_PORT_HANDLE,buffer,VOSPI_PACKAGE_SIZE); + bool first_line=false; + unsigned char *buffer_ptr=buffer; + LEPTONCONTROL_PushVoSPI(buffer_ptr,first_line); + if (first_line==true) break; + } + //read data packets from lepton over SPI + read(SPI_PORT_HANDLE,buffer,VOSPI_PACKAGE_SIZE*SPI_READ_VOSPI_AMOUNT); + unsigned char *buffer_ptr=buffer; + for(long n=0;n +#include + +#include +#include +#include +#include + +#include "leptoncontrol.h" + +class LeptonThread : public QThread +{ + Q_OBJECT; + +public: + LeptonThread(); + ~LeptonThread(); + + void run(); + bool LoadPalette(const char *file_name);//çàãðóçèòü ïàëèòðó + void CreateImage(void); + +public slots: + void performFFC(); + +signals: + void updateText(QString); + void updateImage(QImage); + +private: + + QImage myImage; + uint16_t *frameBuffer; + unsigned long ColorMap_R[256];//ïàëèòðà R + unsigned long ColorMap_G[256];//ïàëèòðà G + unsigned long ColorMap_B[256];//ïàëèòðà B + +}; + +#endif diff --git a/software/raspberrypi_lepton3_video/Lepton_I2C.cpp b/software/raspberrypi_lepton3_video/Lepton_I2C.cpp new file mode 100644 index 0000000..40c7572 --- /dev/null +++ b/software/raspberrypi_lepton3_video/Lepton_I2C.cpp @@ -0,0 +1,24 @@ +#include "Lepton_I2C.h" + +#include "leptonSDKEmb32PUB/LEPTON_SDK.h" +#include "leptonSDKEmb32PUB/LEPTON_SYS.h" +#include "leptonSDKEmb32PUB/LEPTON_Types.h" + +bool _connected; + +LEP_CAMERA_PORT_DESC_T _port; + +int lepton_connect() { + LEP_OpenPort(1, LEP_CCI_TWI, 400, &_port); + _connected = true; + return 0; +} + +void lepton_perform_ffc() { + if(!_connected) { + lepton_connect(); + } + LEP_RunSysFFCNormalization(&_port); +} + +//presumably more commands could go here if desired diff --git a/software/raspberrypi_lepton3_video/Lepton_I2C.h b/software/raspberrypi_lepton3_video/Lepton_I2C.h new file mode 100644 index 0000000..a43409e --- /dev/null +++ b/software/raspberrypi_lepton3_video/Lepton_I2C.h @@ -0,0 +1,6 @@ +#ifndef LEPTON_I2C +#define LEPTON_I2C + +void lepton_perform_ffc(); + +#endif diff --git a/software/raspberrypi_lepton3_video/MyLabel.cpp b/software/raspberrypi_lepton3_video/MyLabel.cpp new file mode 100644 index 0000000..d120aa8 --- /dev/null +++ b/software/raspberrypi_lepton3_video/MyLabel.cpp @@ -0,0 +1,16 @@ +#include "MyLabel.h" + +MyLabel::MyLabel(QWidget *parent) : QLabel(parent) +{ +} +MyLabel::~MyLabel() +{ +} + +//when the system calls setImage, we'll set the label's pixmap +void MyLabel::setImage(QImage image) { + QPixmap pixmap = QPixmap::fromImage(image); + int w = this->width(); + int h = this->height(); + setPixmap(pixmap.scaled(w, h, Qt::KeepAspectRatio)); +} diff --git a/software/raspberrypi_lepton3_video/MyLabel.h b/software/raspberrypi_lepton3_video/MyLabel.h new file mode 100644 index 0000000..2a8d083 --- /dev/null +++ b/software/raspberrypi_lepton3_video/MyLabel.h @@ -0,0 +1,24 @@ +#ifndef MYLABEL_H +#define MYLABEL_H + +#include +#include +#include + + +//we extend QLabel to give it an extra slot, setImage +//this is because we can't pass a QPixmap from our thread +//so we have to pass a QImage and turn the QImage into a QPixmap on our end + +class MyLabel : public QLabel { + Q_OBJECT; + + public: + MyLabel(QWidget *parent = 0); + ~MyLabel(); + + public slots: + void setImage(QImage); +}; + +#endif diff --git a/software/raspberrypi_lepton3_video/MyLabel.h.save b/software/raspberrypi_lepton3_video/MyLabel.h.save new file mode 100644 index 0000000..36bc09a --- /dev/null +++ b/software/raspberrypi_lepton3_video/MyLabel.h.save @@ -0,0 +1,25 @@ + +#ifndef MYLABEL_H +#define MYLABEL_H + +#include +#include +#include + + +//we extend QLabel to give it an extra slot, setImage +//this is because we can't pass a QPixmap from our thread +//so we have to pass a QImage and turn the QImage into a QPixmap on our end + +class MyLabel : public QLabel { + Q_OBJECT; + + public: + MyLabel(QWidget *parent = 0); + ~MyLabel(); + + public slots: + void setImage(QImage); +}; + +#endif diff --git a/software/raspberrypi_lepton3_video/Palettes.cpp b/software/raspberrypi_lepton3_video/Palettes.cpp new file mode 100644 index 0000000..5dd67fc --- /dev/null +++ b/software/raspberrypi_lepton3_video/Palettes.cpp @@ -0,0 +1,7 @@ +#include + +const int colormap_rainbow[] = {1, 3, 74, 0, 3, 74, 0, 3, 75, 0, 3, 75, 0, 3, 76, 0, 3, 76, 0, 3, 77, 0, 3, 79, 0, 3, 82, 0, 5, 85, 0, 7, 88, 0, 10, 91, 0, 14, 94, 0, 19, 98, 0, 22, 100, 0, 25, 103, 0, 28, 106, 0, 32, 109, 0, 35, 112, 0, 38, 116, 0, 40, 119, 0, 42, 123, 0, 45, 128, 0, 49, 133, 0, 50, 134, 0, 51, 136, 0, 52, 137, 0, 53, 139, 0, 54, 142, 0, 55, 144, 0, 56, 145, 0, 58, 149, 0, 61, 154, 0, 63, 156, 0, 65, 159, 0, 66, 161, 0, 68, 164, 0, 69, 167, 0, 71, 170, 0, 73, 174, 0, 75, 179, 0, 76, 181, 0, 78, 184, 0, 79, 187, 0, 80, 188, 0, 81, 190, 0, 84, 194, 0, 87, 198, 0, 88, 200, 0, 90, 203, 0, 92, 205, 0, 94, 207, 0, 94, 208, 0, 95, 209, 0, 96, 210, 0, 97, 211, 0, 99, 214, 0, 102, 217, 0, 103, 218, 0, 104, 219, 0, 105, 220, 0, 107, 221, 0, 109, 223, 0, 111, 223, 0, 113, 223, 0, 115, 222, 0, 117, 221, 0, 118, 220, 1, 120, 219, 1, 122, 217, 2, 124, 216, 2, 126, 214, 3, 129, 212, 3, 131, 207, 4, 132, 205, 4, 133, 202, 4, 134, 197, 5, 136, 192, 6, 138, 185, 7, 141, 178, 8, 142, 172, 10, 144, 166, 10, 144, 162, 11, 145, 158, 12, 146, 153, 13, 147, 149, 15, 149, 140, 17, 151, 132, 22, 153, 120, 25, 154, 115, 28, 156, 109, 34, 158, 101, 40, 160, 94, 45, 162, 86, 51, 164, 79, 59, 167, 69, 67, 171, 60, 72, 173, 54, 78, 175, 48, 83, 177, 43, 89, 179, 39, 93, 181, 35, 98, 183, 31, 105, 185, 26, 109, 187, 23, 113, 188, 21, 118, 189, 19, 123, 191, 17, 128, 193, 14, 134, 195, 12, 138, 196, 10, 142, 197, 8, 146, 198, 6, 151, 200, 5, 155, 201, 4, 160, 203, 3, 164, 204, 2, 169, 205, 2, 173, 206, 1, 175, 207, 1, 178, 207, 1, 184, 208, 0, 190, 210, 0, 193, 211, 0, 196, 212, 0, 199, 212, 0, 202, 213, 1, 207, 214, 2, 212, 215, 3, 215, 214, 3, 218, 214, 3, 220, 213, 3, 222, 213, 4, 224, 212, 4, 225, 212, 5, 226, 212, 5, 229, 211, 5, 232, 211, 6, 232, 211, 6, 233, 211, 6, 234, 210, 6, 235, 210, 7, 236, 209, 7, 237, 208, 8, 239, 206, 8, 241, 204, 9, 242, 203, 9, 244, 202, 10, 244, 201, 10, 245, 200, 10, 245, 199, 11, 246, 198, 11, 247, 197, 12, 248, 194, 13, 249, 191, 14, 250, 189, 14, 251, 187, 15, 251, 185, 16, 252, 183, 17, 252, 178, 18, 253, 174, 19, 253, 171, 19, 254, 168, 20, 254, 165, 21, 254, 164, 21, 255, 163, 22, 255, 161, 22, 255, 159, 23, 255, 157, 23, 255, 155, 24, 255, 149, 25, 255, 143, 27, 255, 139, 28, 255, 135, 30, 255, 131, 31, 255, 127, 32, 255, 118, 34, 255, 110, 36, 255, 104, 37, 255, 101, 38, 255, 99, 39, 255, 93, 40, 255, 88, 42, 254, 82, 43, 254, 77, 45, 254, 69, 47, 254, 62, 49, 253, 57, 50, 253, 53, 52, 252, 49, 53, 252, 45, 55, 251, 39, 57, 251, 33, 59, 251, 32, 60, 251, 31, 60, 251, 30, 61, 251, 29, 61, 251, 28, 62, 250, 27, 63, 250, 27, 65, 249, 26, 66, 249, 26, 68, 248, 25, 70, 248, 24, 73, 247, 24, 75, 247, 25, 77, 247, 25, 79, 247, 26, 81, 247, 32, 83, 247, 35, 85, 247, 38, 86, 247, 42, 88, 247, 46, 90, 247, 50, 92, 248, 55, 94, 248, 59, 96, 248, 64, 98, 248, 72, 101, 249, 81, 104, 249, 87, 106, 250, 93, 108, 250, 95, 109, 250, 98, 110, 250, 100, 111, 251, 101, 112, 251, 102, 113, 251, 109, 117, 252, 116, 121, 252, 121, 123, 253, 126, 126, 253, 130, 128, 254, 135, 131, 254, 139, 133, 254, 144, 136, 254, 151, 140, 255, 158, 144, 255, 163, 146, 255, 168, 149, 255, 173, 152, 255, 176, 153, 255, 178, 155, 255, 184, 160, 255, 191, 165, 255, 195, 168, 255, 199, 172, 255, 203, 175, 255, 207, 179, 255, 211, 182, 255, 216, 185, 255, 218, 190, 255, 220, 196, 255, 222, 200, 255, 225, 202, 255, 227, 204, 255, 230, 206, 255, 233, 208}; + +const int colormap_grayscale[] = {0, 0, 0, 1, 1, 1, 2, 2, 2, 3, 3, 3, 4, 4, 4, 5, 5, 5, 6, 6, 6, 7, 7, 7, 8, 8, 8, 9, 9, 9, 10, 10, 10, 11, 11, 11, 12, 12, 12, 13, 13, 13, 14, 14, 14, 15, 15, 15, 16, 16, 16, 17, 17, 17, 18, 18, 18, 19, 19, 19, 20, 20, 20, 21, 21, 21, 22, 22, 22, 23, 23, 23, 24, 24, 24, 25, 25, 25, 26, 26, 26, 27, 27, 27, 28, 28, 28, 29, 29, 29, 30, 30, 30, 31, 31, 31, 32, 32, 32, 33, 33, 33, 34, 34, 34, 35, 35, 35, 36, 36, 36, 37, 37, 37, 38, 38, 38, 39, 39, 39, 40, 40, 40, 41, 41, 41, 42, 42, 42, 43, 43, 43, 44, 44, 44, 45, 45, 45, 46, 46, 46, 47, 47, 47, 48, 48, 48, 49, 49, 49, 50, 50, 50, 51, 51, 51, 52, 52, 52, 53, 53, 53, 54, 54, 54, 55, 55, 55, 56, 56, 56, 57, 57, 57, 58, 58, 58, 59, 59, 59, 60, 60, 60, 61, 61, 61, 62, 62, 62, 63, 63, 63, 64, 64, 64, 65, 65, 65, 66, 66, 66, 67, 67, 67, 68, 68, 68, 69, 69, 69, 70, 70, 70, 71, 71, 71, 72, 72, 72, 73, 73, 73, 74, 74, 74, 75, 75, 75, 76, 76, 76, 77, 77, 77, 78, 78, 78, 79, 79, 79, 80, 80, 80, 81, 81, 81, 82, 82, 82, 83, 83, 83, 84, 84, 84, 85, 85, 85, 86, 86, 86, 87, 87, 87, 88, 88, 88, 89, 89, 89, 90, 90, 90, 91, 91, 91, 92, 92, 92, 93, 93, 93, 94, 94, 94, 95, 95, 95, 96, 96, 96, 97, 97, 97, 98, 98, 98, 99, 99, 99, 100, 100, 100, 101, 101, 101, 102, 102, 102, 103, 103, 103, 104, 104, 104, 105, 105, 105, 106, 106, 106, 107, 107, 107, 108, 108, 108, 109, 109, 109, 110, 110, 110, 111, 111, 111, 112, 112, 112, 113, 113, 113, 114, 114, 114, 115, 115, 115, 116, 116, 116, 117, 117, 117, 118, 118, 118, 119, 119, 119, 120, 120, 120, 121, 121, 121, 122, 122, 122, 123, 123, 123, 124, 124, 124, 125, 125, 125, 126, 126, 126, 127, 127, 127, 128, 128, 128, 129, 129, 129, 130, 130, 130, 131, 131, 131, 132, 132, 132, 133, 133, 133, 134, 134, 134, 135, 135, 135, 136, 136, 136, 137, 137, 137, 138, 138, 138, 139, 139, 139, 140, 140, 140, 141, 141, 141, 142, 142, 142, 143, 143, 143, 144, 144, 144, 145, 145, 145, 146, 146, 146, 147, 147, 147, 148, 148, 148, 149, 149, 149, 150, 150, 150, 151, 151, 151, 152, 152, 152, 153, 153, 153, 154, 154, 154, 155, 155, 155, 156, 156, 156, 157, 157, 157, 158, 158, 158, 159, 159, 159, 160, 160, 160, 161, 161, 161, 162, 162, 162, 163, 163, 163, 164, 164, 164, 165, 165, 165, 166, 166, 166, 167, 167, 167, 168, 168, 168, 169, 169, 169, 170, 170, 170, 171, 171, 171, 172, 172, 172, 173, 173, 173, 174, 174, 174, 175, 175, 175, 176, 176, 176, 177, 177, 177, 178, 178, 178, 179, 179, 179, 180, 180, 180, 181, 181, 181, 182, 182, 182, 183, 183, 183, 184, 184, 184, 185, 185, 185, 186, 186, 186, 187, 187, 187, 188, 188, 188, 189, 189, 189, 190, 190, 190, 191, 191, 191, 192, 192, 192, 193, 193, 193, 194, 194, 194, 195, 195, 195, 196, 196, 196, 197, 197, 197, 198, 198, 198, 199, 199, 199, 200, 200, 200, 201, 201, 201, 202, 202, 202, 203, 203, 203, 204, 204, 204, 205, 205, 205, 206, 206, 206, 207, 207, 207, 208, 208, 208, 209, 209, 209, 210, 210, 210, 211, 211, 211, 212, 212, 212, 213, 213, 213, 214, 214, 214, 215, 215, 215, 216, 216, 216, 217, 217, 217, 218, 218, 218, 219, 219, 219, 220, 220, 220, 221, 221, 221, 222, 222, 222, 223, 223, 223, 224, 224, 224, 225, 225, 225, 226, 226, 226, 227, 227, 227, 228, 228, 228, 229, 229, 229, 230, 230, 230, 231, 231, 231, 232, 232, 232, 233, 233, 233, 234, 234, 234, 235, 235, 235, 236, 236, 236, 237, 237, 237, 238, 238, 238, 239, 239, 239, 240, 240, 240, 241, 241, 241, 242, 242, 242, 243, 243, 243, 244, 244, 244, 245, 245, 245, 246, 246, 246, 247, 247, 247, 248, 248, 248, 249, 249, 249, 250, 250, 250, 251, 251, 251, 252, 252, 252, 253, 253, 253, 254, 254, 254, 255, 255, 255}; + +const int colormap_ironblack[] = {255, 255, 255, 253, 253, 253, 251, 251, 251, 249, 249, 249, 247, 247, 247, 245, 245, 245, 243, 243, 243, 241, 241, 241, 239, 239, 239, 237, 237, 237, 235, 235, 235, 233, 233, 233, 231, 231, 231, 229, 229, 229, 227, 227, 227, 225, 225, 225, 223, 223, 223, 221, 221, 221, 219, 219, 219, 217, 217, 217, 215, 215, 215, 213, 213, 213, 211, 211, 211, 209, 209, 209, 207, 207, 207, 205, 205, 205, 203, 203, 203, 201, 201, 201, 199, 199, 199, 197, 197, 197, 195, 195, 195, 193, 193, 193, 191, 191, 191, 189, 189, 189, 187, 187, 187, 185, 185, 185, 183, 183, 183, 181, 181, 181, 179, 179, 179, 177, 177, 177, 175, 175, 175, 173, 173, 173, 171, 171, 171, 169, 169, 169, 167, 167, 167, 165, 165, 165, 163, 163, 163, 161, 161, 161, 159, 159, 159, 157, 157, 157, 155, 155, 155, 153, 153, 153, 151, 151, 151, 149, 149, 149, 147, 147, 147, 145, 145, 145, 143, 143, 143, 141, 141, 141, 139, 139, 139, 137, 137, 137, 135, 135, 135, 133, 133, 133, 131, 131, 131, 129, 129, 129, 126, 126, 126, 124, 124, 124, 122, 122, 122, 120, 120, 120, 118, 118, 118, 116, 116, 116, 114, 114, 114, 112, 112, 112, 110, 110, 110, 108, 108, 108, 106, 106, 106, 104, 104, 104, 102, 102, 102, 100, 100, 100, 98, 98, 98, 96, 96, 96, 94, 94, 94, 92, 92, 92, 90, 90, 90, 88, 88, 88, 86, 86, 86, 84, 84, 84, 82, 82, 82, 80, 80, 80, 78, 78, 78, 76, 76, 76, 74, 74, 74, 72, 72, 72, 70, 70, 70, 68, 68, 68, 66, 66, 66, 64, 64, 64, 62, 62, 62, 60, 60, 60, 58, 58, 58, 56, 56, 56, 54, 54, 54, 52, 52, 52, 50, 50, 50, 48, 48, 48, 46, 46, 46, 44, 44, 44, 42, 42, 42, 40, 40, 40, 38, 38, 38, 36, 36, 36, 34, 34, 34, 32, 32, 32, 30, 30, 30, 28, 28, 28, 26, 26, 26, 24, 24, 24, 22, 22, 22, 20, 20, 20, 18, 18, 18, 16, 16, 16, 14, 14, 14, 12, 12, 12, 10, 10, 10, 8, 8, 8, 6, 6, 6, 4, 4, 4, 2, 2, 2, 0, 0, 0, 0, 0, 9, 2, 0, 16, 4, 0, 24, 6, 0, 31, 8, 0, 38, 10, 0, 45, 12, 0, 53, 14, 0, 60, 17, 0, 67, 19, 0, 74, 21, 0, 82, 23, 0, 89, 25, 0, 96, 27, 0, 103, 29, 0, 111, 31, 0, 118, 36, 0, 120, 41, 0, 121, 46, 0, 122, 51, 0, 123, 56, 0, 124, 61, 0, 125, 66, 0, 126, 71, 0, 127, 76, 1, 128, 81, 1, 129, 86, 1, 130, 91, 1, 131, 96, 1, 132, 101, 1, 133, 106, 1, 134, 111, 1, 135, 116, 1, 136, 121, 1, 136, 125, 2, 137, 130, 2, 137, 135, 3, 137, 139, 3, 138, 144, 3, 138, 149, 4, 138, 153, 4, 139, 158, 5, 139, 163, 5, 139, 167, 5, 140, 172, 6, 140, 177, 6, 140, 181, 7, 141, 186, 7, 141, 189, 10, 137, 191, 13, 132, 194, 16, 127, 196, 19, 121, 198, 22, 116, 200, 25, 111, 203, 28, 106, 205, 31, 101, 207, 34, 95, 209, 37, 90, 212, 40, 85, 214, 43, 80, 216, 46, 75, 218, 49, 69, 221, 52, 64, 223, 55, 59, 224, 57, 49, 225, 60, 47, 226, 64, 44, 227, 67, 42, 228, 71, 39, 229, 74, 37, 230, 78, 34, 231, 81, 32, 231, 85, 29, 232, 88, 27, 233, 92, 24, 234, 95, 22, 235, 99, 19, 236, 102, 17, 237, 106, 14, 238, 109, 12, 239, 112, 12, 240, 116, 12, 240, 119, 12, 241, 123, 12, 241, 127, 12, 242, 130, 12, 242, 134, 12, 243, 138, 12, 243, 141, 13, 244, 145, 13, 244, 149, 13, 245, 152, 13, 245, 156, 13, 246, 160, 13, 246, 163, 13, 247, 167, 13, 247, 171, 13, 248, 175, 14, 248, 178, 15, 249, 182, 16, 249, 185, 18, 250, 189, 19, 250, 192, 20, 251, 196, 21, 251, 199, 22, 252, 203, 23, 252, 206, 24, 253, 210, 25, 253, 213, 27, 254, 217, 28, 254, 220, 29, 255, 224, 30, 255, 227, 39, 255, 229, 53, 255, 231, 67, 255, 233, 81, 255, 234, 95, 255, 236, 109, 255, 238, 123, 255, 240, 137, 255, 242, 151, 255, 244, 165, 255, 246, 179, 255, 248, 193, 255, 249, 207, 255, 251, 221, 255, 253, 235, 255, 255, 24}; diff --git a/software/raspberrypi_lepton3_video/Palettes.h b/software/raspberrypi_lepton3_video/Palettes.h new file mode 100644 index 0000000..ec91834 --- /dev/null +++ b/software/raspberrypi_lepton3_video/Palettes.h @@ -0,0 +1,8 @@ +#ifndef PALETTES_H +#define PALETTES_H + +extern const int colormap_rainbow[]; +extern const int colormap_grayscale[]; +extern const int colormap_ironblack[]; + +#endif diff --git a/software/raspberrypi_lepton3_video/README.md b/software/raspberrypi_lepton3_video/README.md new file mode 100644 index 0000000..af6f63f --- /dev/null +++ b/software/raspberrypi_lepton3_video/README.md @@ -0,0 +1,26 @@ +This example is meant for Raspberry Pi and Pi2 and has been tested with Raspbian. + +Enable the SPI and I2C interfaces on the Pi. + +Install the 'qt4-dev-tools' package, which allows compiling of QT applications. + +To build (will build any SDK dependencies as well): +qmake && make + +To clean: +make sdkclean && make distclean + +If you wish to run this application without using sudo, you should add the user "pi" to the usergroup "i2c". + +---- + +In order for the application to run properly, a Lepton camera must be attached in a specific way to the SPI, power, and ground pins of the Raspi's GPIO interface, as well as the I2C SDA/SCL pins: + +Lepton's GND pin should be connected to RasPi's ground. +Lepton's CS pin should be connected to RasPi's CE1 pin. +Lepton's MISO pin should be connected to RasPI's MISO pin. +Lepton's CLK pin should be connected to RasPI's SCLK pin. +Lepton's VIN pin should be connected to RasPI's 3v3 pin. +Lepton's SDA pin should be connected to RasPI's SDA pin. +Lepton's SCL pin should be connected to RasPI's SCL pin. + diff --git a/software/raspberrypi_lepton3_video/Rainbow.pal b/software/raspberrypi_lepton3_video/Rainbow.pal new file mode 100644 index 0000000..963977c Binary files /dev/null and b/software/raspberrypi_lepton3_video/Rainbow.pal differ diff --git a/software/raspberrypi_lepton3_video/SPI.cpp b/software/raspberrypi_lepton3_video/SPI.cpp new file mode 100644 index 0000000..026a72b --- /dev/null +++ b/software/raspberrypi_lepton3_video/SPI.cpp @@ -0,0 +1,114 @@ +#include "SPI.h" + +int spi_cs0_fd = -1; +int spi_cs1_fd = -1; + +unsigned char spi_mode = SPI_MODE_3; +unsigned char spi_bitsPerWord = 8; +//unsigned int spi_speed = 32000000; +unsigned int spi_speed; + +int SpiOpenPort (int spi_device) +{ + int status_value = -1; + int *spi_cs_fd; + + + //----- SET SPI MODE ----- + //SPI_MODE_0 (0,0) CPOL=0 (Clock Idle low level), CPHA=0 (SDO transmit/change edge active to idle) + //SPI_MODE_1 (0,1) CPOL=0 (Clock Idle low level), CPHA=1 (SDO transmit/change edge idle to active) + //SPI_MODE_2 (1,0) CPOL=1 (Clock Idle high level), CPHA=0 (SDO transmit/change edge active to idle) + //SPI_MODE_3 (1,1) CPOL=1 (Clock Idle high level), CPHA=1 (SDO transmit/change edge idle to active) + spi_mode = SPI_MODE_3; + + //----- SET BITS PER WORD ----- + spi_bitsPerWord = 8; + + //----- SET SPI BUS SPEED ----- + //spi_speed = 16000000; //1000000 = 1MHz (1uS per bit) + //spi_speed = 28000000; //1000000 = 1MHz (1uS per bit) + spi_speed = 20000000; //1000000 = 1MHz (1uS per bit) + //spi_speed = 28000000; //1000000 = 1MHz (1uS per bit) + // was 32M + + + if (spi_device) + spi_cs_fd = &spi_cs1_fd; + else + spi_cs_fd = &spi_cs0_fd; + + + if (spi_device) + *spi_cs_fd = open(std::string("/dev/spidev0.1").c_str(), O_RDWR); + else + *spi_cs_fd = open(std::string("/dev/spidev0.0").c_str(), O_RDWR); + + if (*spi_cs_fd < 0) + { + perror("Error - Could not open SPI device"); + exit(1); + } + + status_value = ioctl(*spi_cs_fd, SPI_IOC_WR_MODE, &spi_mode); + if(status_value < 0) + { + perror("Could not set SPIMode (WR)...ioctl fail"); + exit(1); + } + + status_value = ioctl(*spi_cs_fd, SPI_IOC_RD_MODE, &spi_mode); + if(status_value < 0) + { + perror("Could not set SPIMode (RD)...ioctl fail"); + exit(1); + } + + status_value = ioctl(*spi_cs_fd, SPI_IOC_WR_BITS_PER_WORD, &spi_bitsPerWord); + if(status_value < 0) + { + perror("Could not set SPI bitsPerWord (WR)...ioctl fail"); + exit(1); + } + + status_value = ioctl(*spi_cs_fd, SPI_IOC_RD_BITS_PER_WORD, &spi_bitsPerWord); + if(status_value < 0) + { + perror("Could not set SPI bitsPerWord(RD)...ioctl fail"); + exit(1); + } + + status_value = ioctl(*spi_cs_fd, SPI_IOC_WR_MAX_SPEED_HZ, &spi_speed); + if(status_value < 0) + { + perror("Could not set SPI speed (WR)...ioctl fail"); + exit(1); + } + + status_value = ioctl(*spi_cs_fd, SPI_IOC_RD_MAX_SPEED_HZ, &spi_speed); + if(status_value < 0) + { + perror("Could not set SPI speed (RD)...ioctl fail"); + exit(1); + } + return(status_value); +} + +int SpiClosePort(int spi_device) +{ + int status_value = -1; + int *spi_cs_fd; + + if (spi_device) + spi_cs_fd = &spi_cs1_fd; + else + spi_cs_fd = &spi_cs0_fd; + + + status_value = close(*spi_cs_fd); + if(status_value < 0) + { + perror("Error - Could not close SPI device"); + exit(1); + } + return(status_value); +} diff --git a/software/raspberrypi_lepton3_video/SPI.h b/software/raspberrypi_lepton3_video/SPI.h new file mode 100644 index 0000000..7d900d6 --- /dev/null +++ b/software/raspberrypi_lepton3_video/SPI.h @@ -0,0 +1,37 @@ +/* + * SPI testing utility (using spidev driver) + * + * Copyright (c) 2007 MontaVista Software, Inc. + * Copyright (c) 2007 Anton Vorontsov + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License. + * + * Cross-compile with cross-gcc -I/path/to/cross-kernel/include + */ + +#ifndef SPI_H +#define SPI_H + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +extern int spi_cs0_fd; +extern int spi_cs1_fd; +extern unsigned char spi_mode; +extern unsigned char spi_bitsPerWord; +extern unsigned int spi_speed; + +int SpiOpenPort(int spi_device); +int SpiClosePort(int spi_device); + +#endif diff --git a/software/raspberrypi_lepton3_video/connected.png b/software/raspberrypi_lepton3_video/connected.png new file mode 100644 index 0000000..5ef541a Binary files /dev/null and b/software/raspberrypi_lepton3_video/connected.png differ diff --git a/software/raspberrypi_lepton3_video/leptoncontrol.cpp b/software/raspberrypi_lepton3_video/leptoncontrol.cpp new file mode 100644 index 0000000..376b153 --- /dev/null +++ b/software/raspberrypi_lepton3_video/leptoncontrol.cpp @@ -0,0 +1,184 @@ +#include "leptoncontrol.h" +#include + +static unsigned short RAW14Image[LEPTON_ORIGINAL_IMAGE_HEIGHT*LEPTON_ORIGINAL_IMAGE_WIDTH];//ñîáèðàåìîå èçîáðàæåíèå + +#define RESYNC_TIMEOUT 19890 +#define NO_SEGMENT -1 +#define ERROR_PACKAGE -2 + +//---------------------------------------------------------------------------------------------------- +//èíèöèàëèçàöèÿ +//---------------------------------------------------------------------------------------------------- +void LEPTONCONTROL_Init(void) +{ +} + +//---------------------------------------------------------------------------------------------------- +//âû÷èñëèòü crc +//---------------------------------------------------------------------------------------------------- +void LEPTONCONTROL_CalculateCRC(unsigned short *crc,unsigned char byte) +{ + (*crc)^=(byte<<8); + for(unsigned char n=0;n<8;n++) + { + if ((*crc)&0x8000) *crc=((*crc)<<1)^0x1021; + else (*crc)<<=1; + } +} + + +//---------------------------------------------------------------------------------------------------- +//---------------------------------------------------------------------------------------------------- +long LEPTONCONTROL_ReadSegment(unsigned short *raw14_ptr,unsigned char data[VOSPI_PACKAGE_SIZE],bool &first_line) +{ + static long current_package=-1; + static long segment=-1; + long n; + first_line=false; + if ((data[0]&0x0F)==0x0F) return(NO_SEGMENT);//îòáðàñûâàåìûé ïàêåò + unsigned short crc=data[2]; + crc<<=8; + crc|=data[3]; + //ñ÷èòàåì CRC + unsigned short crc16=0; + LEPTONCONTROL_CalculateCRC(&crc16,data[0]&0x0F); + LEPTONCONTROL_CalculateCRC(&crc16,data[1]); + LEPTONCONTROL_CalculateCRC(&crc16,0); + LEPTONCONTROL_CalculateCRC(&crc16,0); + for(n=4;n>4;//íîìåð êàäðà áûâàåò òîëüêî â 20 ïàêåòå + segment=ttt; + } + if (current_package<0) return(NO_SEGMENT); + if (current_package!=package) + { + current_package=-1; + return(ERROR_PACKAGE); + } + unsigned short *raw_ptr=raw14_ptr+current_package*VOSPI_PACKAGE_LINE_SIZE/2; + for(n=0;n>4;//íîìåð êàäðà áûâàåò òîëüêî â 20 ïàêåòå + if (ttt==0) + { + CurrentPackage=0; + CurrentSegment=0; + return(false);//ëþáîé ñåãìåíò ñ íóëåâûì ttt äîëæåí áûòü ïðîèãíîðèðîâàí (â äîêóìåíòàöèè îøèáêà?) + } + //ñîáèðàåì èçîáðàæåíèå + ttt--; + if (CurrentSegment!=ttt)//íîìåð êàäðà íåâåðíûé + { + CurrentPackage=0; + CurrentSegment=0; + return(false); + } + } + if (CurrentPackage!=package)//íîìåð ñòðîêè íåâåðíûé + { + CurrentPackage=0; + CurrentSegment=0; + return(false); + } + unsigned long sub_package=(CurrentSegment*VOSPI_FRAME_HEIGHT)+CurrentPackage; + unsigned short *raw_ptr=&(RAW14Image[(sub_package>>1)*LEPTON_ORIGINAL_IMAGE_WIDTH+(sub_package&0x01)*VOSPI_FRAME_WIDTH]); + for(n=0;n + +//èñõîäíûå ðàçìåðû èçîáðàæåíèÿ (íå ïåðåâ¸ðíóòîå) +#define LEPTON_ORIGINAL_IMAGE_WIDTH 160 +#define LEPTON_ORIGINAL_IMAGE_HEIGHT 120 + +//âûñîòà êàäðà VoSPI +#define VOSPI_FRAME_HEIGHT 60 +//øèðèíà êàäðà VoSPI +#define VOSPI_FRAME_WIDTH 80 +//ðàçìåð ïàêåòà VoSPI à áàéòàõ (164 äëÿ RAW14 è 244 äëÿ RGB) +#define VOSPI_PACKAGE_SIZE 164 +//ðàçìåð ñòðîêè ïàêåòà VoSPI â áàéòàõ +#define VOSPI_PACKAGE_LINE_SIZE 160 + +#define VOSPI_SEGMENT_LINE_AMOUNT 60 + +void LEPTONCONTROL_Init(void);//èíèöèàëèçàöèÿ +void LEPTONCONTROL_CalculateCRC(unsigned short *crc,unsigned char byte);//âû÷èñëèòü crc +bool LEPTONCONTROL_PushVoSPI(unsigned char data[VOSPI_PACKAGE_SIZE],bool &first_line);//ïîäàòü äàííûå îäíîãî ïàêåòà VoSPI íà âõîä ìîäóëÿ +unsigned short *LEPTONCONTROL_GetRAW14Ptr(void);//ïîëó÷èòü óêàçàòåëü íà äàííûå ñîáðàííîãî èçîáðàæåíèÿ + +#endif diff --git a/software/raspberrypi_lepton3_video/main.cpp b/software/raspberrypi_lepton3_video/main.cpp new file mode 100644 index 0000000..57501a7 --- /dev/null +++ b/software/raspberrypi_lepton3_video/main.cpp @@ -0,0 +1,56 @@ +#include +#include +#include +#include + +#include +#include +#include +#include +#include + +#include "LeptonThread.h" +#include "MyLabel.h" + +int main( int argc, char **argv ) +{ + //create the app + QApplication a( argc, argv ); + + QWidget *myWidget = new QWidget; + myWidget->setGeometry(400, 300, 340, 290); + + //create an image placeholder for myLabel + //fill the top left corner with red, just bcuz + QImage myImage; + myImage = QImage(320, 240, QImage::Format_RGB888); + QRgb red = qRgb(255,0,0); + for(int i=0;i<160;i++) { + for(int j=0;j<120;j++) { + myImage.setPixel(i, j, red); + } + } + + //create a label, and set it's image to the placeholder + MyLabel myLabel(myWidget); + myLabel.setGeometry(10, 10, 320, 240); + myLabel.setPixmap(QPixmap::fromImage(myImage)); + + //create a FFC button + QPushButton *button1 = new QPushButton("Perform FFC", myWidget); + button1->setGeometry(320/2-50, 290-35, 100, 30); + + //create a thread to gather SPI data + //when the thread emits updateImage, the label should update its image accordingly + LeptonThread *thread = new LeptonThread(); + QObject::connect(thread, SIGNAL(updateImage(QImage)), &myLabel, SLOT(setImage(QImage))); + + //connect ffc button to the thread's ffc action + QObject::connect(button1, SIGNAL(clicked()), thread, SLOT(performFFC())); + thread->start(); + + myWidget->show(); + + return a.exec(); +} + diff --git a/software/raspberrypi_lepton3_video/raspberrypi_video.pro b/software/raspberrypi_lepton3_video/raspberrypi_video.pro new file mode 100644 index 0000000..f1c5a6a --- /dev/null +++ b/software/raspberrypi_lepton3_video/raspberrypi_video.pro @@ -0,0 +1,30 @@ + +TEMPLATE = app +QT += core gui +greaterThan(QT_MAJOR_VERSION, 4): QT += widgets + +TARGET = + +RPI_LIBS = ../raspberrypi_libs +LEPTONSDK = leptonSDKEmb32PUB + +PRE_TARGETDEPS += sdk +QMAKE_EXTRA_TARGETS += sdk sdkclean +sdk.commands = make -C $${RPI_LIBS}/$${LEPTONSDK} +sdkclean.commands = make -C $${RPI_LIBS}/$${LEPTONSDK} clean + +DEPENDPATH += . +INCLUDEPATH += . $${RPI_LIBS} + +DESTDIR=. +OBJECTS_DIR=gen_objs +MOC_DIR=gen_mocs + +HEADERS += *.h + +SOURCES += *.cpp + +unix:LIBS += -L$${RPI_LIBS}/$${LEPTONSDK}/Debug -lLEPTON_SDK + +unix:QMAKE_CLEAN += -r $(OBJECTS_DIR) $${MOC_DIR} +