├── .gitignore ├── LICENSE ├── Makefile ├── README.md ├── palettes ├── 15.raw ├── 17.raw ├── 7.raw ├── 85.raw ├── 92.raw ├── Grayscale.raw ├── Grey.raw ├── Iron2.raw ├── Iron_Black.raw └── Rainbow.raw ├── scripts ├── gstreamer_rgbcamera ├── gstreamer_testmosaic └── load_v4l2loopback └── src ├── flirone.c ├── font5x7.h └── plank.h /.gitignore: -------------------------------------------------------------------------------- 1 | src/flirone.o 2 | flirone 3 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | GNU GENERAL PUBLIC LICENSE 2 | Version 2, June 1991 3 | 4 | Copyright (C) 1989, 1991 Free Software Foundation, Inc., 5 | 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 6 | Everyone is permitted to copy and distribute verbatim copies 7 | of this license document, but changing it is not allowed. 8 | 9 | Preamble 10 | 11 | The licenses for most software are designed to take away your 12 | freedom to share and change it. By contrast, the GNU General Public 13 | License is intended to guarantee your freedom to share and change free 14 | software--to make sure the software is free for all its users. This 15 | General Public License applies to most of the Free Software 16 | Foundation's software and to any other program whose authors commit to 17 | using it. (Some other Free Software Foundation software is covered by 18 | the GNU Lesser General Public License instead.) You can apply it to 19 | your programs, too. 20 | 21 | When we speak of free software, we are referring to freedom, not 22 | price. Our General Public Licenses are designed to make sure that you 23 | have the freedom to distribute copies of free software (and charge for 24 | this service if you wish), that you receive source code or can get it 25 | if you want it, that you can change the software or use pieces of it 26 | in new free programs; and that you know you can do these things. 27 | 28 | To protect your rights, we need to make restrictions that forbid 29 | anyone to deny you these rights or to ask you to surrender the rights. 30 | These restrictions translate to certain responsibilities for you if you 31 | distribute copies of the software, or if you modify it. 32 | 33 | For example, if you distribute copies of such a program, whether 34 | gratis or for a fee, you must give the recipients all the rights that 35 | you have. You must make sure that they, too, receive or can get the 36 | source code. And you must show them these terms so they know their 37 | rights. 38 | 39 | We protect your rights with two steps: (1) copyright the software, and 40 | (2) offer you this license which gives you legal permission to copy, 41 | distribute and/or modify the software. 42 | 43 | Also, for each author's protection and ours, we want to make certain 44 | that everyone understands that there is no warranty for this free 45 | software. If the software is modified by someone else and passed on, we 46 | want its recipients to know that what they have is not the original, so 47 | that any problems introduced by others will not reflect on the original 48 | authors' reputations. 49 | 50 | Finally, any free program is threatened constantly by software 51 | patents. We wish to avoid the danger that redistributors of a free 52 | program will individually obtain patent licenses, in effect making the 53 | program proprietary. To prevent this, we have made it clear that any 54 | patent must be licensed for everyone's free use or not licensed at all. 55 | 56 | The precise terms and conditions for copying, distribution and 57 | modification follow. 58 | 59 | GNU GENERAL PUBLIC LICENSE 60 | TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION 61 | 62 | 0. This License applies to any program or other work which contains 63 | a notice placed by the copyright holder saying it may be distributed 64 | under the terms of this General Public License. The "Program", below, 65 | refers to any such program or work, and a "work based on the Program" 66 | means either the Program or any derivative work under copyright law: 67 | that is to say, a work containing the Program or a portion of it, 68 | either verbatim or with modifications and/or translated into another 69 | language. (Hereinafter, translation is included without limitation in 70 | the term "modification".) Each licensee is addressed as "you". 71 | 72 | Activities other than copying, distribution and modification are not 73 | covered by this License; they are outside its scope. The act of 74 | running the Program is not restricted, and the output from the Program 75 | is covered only if its contents constitute a work based on the 76 | Program (independent of having been made by running the Program). 77 | Whether that is true depends on what the Program does. 78 | 79 | 1. You may copy and distribute verbatim copies of the Program's 80 | source code as you receive it, in any medium, provided that you 81 | conspicuously and appropriately publish on each copy an appropriate 82 | copyright notice and disclaimer of warranty; keep intact all the 83 | notices that refer to this License and to the absence of any warranty; 84 | and give any other recipients of the Program a copy of this License 85 | along with the Program. 86 | 87 | You may charge a fee for the physical act of transferring a copy, and 88 | you may at your option offer warranty protection in exchange for a fee. 89 | 90 | 2. You may modify your copy or copies of the Program or any portion 91 | of it, thus forming a work based on the Program, and copy and 92 | distribute such modifications or work under the terms of Section 1 93 | above, provided that you also meet all of these conditions: 94 | 95 | a) You must cause the modified files to carry prominent notices 96 | stating that you changed the files and the date of any change. 97 | 98 | b) You must cause any work that you distribute or publish, that in 99 | whole or in part contains or is derived from the Program or any 100 | part thereof, to be licensed as a whole at no charge to all third 101 | parties under the terms of this License. 102 | 103 | c) If the modified program normally reads commands interactively 104 | when run, you must cause it, when started running for such 105 | interactive use in the most ordinary way, to print or display an 106 | announcement including an appropriate copyright notice and a 107 | notice that there is no warranty (or else, saying that you provide 108 | a warranty) and that users may redistribute the program under 109 | these conditions, and telling the user how to view a copy of this 110 | License. (Exception: if the Program itself is interactive but 111 | does not normally print such an announcement, your work based on 112 | the Program is not required to print an announcement.) 113 | 114 | These requirements apply to the modified work as a whole. If 115 | identifiable sections of that work are not derived from the Program, 116 | and can be reasonably considered independent and separate works in 117 | themselves, then this License, and its terms, do not apply to those 118 | sections when you distribute them as separate works. But when you 119 | distribute the same sections as part of a whole which is a work based 120 | on the Program, the distribution of the whole must be on the terms of 121 | this License, whose permissions for other licensees extend to the 122 | entire whole, and thus to each and every part regardless of who wrote it. 123 | 124 | Thus, it is not the intent of this section to claim rights or contest 125 | your rights to work written entirely by you; rather, the intent is to 126 | exercise the right to control the distribution of derivative or 127 | collective works based on the Program. 128 | 129 | In addition, mere aggregation of another work not based on the Program 130 | with the Program (or with a work based on the Program) on a volume of 131 | a storage or distribution medium does not bring the other work under 132 | the scope of this License. 133 | 134 | 3. You may copy and distribute the Program (or a work based on it, 135 | under Section 2) in object code or executable form under the terms of 136 | Sections 1 and 2 above provided that you also do one of the following: 137 | 138 | a) Accompany it with the complete corresponding machine-readable 139 | source code, which must be distributed under the terms of Sections 140 | 1 and 2 above on a medium customarily used for software interchange; or, 141 | 142 | b) Accompany it with a written offer, valid for at least three 143 | years, to give any third party, for a charge no more than your 144 | cost of physically performing source distribution, a complete 145 | machine-readable copy of the corresponding source code, to be 146 | distributed under the terms of Sections 1 and 2 above on a medium 147 | customarily used for software interchange; or, 148 | 149 | c) Accompany it with the information you received as to the offer 150 | to distribute corresponding source code. (This alternative is 151 | allowed only for noncommercial distribution and only if you 152 | received the program in object code or executable form with such 153 | an offer, in accord with Subsection b above.) 154 | 155 | The source code for a work means the preferred form of the work for 156 | making modifications to it. For an executable work, complete source 157 | code means all the source code for all modules it contains, plus any 158 | associated interface definition files, plus the scripts used to 159 | control compilation and installation of the executable. However, as a 160 | special exception, the source code distributed need not include 161 | anything that is normally distributed (in either source or binary 162 | form) with the major components (compiler, kernel, and so on) of the 163 | operating system on which the executable runs, unless that component 164 | itself accompanies the executable. 165 | 166 | If distribution of executable or object code is made by offering 167 | access to copy from a designated place, then offering equivalent 168 | access to copy the source code from the same place counts as 169 | distribution of the source code, even though third parties are not 170 | compelled to copy the source along with the object code. 171 | 172 | 4. You may not copy, modify, sublicense, or distribute the Program 173 | except as expressly provided under this License. Any attempt 174 | otherwise to copy, modify, sublicense or distribute the Program is 175 | void, and will automatically terminate your rights under this License. 176 | However, parties who have received copies, or rights, from you under 177 | this License will not have their licenses terminated so long as such 178 | parties remain in full compliance. 179 | 180 | 5. You are not required to accept this License, since you have not 181 | signed it. However, nothing else grants you permission to modify or 182 | distribute the Program or its derivative works. These actions are 183 | prohibited by law if you do not accept this License. Therefore, by 184 | modifying or distributing the Program (or any work based on the 185 | Program), you indicate your acceptance of this License to do so, and 186 | all its terms and conditions for copying, distributing or modifying 187 | the Program or works based on it. 188 | 189 | 6. Each time you redistribute the Program (or any work based on the 190 | Program), the recipient automatically receives a license from the 191 | original licensor to copy, distribute or modify the Program subject to 192 | these terms and conditions. You may not impose any further 193 | restrictions on the recipients' exercise of the rights granted herein. 194 | You are not responsible for enforcing compliance by third parties to 195 | this License. 196 | 197 | 7. If, as a consequence of a court judgment or allegation of patent 198 | infringement or for any other reason (not limited to patent issues), 199 | conditions are imposed on you (whether by court order, agreement or 200 | otherwise) that contradict the conditions of this License, they do not 201 | excuse you from the conditions of this License. If you cannot 202 | distribute so as to satisfy simultaneously your obligations under this 203 | License and any other pertinent obligations, then as a consequence you 204 | may not distribute the Program at all. For example, if a patent 205 | license would not permit royalty-free redistribution of the Program by 206 | all those who receive copies directly or indirectly through you, then 207 | the only way you could satisfy both it and this License would be to 208 | refrain entirely from distribution of the Program. 209 | 210 | If any portion of this section is held invalid or unenforceable under 211 | any particular circumstance, the balance of the section is intended to 212 | apply and the section as a whole is intended to apply in other 213 | circumstances. 214 | 215 | It is not the purpose of this section to induce you to infringe any 216 | patents or other property right claims or to contest validity of any 217 | such claims; this section has the sole purpose of protecting the 218 | integrity of the free software distribution system, which is 219 | implemented by public license practices. Many people have made 220 | generous contributions to the wide range of software distributed 221 | through that system in reliance on consistent application of that 222 | system; it is up to the author/donor to decide if he or she is willing 223 | to distribute software through any other system and a licensee cannot 224 | impose that choice. 225 | 226 | This section is intended to make thoroughly clear what is believed to 227 | be a consequence of the rest of this License. 228 | 229 | 8. If the distribution and/or use of the Program is restricted in 230 | certain countries either by patents or by copyrighted interfaces, the 231 | original copyright holder who places the Program under this License 232 | may add an explicit geographical distribution limitation excluding 233 | those countries, so that distribution is permitted only in or among 234 | countries not thus excluded. In such case, this License incorporates 235 | the limitation as if written in the body of this License. 236 | 237 | 9. The Free Software Foundation may publish revised and/or new versions 238 | of the General Public License from time to time. Such new versions will 239 | be similar in spirit to the present version, but may differ in detail to 240 | address new problems or concerns. 241 | 242 | Each version is given a distinguishing version number. If the Program 243 | specifies a version number of this License which applies to it and "any 244 | later version", you have the option of following the terms and conditions 245 | either of that version or of any later version published by the Free 246 | Software Foundation. If the Program does not specify a version number of 247 | this License, you may choose any version ever published by the Free Software 248 | Foundation. 249 | 250 | 10. If you wish to incorporate parts of the Program into other free 251 | programs whose distribution conditions are different, write to the author 252 | to ask for permission. For software which is copyrighted by the Free 253 | Software Foundation, write to the Free Software Foundation; we sometimes 254 | make exceptions for this. Our decision will be guided by the two goals 255 | of preserving the free status of all derivatives of our free software and 256 | of promoting the sharing and reuse of software generally. 257 | 258 | NO WARRANTY 259 | 260 | 11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY 261 | FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN 262 | OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES 263 | PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED 264 | OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 265 | MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS 266 | TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE 267 | PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, 268 | REPAIR OR CORRECTION. 269 | 270 | 12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING 271 | WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR 272 | REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, 273 | INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING 274 | OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED 275 | TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY 276 | YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER 277 | PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE 278 | POSSIBILITY OF SUCH DAMAGES. 279 | 280 | END OF TERMS AND CONDITIONS 281 | 282 | How to Apply These Terms to Your New Programs 283 | 284 | If you develop a new program, and you want it to be of the greatest 285 | possible use to the public, the best way to achieve this is to make it 286 | free software which everyone can redistribute and change under these terms. 287 | 288 | To do so, attach the following notices to the program. It is safest 289 | to attach them to the start of each source file to most effectively 290 | convey the exclusion of warranty; and each file should have at least 291 | the "copyright" line and a pointer to where the full notice is found. 292 | 293 | 294 | Copyright (C) 295 | 296 | This program is free software; you can redistribute it and/or modify 297 | it under the terms of the GNU General Public License as published by 298 | the Free Software Foundation; either version 2 of the License, or 299 | (at your option) any later version. 300 | 301 | This program is distributed in the hope that it will be useful, 302 | but WITHOUT ANY WARRANTY; without even the implied warranty of 303 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 304 | GNU General Public License for more details. 305 | 306 | You should have received a copy of the GNU General Public License along 307 | with this program; if not, write to the Free Software Foundation, Inc., 308 | 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. 309 | 310 | Also add information on how to contact you by electronic and paper mail. 311 | 312 | If the program is interactive, make it output a short notice like this 313 | when it starts in an interactive mode: 314 | 315 | Gnomovision version 69, Copyright (C) year name of author 316 | Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'. 317 | This is free software, and you are welcome to redistribute it 318 | under certain conditions; type `show c' for details. 319 | 320 | The hypothetical commands `show w' and `show c' should show the appropriate 321 | parts of the General Public License. Of course, the commands you use may 322 | be called something other than `show w' and `show c'; they could even be 323 | mouse-clicks or menu items--whatever suits your program. 324 | 325 | You should also get your employer (if you work as a programmer) or your 326 | school, if any, to sign a "copyright disclaimer" for the program, if 327 | necessary. Here is a sample; alter the names: 328 | 329 | Yoyodyne, Inc., hereby disclaims all copyright interest in the program 330 | `Gnomovision' (which makes passes at compilers) written by James Hacker. 331 | 332 | , 1 April 1989 333 | Ty Coon, President of Vice 334 | 335 | This General Public License does not permit incorporating your program into 336 | proprietary programs. If your program is a subroutine library, you may 337 | consider it more useful to permit linking proprietary applications with the 338 | library. If this is what you want to do, use the GNU Lesser General 339 | Public License instead of this License. 340 | -------------------------------------------------------------------------------- /Makefile: -------------------------------------------------------------------------------- 1 | CC = gcc -I/usr/include/libusb-1.0 2 | GXX = g++ 3 | CXXFLAGS = -pipe -O2 -Wall -W -D_REENTRANT -lusb-1.0 -lm 4 | INCPATH = -I. -I/usr/include/libusb-1.0 5 | 6 | all: flirone.o flirone 7 | 8 | flirone.o: src/flirone.c src/plank.h 9 | 10 | flirone: src/flirone.o 11 | ${CC} -o flirone src/flirone.o -lusb-1.0 -lm -Wall 12 | 13 | clean: 14 | rm -f flirone.o flirone 15 | 16 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | ### Flir One for Linux v4l2 2 | 3 | This is a cleaned up version of code posted here: 4 | http://www.eevblog.com/forum/thermal-imaging/question-about-flir-one-for-android/ 5 | 6 | All credit goes to tomas123, cynfab etc from that forum who did the awesome research and work to make this support. -------------------------------------------------------------------------------- /palettes/15.raw: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/fnoop/flirone-v4l2/b07e3a1d065befbb92aafcb2981638a22934bb13/palettes/15.raw -------------------------------------------------------------------------------- /palettes/17.raw: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/fnoop/flirone-v4l2/b07e3a1d065befbb92aafcb2981638a22934bb13/palettes/17.raw -------------------------------------------------------------------------------- /palettes/7.raw: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/fnoop/flirone-v4l2/b07e3a1d065befbb92aafcb2981638a22934bb13/palettes/7.raw -------------------------------------------------------------------------------- /palettes/85.raw: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/fnoop/flirone-v4l2/b07e3a1d065befbb92aafcb2981638a22934bb13/palettes/85.raw -------------------------------------------------------------------------------- /palettes/92.raw: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/fnoop/flirone-v4l2/b07e3a1d065befbb92aafcb2981638a22934bb13/palettes/92.raw -------------------------------------------------------------------------------- /palettes/Grayscale.raw: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/fnoop/flirone-v4l2/b07e3a1d065befbb92aafcb2981638a22934bb13/palettes/Grayscale.raw -------------------------------------------------------------------------------- /palettes/Grey.raw: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/fnoop/flirone-v4l2/b07e3a1d065befbb92aafcb2981638a22934bb13/palettes/Grey.raw -------------------------------------------------------------------------------- /palettes/Iron2.raw: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/fnoop/flirone-v4l2/b07e3a1d065befbb92aafcb2981638a22934bb13/palettes/Iron2.raw -------------------------------------------------------------------------------- /palettes/Iron_Black.raw: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/fnoop/flirone-v4l2/b07e3a1d065befbb92aafcb2981638a22934bb13/palettes/Iron_Black.raw -------------------------------------------------------------------------------- /palettes/Rainbow.raw: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/fnoop/flirone-v4l2/b07e3a1d065befbb92aafcb2981638a22934bb13/palettes/Rainbow.raw -------------------------------------------------------------------------------- /scripts/gstreamer_rgbcamera: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | gst-launch-1.0 \ 4 | v4l2src device=/dev/video2 \ 5 | ! videoconvert \ 6 | ! videoscale \ 7 | ! video/x-raw,format=mjpg, width=640, height=480, framerate=8/1 \ 8 | ! autovideosink 9 | -------------------------------------------------------------------------------- /scripts/gstreamer_testmosaic: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | gst-launch-1.0 \ 4 | videotestsrc pattern=0 ! queue2 ! c.sink_0 \ 5 | v4l2src device=/dev/video3 do-timestamp=true ! c.sink_1 \ 6 | videotestsrc pattern=0 ! queue2 ! c.sink_2 \ 7 | videotestsrc pattern=1 ! queue2 ! c.sink_3 \ 8 | videotestsrc pattern=18 ! queue2 ! c.sink_4 \ 9 | compositor name=c background-color=0x223344 \ 10 | sink_0::xpos=0 sink_0::ypos=0 sink_0::width=400 sink_0::height=300 sink_0::fill_color=0x00000000 \ 11 | sink_1::xpos=400 sink_1::ypos=0 sink_1::width=400 sink_1::height=300 sink_1::fill_color=0x11111111 \ 12 | sink_2::xpos=0 sink_2::ypos=300 sink_2::width=400 sink_2::height=300 sink_2::fill_color=0x22222222 \ 13 | sink_3::xpos=400 sink_3::ypos=300 sink_3::width=400 sink_3::height=300 sink_3::fill_color=0x33333333 \ 14 | sink_4::xpos=200 sink_4::ypos=150 sink_4::width=400 sink_4::height=300 sink_4::fill_color=0x44444444 sink_4::alpha=0.5 ! \ 15 | queue2 ! video/x-raw, width=800, height=600 ! ximagesink 16 | -------------------------------------------------------------------------------- /scripts/load_v4l2loopback: -------------------------------------------------------------------------------- 1 | sudo modprobe v4l2loopback exclusive_caps=0,0 video_nr=1,2,3 -------------------------------------------------------------------------------- /src/flirone.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2015-2016 Thomas 3 | * 4 | * This program is free software; you can redistribute it and/or modify 5 | * it under the terms of the GNU General Public License as published by 6 | * the Free Software Foundation; either version 2 of the License, or 7 | * (at your option) any later version. 8 | * 9 | * This program is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | * GNU General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU General Public License 15 | * along with this program; if not, write to the Free Software 16 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 17 | */ 18 | 19 | #include 20 | #include 21 | #include 22 | #include 23 | #include 24 | #include 25 | #include 26 | 27 | #include 28 | #include 29 | 30 | #include "jpeglib.h" 31 | 32 | #include "plank.h" 33 | 34 | // -- define v4l2 --------------- 35 | #include 36 | #include 37 | #include 38 | #include 39 | #include 40 | 41 | #define VIDEO_DEVICE0 "/dev/video1" // gray scale thermal image 42 | #define FRAME_WIDTH0 160 43 | #define FRAME_HEIGHT0 120 44 | 45 | #define VIDEO_DEVICE1 "/dev/video2" // color visible image 46 | #define FRAME_WIDTH1 640 47 | #define FRAME_HEIGHT1 480 48 | 49 | #define VIDEO_DEVICE2 "/dev/video3" // colorized thermal image 50 | #define FRAME_WIDTH2 160 51 | #define FRAME_HEIGHT2 128 52 | 53 | #define FRAME_FORMAT0 V4L2_PIX_FMT_GREY 54 | #define FRAME_FORMAT1 V4L2_PIX_FMT_MJPEG 55 | #define FRAME_FORMAT2 V4L2_PIX_FMT_RGB24 56 | 57 | struct v4l2_capability vid_caps0; 58 | struct v4l2_capability vid_caps1; 59 | struct v4l2_capability vid_caps2; 60 | 61 | struct v4l2_format vid_format0; 62 | struct v4l2_format vid_format1; 63 | struct v4l2_format vid_format2; 64 | 65 | size_t framesize0; 66 | size_t linewidth0; 67 | 68 | size_t framesize1; 69 | size_t linewidth1; 70 | 71 | size_t framesize2; 72 | size_t linewidth2; 73 | 74 | 75 | const char *video_device0=VIDEO_DEVICE0; 76 | const char *video_device1=VIDEO_DEVICE1; 77 | const char *video_device2=VIDEO_DEVICE2; 78 | 79 | int fdwr0 = 0; 80 | int fdwr1 = 0; 81 | int fdwr2 = 0; 82 | 83 | // -- end define v4l2 --------------- 84 | 85 | #define VENDOR_ID 0x09cb 86 | #define PRODUCT_ID 0x1996 87 | 88 | static struct libusb_device_handle *devh = NULL; 89 | int filecount=0; 90 | struct timeval t1, t2; 91 | long long fps_t; 92 | 93 | int FFC = 0; // detect FFC 94 | 95 | // -- buffer for EP 0x85 chunks --------------- 96 | #define BUF85SIZE 1048576 // size got from android app 97 | int buf85pointer = 0; 98 | unsigned char buf85[BUF85SIZE]; 99 | 100 | void print_format(struct v4l2_format*vid_format) { 101 | printf(" vid_format->type =%d\n", vid_format->type ); 102 | printf(" vid_format->fmt.pix.width =%d\n", vid_format->fmt.pix.width ); 103 | printf(" vid_format->fmt.pix.height =%d\n", vid_format->fmt.pix.height ); 104 | printf(" vid_format->fmt.pix.pixelformat =%d\n", vid_format->fmt.pix.pixelformat); 105 | printf(" vid_format->fmt.pix.sizeimage =%u\n", vid_format->fmt.pix.sizeimage ); 106 | printf(" vid_format->fmt.pix.field =%d\n", vid_format->fmt.pix.field ); 107 | printf(" vid_format->fmt.pix.bytesperline=%d\n", vid_format->fmt.pix.bytesperline ); 108 | printf(" vid_format->fmt.pix.colorspace =%d\n", vid_format->fmt.pix.colorspace ); 109 | } 110 | 111 | //#include "font.h" 112 | #include "font5x7.h" 113 | void font_write(unsigned char *fb, int x, int y, const char *string) 114 | { 115 | int rx, ry; 116 | while (*string) { 117 | for (ry = 0; ry < 5; ++ry) { 118 | for (rx = 0; rx < 7; ++rx) { 119 | int v = (font5x7_basic[((*string) & 0x7F) - CHAR_OFFSET][ry] >> (rx)) & 1; 120 | // fb[(y+ry) * 160 + (x + rx)] = v ? 0 : 0xFF; // black / white 121 | // fb[(y+rx) * 160 + (x + ry)] = v ? 0 : 0xFF; // black / white 122 | 123 | fb[(y+rx) * 160 + (x + ry)] = v ? 0 : fb[(y+rx) * 160 + (x + ry)]; // transparent 124 | } 125 | } 126 | string++; 127 | x += 6; 128 | } 129 | } 130 | 131 | double raw2temperature(unsigned short RAW) 132 | { 133 | // mystery correction factor 134 | RAW *=4; 135 | // calc amount of radiance of reflected objects ( Emissivity < 1 ) 136 | double RAWrefl=PlanckR1/(PlanckR2*(exp(PlanckB/(TempReflected+273.15))-PlanckF))-PlanckO; 137 | // get displayed object temp max/min 138 | double RAWobj=(RAW-(1-Emissivity)*RAWrefl)/Emissivity; 139 | // calc object temperature 140 | return PlanckB/log(PlanckR1/(PlanckR2*(RAWobj+PlanckO))+PlanckF)-273.15; 141 | } 142 | 143 | 144 | void startv4l2() 145 | { 146 | int ret_code = 0; 147 | 148 | int i; 149 | int k=1; 150 | /* 151 | //open video_device0 152 | printf("using output device: %s\n", video_device0); 153 | 154 | fdwr0 = open(video_device0, O_RDWR); 155 | assert(fdwr0 >= 0); 156 | 157 | ret_code = ioctl(fdwr0, VIDIOC_QUERYCAP, &vid_caps0); 158 | assert(ret_code != -1); 159 | 160 | memset(&vid_format0, 0, sizeof(vid_format0)); 161 | 162 | ret_code = ioctl(fdwr0, VIDIOC_G_FMT, &vid_format0); 163 | 164 | linewidth0=FRAME_WIDTH0; 165 | framesize0=FRAME_WIDTH0*FRAME_HEIGHT0*1; // 8 Bit 166 | 167 | vid_format0.type = V4L2_BUF_TYPE_VIDEO_OUTPUT; 168 | vid_format0.fmt.pix.width = FRAME_WIDTH0; 169 | vid_format0.fmt.pix.height = FRAME_HEIGHT0; 170 | vid_format0.fmt.pix.pixelformat = FRAME_FORMAT0; 171 | vid_format0.fmt.pix.sizeimage = framesize0; 172 | vid_format0.fmt.pix.field = V4L2_FIELD_NONE; 173 | vid_format0.fmt.pix.bytesperline = linewidth0; 174 | vid_format0.fmt.pix.colorspace = V4L2_COLORSPACE_SRGB; 175 | 176 | // set data format 177 | ret_code = ioctl(fdwr0, VIDIOC_S_FMT, &vid_format0); 178 | assert(ret_code != -1); 179 | 180 | print_format(&vid_format0); 181 | */ 182 | //open video_device1 183 | printf("using output device: %s\n", video_device1); 184 | 185 | fdwr1 = open(video_device1, O_RDWR); 186 | assert(fdwr1 >= 0); 187 | 188 | ret_code = ioctl(fdwr1, VIDIOC_QUERYCAP, &vid_caps1); 189 | assert(ret_code != -1); 190 | 191 | memset(&vid_format1, 0, sizeof(vid_format1)); 192 | 193 | ret_code = ioctl(fdwr1, VIDIOC_G_FMT, &vid_format1); 194 | 195 | linewidth1=FRAME_WIDTH1; 196 | framesize1=FRAME_WIDTH1*FRAME_HEIGHT1*1; // 8 Bit ?? 197 | 198 | vid_format1.type = V4L2_BUF_TYPE_VIDEO_OUTPUT; 199 | vid_format1.fmt.pix.width = FRAME_WIDTH1; 200 | vid_format1.fmt.pix.height = FRAME_HEIGHT1; 201 | vid_format1.fmt.pix.pixelformat = FRAME_FORMAT1; 202 | vid_format1.fmt.pix.sizeimage = framesize1; 203 | vid_format1.fmt.pix.field = V4L2_FIELD_NONE; 204 | vid_format1.fmt.pix.bytesperline = linewidth1; 205 | vid_format1.fmt.pix.colorspace = V4L2_COLORSPACE_SRGB; 206 | 207 | // set data format 208 | ret_code = ioctl(fdwr1, VIDIOC_S_FMT, &vid_format1); 209 | assert(ret_code != -1); 210 | 211 | print_format(&vid_format1); 212 | 213 | 214 | //open video_device2 215 | printf("using output device: %s\n", video_device2); 216 | 217 | fdwr2 = open(video_device2, O_RDWR); 218 | assert(fdwr2 >= 0); 219 | 220 | ret_code = ioctl(fdwr2, VIDIOC_QUERYCAP, &vid_caps2); 221 | assert(ret_code != -1); 222 | 223 | memset(&vid_format2, 0, sizeof(vid_format2)); 224 | 225 | ret_code = ioctl(fdwr2, VIDIOC_G_FMT, &vid_format2); 226 | 227 | linewidth2=FRAME_WIDTH2; 228 | framesize2=FRAME_WIDTH2*FRAME_HEIGHT2*3; // 8x8x8 Bit 229 | 230 | vid_format2.type = V4L2_BUF_TYPE_VIDEO_OUTPUT; 231 | vid_format2.fmt.pix.width = FRAME_WIDTH2; 232 | vid_format2.fmt.pix.height = FRAME_HEIGHT2; 233 | vid_format2.fmt.pix.pixelformat = FRAME_FORMAT2; 234 | vid_format2.fmt.pix.sizeimage = framesize2; 235 | vid_format2.fmt.pix.field = V4L2_FIELD_NONE; 236 | vid_format2.fmt.pix.bytesperline = linewidth2; 237 | vid_format2.fmt.pix.colorspace = V4L2_COLORSPACE_SRGB; 238 | 239 | // set data format 240 | ret_code = ioctl(fdwr2, VIDIOC_S_FMT, &vid_format2); 241 | assert(ret_code != -1); 242 | 243 | print_format(&vid_format2); 244 | } 245 | 246 | 247 | // unused 248 | void closev4l2() 249 | { 250 | // close(fdwr0); 251 | close(fdwr1); 252 | close(fdwr2); 253 | 254 | } 255 | 256 | void vframe(char ep[],char EP_error[], int r, int actual_length, unsigned char buf[], unsigned char *colormap) 257 | { 258 | // error handler 259 | time_t now1; 260 | now1 = time(NULL); 261 | if (r < 0) { 262 | if (strcmp (EP_error, libusb_error_name(r))!=0) 263 | { 264 | strcpy(EP_error, libusb_error_name(r)); 265 | fprintf(stderr, "\n: %s >>>>>>>>>>>>>>>>>bulk transfer (in) %s:%i %s\n", ctime(&now1), ep , r, libusb_error_name(r)); 266 | sleep(1); 267 | } 268 | return; 269 | } 270 | 271 | // reset buffer if the new chunk begins with magic bytes or the buffer size limit is exceeded 272 | unsigned char magicbyte[4]={0xEF,0xBE,0x00,0x00}; 273 | 274 | if ((strncmp (buf, magicbyte,4)==0 ) || ((buf85pointer + actual_length) >= BUF85SIZE)) 275 | { 276 | //printf(">>>>>>>>>>>begin of new frame<<<<<<<<<<<<<\n"); 277 | buf85pointer=0; 278 | } 279 | 280 | //printf("actual_length %d !!!!!\n", actual_length); 281 | 282 | memmove(buf85+buf85pointer, buf, actual_length); 283 | buf85pointer=buf85pointer+actual_length; 284 | 285 | if ((strncmp (buf85, magicbyte,4)!=0 )) 286 | { 287 | //reset buff pointer 288 | buf85pointer=0; 289 | printf("Reset buffer because of bad Magic Byte!\n"); 290 | return; 291 | } 292 | 293 | // a quick and dirty job for gcc 294 | uint32_t FrameSize = buf85[ 8] + (buf85[ 9] << 8) + (buf85[10] << 16) + (buf85[11] << 24); 295 | uint32_t ThermalSize = buf85[12] + (buf85[13] << 8) + (buf85[14] << 16) + (buf85[15] << 24); 296 | uint32_t JpgSize = buf85[16] + (buf85[17] << 8) + (buf85[18] << 16) + (buf85[19] << 24); 297 | uint32_t StatusSize = buf85[20] + (buf85[21] << 8) + (buf85[22] << 16) + (buf85[23] << 24); 298 | 299 | //printf("FrameSize= %d (+28=%d), ThermalSize %d, JPG %d, StatusSize %d, Pointer %d\n",FrameSize,FrameSize+28, ThermalSize, JpgSize,StatusSize,buf85pointer); 300 | 301 | if ( (FrameSize+28) > (buf85pointer) ) 302 | { 303 | // wait for next chunk 304 | return; 305 | } 306 | 307 | int i,v; 308 | // get a full frame, first print the status 309 | t1=t2; 310 | gettimeofday(&t2, NULL); 311 | // fps as moving average over last 20 frames 312 | // fps_t = (19*fps_t+10000000/(((t2.tv_sec * 1000000) + t2.tv_usec) - ((t1.tv_sec * 1000000) + t1.tv_usec)))/20; 313 | 314 | filecount++; 315 | // printf("#%08i %lld/10 fps:",filecount,fps_t); 316 | // for (i = 0; i < StatusSize; i++) { 317 | // v=28+ThermalSize+JpgSize+i; 318 | // if(buf85[v]>31) {printf("%c", buf85[v]);} 319 | // } 320 | // printf("\n"); 321 | 322 | buf85pointer=0; 323 | 324 | unsigned short pix[160*120]; // original Flir 16 Bit RAW 325 | int x, y; 326 | unsigned char *fb_proc,*fb_proc2; 327 | 328 | fb_proc = malloc(160 * 128); // 8 Bit gray buffer really needs only 160 x 120 329 | memset(fb_proc, 128, 160*128); // sizeof(fb_proc) doesn't work, value depends from LUT 330 | 331 | fb_proc2 = malloc(160 * 128 * 3 ); // 8x8x8 Bit RGB buffer 332 | 333 | int min = 0x10000, max = 0; 334 | float rms = 0; 335 | 336 | // Make a unsigned short array from what comes from the thermal frame 337 | // find the max, min and RMS (not used yet) values of the array 338 | int maxx, maxy; 339 | for (y = 0; y < 120; ++y) 340 | { 341 | for (x = 0; x < 160; ++x) { 342 | if (x<80) 343 | v = buf85[2*(y * 164 + x) +32]+256*buf85[2*(y * 164 + x) +33]; 344 | else 345 | v = buf85[2*(y * 164 + x) +32+4]+256*buf85[2*(y * 164 + x) +33+4]; 346 | pix[y * 160 + x] = v; // unsigned char!! 347 | 348 | if (v < min) min = v; 349 | if (v > max) { max = v; maxx = x; maxy = y; } 350 | rms += v * v; 351 | } 352 | } 353 | 354 | // RMS used later 355 | // rms /= 160 * 120; 356 | // rms = sqrtf(rms); 357 | 358 | // scale the data in the array 359 | int delta = max - min; 360 | if (!delta) delta = 1; // if max = min we have divide by zero 361 | int scale = 0x10000 / delta; 362 | 363 | for (y = 0; y < 120; ++y) //120 364 | { 365 | for (x = 0; x < 160; ++x) { //160 366 | int v = (pix[y * 160 + x] - min) * scale >> 8; 367 | 368 | // fb_proc is the gray scale frame buffer 369 | fb_proc[y * 160 + x] = v; // unsigned char!! 370 | 371 | } 372 | } 373 | 374 | char st1[100]; 375 | char st2[100]; 376 | struct tm *loctime; 377 | // Convert it to local time and Print it out in a nice format. 378 | loctime = localtime (&now1); 379 | strftime (st1, 60, "%H:%M:%S", loctime); 380 | 381 | // calc medium of 2x2 center pixels 382 | int med = (pix[59 * 160 + 79]+pix[59 * 160 + 80]+pix[60 * 160 + 79]+pix[60 * 160 + 80])/4; 383 | sprintf(st2," %.1f/%.1f/%.1f'C", raw2temperature(min),raw2temperature(med),raw2temperature(max)); 384 | strcat(st1, st2); 385 | 386 | #define MAX 26 // max chars in line 160/6=26,6 387 | strncpy(st2, st1, MAX); 388 | // write zero to string !! 389 | st2[MAX-1] = '\0'; 390 | font_write(fb_proc, 1, 120, st2); 391 | 392 | // show crosshairs, remove if required 393 | font_write(fb_proc, 80-2, 60-3, "+"); 394 | 395 | maxx -= 4; 396 | maxy -= 4; 397 | 398 | if (maxx < 0) maxx = 0; 399 | if (maxy < 0) maxy = 0; 400 | if (maxx > 150) maxx = 150; 401 | if (maxy > 110) maxy = 110; 402 | 403 | font_write(fb_proc, 160-6, maxy, "<"); 404 | font_write(fb_proc, maxx, 120-8, "|"); 405 | 406 | for (y = 0; y < 128; ++y) 407 | { 408 | for (x = 0; x < 160; ++x) { 409 | 410 | // fb_proc is the gray scale frame buffer 411 | v=fb_proc[y * 160 + x] ; // unsigned char!! 412 | 413 | // fb_proc2 is an 24bit RGB buffer 414 | 415 | fb_proc2[3*y * 160 + x*3] = colormap[3 * v]; // unsigned char!! 416 | fb_proc2[(3*y * 160 + x*3)+1] = colormap[3 * v + 1]; // unsigned char!! 417 | fb_proc2[(3*y * 160 + x*3)+2] = colormap[3 * v + 2]; // unsigned char!! 418 | } 419 | } 420 | 421 | 422 | 423 | // write video to v4l2loopback(s) 424 | // write(fdwr0, fb_proc, framesize0); // gray scale Thermal Image 425 | write(fdwr1, &buf85[28+ThermalSize], JpgSize); // jpg Visual Image 426 | 427 | if (strncmp (&buf85[28+ThermalSize+JpgSize+17],"FFC",3)==0) 428 | { 429 | FFC=1; // drop all FFC frames 430 | } else 431 | { 432 | if (FFC==1) 433 | { 434 | FFC=0; // drop first frame after FFC 435 | } 436 | else 437 | { 438 | write(fdwr2, fb_proc2, framesize2); // colorized RGB Thermal Image 439 | } 440 | } 441 | 442 | 443 | 444 | // free memory 445 | free(fb_proc); // thermal RAW 446 | free(fb_proc2); // visible jpg 447 | 448 | } 449 | 450 | static int find_lvr_flirusb(void) 451 | { 452 | devh = libusb_open_device_with_vid_pid(NULL, VENDOR_ID, PRODUCT_ID); 453 | return devh ? 0 : -EIO; 454 | } 455 | 456 | void print_bulk_result(char ep[],char EP_error[], int r, int actual_length, unsigned char buf[]) 457 | { 458 | time_t now1; 459 | int i; 460 | 461 | now1 = time(NULL); 462 | if (r < 0) { 463 | if (strcmp (EP_error, libusb_error_name(r))!=0) 464 | { 465 | strcpy(EP_error, libusb_error_name(r)); 466 | fprintf(stderr, "\n: %s >>>>>>>>>>>>>>>>>bulk transfer (in) %s:%i %s\n", ctime(&now1), ep , r, libusb_error_name(r)); 467 | sleep(1); 468 | } 469 | //return 1; 470 | } else 471 | { 472 | printf("\n: %s bulk read EP %s, actual length %d\nHEX:\n",ctime(&now1), ep ,actual_length); 473 | // write frame to file 474 | /* 475 | char filename[100]; 476 | sprintf(filename, "EP%s#%05i.bin",ep,filecount); 477 | filecount++; 478 | FILE *file = fopen(filename, "wb"); 479 | fwrite(buf, 1, actual_length, file); 480 | fclose(file); 481 | */ 482 | // hex print of first byte 483 | for (i = 0; i < (((200)<(actual_length))?(200):(actual_length)); i++) { 484 | printf(" %02x", buf[i]); 485 | } 486 | 487 | printf("\nSTRING:\n"); 488 | for (i = 0; i < (((200)<(actual_length))?(200):(actual_length)); i++) { 489 | if(buf[i]>31) {printf("%c", buf[i]);} 490 | } 491 | printf("\n"); 492 | 493 | } 494 | } 495 | 496 | int EPloop(unsigned char *colormap) 497 | { 498 | int i,r = 1; 499 | r = libusb_init(NULL); 500 | if (r < 0) { 501 | fprintf(stderr, "failed to initialise libusb\n"); 502 | exit(1); 503 | } 504 | 505 | r = find_lvr_flirusb(); 506 | if (r < 0) { 507 | fprintf(stderr, "Could not find/open device\n"); 508 | goto out; 509 | } 510 | printf("Successfully find the Flir One G2 device\n"); 511 | 512 | 513 | r = libusb_set_configuration(devh, 3); 514 | if (r < 0) { 515 | fprintf(stderr, "libusb_set_configuration error %d\n", r); 516 | goto out; 517 | } 518 | printf("Successfully set usb configuration 3\n"); 519 | 520 | 521 | // Claiming of interfaces is a purely logical operation; 522 | // it does not cause any requests to be sent over the bus. 523 | r = libusb_claim_interface(devh, 0); 524 | if (r <0) { 525 | fprintf(stderr, "libusb_claim_interface 0 error %d\n", r); 526 | goto out; 527 | } 528 | r = libusb_claim_interface(devh, 1); 529 | if (r < 0) { 530 | fprintf(stderr, "libusb_claim_interface 1 error %d\n", r); 531 | goto out; 532 | } 533 | r = libusb_claim_interface(devh, 2); 534 | if (r < 0) { 535 | fprintf(stderr, "libusb_claim_interface 2 error %d\n", r); 536 | goto out; 537 | } 538 | printf("Successfully claimed interface 0,1,2\n"); 539 | 540 | 541 | unsigned char buf[1048576]; 542 | int actual_length; 543 | 544 | time_t now; 545 | // save last error status to avoid clutter the log 546 | char EP81_error[50]="", EP83_error[50]="",EP85_error[50]=""; 547 | unsigned char data[2]={0,0}; // only a bad dummy 548 | 549 | // don't forget: $ sudo modprobe v4l2loopback video_nr=0,1 550 | startv4l2(); 551 | 552 | int state = 1; 553 | int ct=0; 554 | 555 | while (1) 556 | { 557 | 558 | switch(state) { 559 | 560 | case 1: 561 | /* Flir config 562 | 01 0b 01 00 01 00 00 00 c4 d5 563 | 0 bmRequestType = 01 564 | 1 bRequest = 0b 565 | 2 wValue 0001 type (H) index (L) stop=0/start=1 (Alternate Setting) 566 | 4 wIndex 01 interface 1/2 567 | 5 wLength 00 568 | 6 Data 00 00 569 | 570 | libusb_control_transfer (*dev_handle, bmRequestType, bRequest, wValue, wIndex, *data, wLength, timeout) 571 | */ 572 | 573 | printf("stop interface 2 FRAME\n"); 574 | r = libusb_control_transfer(devh,1,0x0b,0,2,data,0,100); 575 | if (r < 0) { 576 | fprintf(stderr, "Control Out error %d\n", r); 577 | return r; 578 | } 579 | 580 | printf("stop interface 1 FILEIO\n"); 581 | r = libusb_control_transfer(devh,1,0x0b,0,1,data,0,100); 582 | if (r < 0) { 583 | fprintf(stderr, "Control Out error %d\n", r); 584 | return r; 585 | } 586 | 587 | printf("\nstart interface 1 FILEIO\n"); 588 | r = libusb_control_transfer(devh,1,0x0b,1,1,data,0,100); 589 | if (r < 0) { 590 | fprintf(stderr, "Control Out error %d\n", r); 591 | return r; 592 | } 593 | now = time(0); // Get the system time 594 | printf("\n:xx %s",ctime(&now)); 595 | state = 3; // jump over wait stait 2. Not really using any data from CameraFiles.zip 596 | break; 597 | 598 | 599 | case 2: 600 | printf("\nask for CameraFiles.zip on EP 0x83:\n"); 601 | now = time(0); // Get the system time 602 | printf("\n: %s",ctime(&now)); 603 | 604 | int transferred = 0; 605 | char my_string[128]; 606 | 607 | //--------- write string: {"type":"openFile","data":{"mode":"r","path":"CameraFiles.zip"}} 608 | int length = 16; 609 | unsigned char my_string2[16]={0xcc,0x01,0x00,0x00,0x01,0x00,0x00,0x00,0x41,0x00,0x00,0x00,0xF8,0xB3,0xF7,0x00}; 610 | printf("\nEP 0x02 to be sent Hexcode: %i Bytes[",length); 611 | int i; 612 | for (i = 0; i < length; i++) { 613 | printf(" %02x", my_string2[i]); 614 | 615 | } 616 | printf(" ]\n"); 617 | 618 | r = libusb_bulk_transfer(devh, 2, my_string2, length, &transferred, 0); 619 | if(r == 0 && transferred == length) 620 | { 621 | printf("\nWrite successful!"); 622 | } 623 | else 624 | printf("\nError in write! res = %d and transferred = %d\n", r, transferred); 625 | 626 | strcpy( my_string,"{\"type\":\"openFile\",\"data\":{\"mode\":\"r\",\"path\":\"CameraFiles.zip\"}}"); 627 | 628 | length = strlen(my_string)+1; 629 | printf("\nEP 0x02 to be sent: %s", my_string); 630 | 631 | // avoid error: invalid conversion from ‘char*’ to ‘unsigned char*’ [-fpermissive] 632 | unsigned char *my_string1 = (unsigned char*)my_string; 633 | //my_string1 = (unsigned char*)my_string; 634 | 635 | r = libusb_bulk_transfer(devh, 2, my_string1, length, &transferred, 0); 636 | if(r == 0 && transferred == length) 637 | { 638 | printf("\nWrite successful!"); 639 | printf("\nSent %d bytes with string: %s\n", transferred, my_string); 640 | } 641 | else 642 | printf("\nError in write! res = %d and transferred = %d\n", r, transferred); 643 | 644 | //--------- write string: {"type":"readFile","data":{"streamIdentifier":10}} 645 | length = 16; 646 | unsigned char my_string3[16]={0xcc,0x01,0x00,0x00,0x01,0x00,0x00,0x00,0x33,0x00,0x00,0x00,0xef,0xdb,0xc1,0xc1}; 647 | printf("\nEP 0x02 to be sent Hexcode: %i Bytes[",length); 648 | for (i = 0; i < length; i++) { 649 | printf(" %02x", my_string3[i]); 650 | 651 | } 652 | printf(" ]\n"); 653 | 654 | r = libusb_bulk_transfer(devh, 2, my_string3, length, &transferred, 0); 655 | if(r == 0 && transferred == length) 656 | { 657 | printf("\nWrite successful!"); 658 | } 659 | else 660 | printf("\nError in write! res = %d and transferred = %d\n", r, transferred); 661 | 662 | 663 | //strcpy( my_string, "{\"type\":\"setOption\",\"data\":{\"option\":\"autoFFC\",\"value\":true}}"); 664 | strcpy( my_string,"{\"type\":\"readFile\",\"data\":{\"streamIdentifier\":10}}"); 665 | length = strlen(my_string)+1; 666 | printf("\nEP 0x02 to be sent %i Bytes: %s", length, my_string); 667 | 668 | // avoid error: invalid conversion from ‘char*’ to ‘unsigned char*’ [-fpermissive] 669 | my_string1 = (unsigned char*)my_string; 670 | 671 | r = libusb_bulk_transfer(devh, 2, my_string1, length, &transferred, 0); 672 | if(r == 0 && transferred == length) 673 | { 674 | printf("\nWrite successful!"); 675 | printf("\nSent %d bytes with string: %s\n", transferred, my_string); 676 | } 677 | else 678 | printf("\nError in write! res = %d and transferred = %d\n", r, transferred); 679 | 680 | 681 | // go to next state 682 | now = time(0); // Get the system time 683 | printf("\n: %s",ctime(&now)); 684 | //sleep(1); 685 | state = 3; 686 | break; 687 | 688 | 689 | case 3: 690 | printf("\nAsk for video stream, start EP 0x85:\n"); 691 | 692 | r = libusb_control_transfer(devh,1,0x0b,1,2,data, 2,200); 693 | if (r < 0) { 694 | fprintf(stderr, "Control Out error %d\n", r); 695 | return r; 696 | }; 697 | 698 | state = 4; 699 | break; 700 | 701 | case 4: 702 | // endless loop 703 | // poll Frame Endpoints 0x85 704 | // don't change timeout=100ms !! 705 | r = libusb_bulk_transfer(devh, 0x85, buf, sizeof(buf), &actual_length, 100); 706 | if (actual_length > 0) 707 | vframe("0x85",EP85_error, r, actual_length, buf, colormap); 708 | 709 | break; 710 | 711 | } 712 | 713 | // poll Endpoints 0x81, 0x83 714 | r = libusb_bulk_transfer(devh, 0x81, buf, sizeof(buf), &actual_length, 10); 715 | /* 716 | if (actual_length > 0 && actual_length <= 101) 717 | { 718 | 719 | 720 | 721 | char k[5]; 722 | if (strncmp (&buf[32],"VoltageUpdate",13)==0) 723 | { 724 | printf("xx %d\n",actual_length); 725 | 726 | 727 | char *token, *string, *tofree, *string2; 728 | // char l; 729 | strcpy(string,buf); 730 | // string = buf; 731 | // assert(string != NULL); 732 | printf("yy\n"); 733 | 734 | for (i = 32; i < (((200)<(actual_length))?(200):(actual_length)); i++) 735 | { 736 | if(string[i]>31) 737 | { 738 | printf("%c", string[i]); 739 | // printf("%d ", i); 740 | // string2[i-32] = string[i]; 741 | } 742 | } 743 | 744 | while ((token = strsep(&string, ":")) != NULL) 745 | { 746 | printf("zz\n"); 747 | printf("%s\n", token); 748 | } 749 | 750 | // free(tofree); 751 | // for (i = 32; i < (((200)<(actual_length))?(200):(actual_length)); i++) { 752 | // if(buf[i]>31) {printf("%c", buf[i]);} 753 | // } 754 | 755 | 756 | } 757 | } 758 | 759 | 760 | */ 761 | 762 | r = libusb_bulk_transfer(devh, 0x83, buf, sizeof(buf), &actual_length, 10); 763 | if (strcmp(libusb_error_name(r), "LIBUSB_ERROR_NO_DEVICE")==0) { 764 | fprintf(stderr, "EP 0x83 LIBUSB_ERROR_NO_DEVICE -> reset USB\n"); 765 | goto out; 766 | } 767 | // print_bulk_result("0x83",EP83_error, r, actual_length, buf); 768 | } 769 | 770 | // never reached ;-) 771 | libusb_release_interface(devh, 0); 772 | 773 | out: 774 | //close the device 775 | libusb_reset_device(devh); 776 | libusb_close(devh); 777 | libusb_exit(NULL); 778 | return r >= 0 ? r : -r; 779 | } 780 | 781 | int main(int argc, char **argv) 782 | { 783 | int i; 784 | unsigned char colormap[768]; 785 | FILE *fp; 786 | 787 | if(argc < 2) { 788 | fprintf(stderr, "\nUsage:flir8o palette.raw\n"); 789 | exit(1); 790 | } 791 | 792 | fp = fopen(argv[1], "rb"); 793 | fread(colormap, sizeof(unsigned char), 768, fp); // read 256 rgb values 794 | fclose(fp); 795 | 796 | while (1) 797 | { 798 | EPloop(colormap); 799 | } 800 | 801 | 802 | } 803 | -------------------------------------------------------------------------------- /src/font5x7.h: -------------------------------------------------------------------------------- 1 | /* From https://ccrma.stanford.edu/courses/250a-fall-2003/docs/avrlib-new/ */ 2 | 3 | /* Original header: */ 4 | 5 | /*! \file font5x7.h \brief Graphic LCD Font (Ascii Characters). */ 6 | //***************************************************************************** 7 | // 8 | // File Name: 'font5x7.h' 9 | // Title: Graphic LCD Font (Ascii Charaters) 10 | // Author: Pascal Stang 11 | // Date: 10/19/2001 12 | // Revised: 10/19/2001 13 | // Version: 0.1 14 | // Target MCU: Atmel AVR 15 | // Editor Tabs: 4 16 | // 17 | //***************************************************************************** 18 | 19 | /* Original license in cmdline.c: */ 20 | 21 | // This code is distributed under the GNU Public License 22 | // which can be found at http://www.gnu.org/licenses/gpl.txt 23 | 24 | /* Since the original license does not specify the GPL version it is safe */ 25 | /* to assume that it can be distributed under GPL version 1 or any later */ 26 | /* version. */ 27 | 28 | #define MAX_CHARS 96 29 | #define CHAR_OFFSET 0x20 30 | 31 | unsigned char font5x7_basic[MAX_CHARS][5] = { 32 | {0x00, 0x00, 0x00, 0x00, 0x00}, // (space) 33 | {0x00, 0x00, 0x5F, 0x00, 0x00}, // ! 34 | {0x00, 0x07, 0x00, 0x07, 0x00}, // " 35 | {0x14, 0x7F, 0x14, 0x7F, 0x14}, // # 36 | {0x24, 0x2A, 0x7F, 0x2A, 0x12}, // $ 37 | {0x23, 0x13, 0x08, 0x64, 0x62}, // % 38 | {0x36, 0x49, 0x55, 0x22, 0x50}, // & 39 | {0x00, 0x05, 0x03, 0x00, 0x00}, // ' 40 | {0x00, 0x1C, 0x22, 0x41, 0x00}, // ( 41 | {0x00, 0x41, 0x22, 0x1C, 0x00}, // ) 42 | {0x08, 0x2A, 0x1C, 0x2A, 0x08}, // * 43 | {0x08, 0x08, 0x63, 0x08, 0x08}, // + {0x08, 0x08, 0x3E, 0x08, 0x08} 44 | {0x00, 0x50, 0x30, 0x00, 0x00}, // , 45 | {0x08, 0x08, 0x08, 0x08, 0x08}, // - 46 | {0x00, 0x60, 0x60, 0x00, 0x00}, // . 47 | {0x20, 0x10, 0x08, 0x04, 0x02}, // / 48 | {0x3E, 0x51, 0x49, 0x45, 0x3E}, // 0 49 | {0x00, 0x42, 0x7F, 0x40, 0x00}, // 1 50 | {0x42, 0x61, 0x51, 0x49, 0x46}, // 2 51 | {0x21, 0x41, 0x45, 0x4B, 0x31}, // 3 52 | {0x18, 0x14, 0x12, 0x7F, 0x10}, // 4 53 | {0x27, 0x45, 0x45, 0x45, 0x39}, // 5 54 | {0x3C, 0x4A, 0x49, 0x49, 0x30}, // 6 55 | {0x01, 0x71, 0x09, 0x05, 0x03}, // 7 56 | {0x36, 0x49, 0x49, 0x49, 0x36}, // 8 57 | {0x06, 0x49, 0x49, 0x29, 0x1E}, // 9 58 | {0x00, 0x36, 0x36, 0x00, 0x00}, // : 59 | {0x00, 0x56, 0x36, 0x00, 0x00}, // ; 60 | {0x00, 0x08, 0x14, 0x22, 0x41}, // < 61 | {0x14, 0x14, 0x14, 0x14, 0x14}, // = 62 | {0x41, 0x22, 0x14, 0x08, 0x00}, // > 63 | {0x02, 0x01, 0x51, 0x09, 0x06}, // ? 64 | {0x32, 0x49, 0x79, 0x41, 0x3E}, // @ 65 | {0x7E, 0x11, 0x11, 0x11, 0x7E}, // A 66 | {0x7F, 0x49, 0x49, 0x49, 0x36}, // B 67 | {0x3E, 0x41, 0x41, 0x41, 0x22}, // C 68 | {0x7F, 0x41, 0x41, 0x22, 0x1C}, // D 69 | {0x7F, 0x49, 0x49, 0x49, 0x41}, // E 70 | {0x7F, 0x09, 0x09, 0x01, 0x01}, // F 71 | {0x3E, 0x41, 0x41, 0x51, 0x32}, // G 72 | {0x7F, 0x08, 0x08, 0x08, 0x7F}, // H 73 | {0x00, 0x41, 0x7F, 0x41, 0x00}, // I 74 | {0x20, 0x40, 0x41, 0x3F, 0x01}, // J 75 | {0x7F, 0x08, 0x14, 0x22, 0x41}, // K 76 | {0x7F, 0x40, 0x40, 0x40, 0x40}, // L 77 | {0x7F, 0x02, 0x04, 0x02, 0x7F}, // M 78 | {0x7F, 0x04, 0x08, 0x10, 0x7F}, // N 79 | {0x3E, 0x41, 0x41, 0x41, 0x3E}, // O 80 | {0x7F, 0x09, 0x09, 0x09, 0x06}, // P 81 | {0x3E, 0x41, 0x51, 0x21, 0x5E}, // Q 82 | {0x7F, 0x09, 0x19, 0x29, 0x46}, // R 83 | {0x46, 0x49, 0x49, 0x49, 0x31}, // S 84 | {0x01, 0x01, 0x7F, 0x01, 0x01}, // T 85 | {0x3F, 0x40, 0x40, 0x40, 0x3F}, // U 86 | {0x1F, 0x20, 0x40, 0x20, 0x1F}, // V 87 | {0x7F, 0x20, 0x18, 0x20, 0x7F}, // W 88 | {0x63, 0x14, 0x08, 0x14, 0x63}, // X 89 | {0x03, 0x04, 0x78, 0x04, 0x03}, // Y 90 | {0x61, 0x51, 0x49, 0x45, 0x43}, // Z 91 | {0x00, 0x00, 0x7F, 0x41, 0x41}, // [ 92 | {0x02, 0x04, 0x08, 0x10, 0x20}, // "\" 93 | {0x41, 0x41, 0x7F, 0x00, 0x00}, // ] 94 | {0x04, 0x02, 0x01, 0x02, 0x04}, // ^ 95 | {0x40, 0x40, 0x40, 0x40, 0x40}, // _ 96 | {0x00, 0x01, 0x02, 0x04, 0x00}, // ` 97 | {0x20, 0x54, 0x54, 0x54, 0x78}, // a 98 | {0x7F, 0x48, 0x44, 0x44, 0x38}, // b 99 | {0x38, 0x44, 0x44, 0x44, 0x20}, // c 100 | {0x38, 0x44, 0x44, 0x48, 0x7F}, // d 101 | {0x38, 0x54, 0x54, 0x54, 0x18}, // e 102 | {0x08, 0x7E, 0x09, 0x01, 0x02}, // f 103 | {0x08, 0x14, 0x54, 0x54, 0x3C}, // g 104 | {0x7F, 0x08, 0x04, 0x04, 0x78}, // h 105 | {0x00, 0x44, 0x7D, 0x40, 0x00}, // i 106 | {0x20, 0x40, 0x44, 0x3D, 0x00}, // j 107 | {0x00, 0x7F, 0x10, 0x28, 0x44}, // k 108 | {0x00, 0x41, 0x7F, 0x40, 0x00}, // l 109 | {0x7C, 0x04, 0x18, 0x04, 0x78}, // m 110 | {0x7C, 0x08, 0x04, 0x04, 0x78}, // n 111 | {0x38, 0x44, 0x44, 0x44, 0x38}, // o 112 | {0x7C, 0x14, 0x14, 0x14, 0x08}, // p 113 | {0x08, 0x14, 0x14, 0x18, 0x7C}, // q 114 | {0x7C, 0x08, 0x04, 0x04, 0x08}, // r 115 | {0x48, 0x54, 0x54, 0x54, 0x20}, // s 116 | {0x04, 0x3F, 0x44, 0x40, 0x20}, // t 117 | {0x3C, 0x40, 0x40, 0x20, 0x7C}, // u 118 | {0x1C, 0x20, 0x40, 0x20, 0x1C}, // v 119 | {0x3C, 0x40, 0x30, 0x40, 0x3C}, // w 120 | {0x44, 0x28, 0x10, 0x28, 0x44}, // x 121 | {0x0C, 0x50, 0x50, 0x50, 0x3C}, // y 122 | {0x44, 0x64, 0x54, 0x4C, 0x44}, // z 123 | {0x00, 0x08, 0x36, 0x41, 0x00}, // { 124 | {0x00, 0x00, 0x7F, 0x00, 0x00}, // | 125 | {0x00, 0x41, 0x36, 0x08, 0x00}, // } 126 | {0x08, 0x08, 0x2A, 0x1C, 0x08}, // -> 127 | {0x08, 0x1C, 0x2A, 0x08, 0x08}, // <- 128 | }; 129 | -------------------------------------------------------------------------------- /src/plank.h: -------------------------------------------------------------------------------- 1 | // -- define Flir calibration values --------------- 2 | // exiftool -plan* FLIROne-2015-11-30-17-26-48+0100.jpg 3 | 4 | #define PlanckR1 16528.178 5 | #define PlanckB 1427.5 6 | #define PlanckF 1.0 7 | #define PlanckO -1307.0 8 | #define PlanckR2 0.012258549 9 | 10 | #define TempReflected 20.0 // Reflected Apparent Temperature [°C] 11 | #define Emissivity 0.95 // Emissivity of object 12 | --------------------------------------------------------------------------------