Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 5019b86

Browse files
add thermal camera to ascii art example
1 parent 10e2ab1 commit 5019b86

File tree

13 files changed

+274
-126
lines changed

13 files changed

+274
-126
lines changed

‎.gitignore‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,4 +7,6 @@ node_modules
77
yarn-error.log
88
*.patch
99
model.h
10-
tensorflow
10+
tensorflow
11+
.idea/
12+
examples/.idea/

‎.idea/workspace.xml‎

Lines changed: 21 additions & 12 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎examples/.idea/examples.iml‎

Lines changed: 0 additions & 8 deletions
This file was deleted.

‎examples/.idea/misc.xml‎

Lines changed: 0 additions & 6 deletions
This file was deleted.

‎examples/.idea/modules.xml‎

Lines changed: 0 additions & 8 deletions
This file was deleted.

‎examples/.idea/vcs.xml‎

Lines changed: 0 additions & 6 deletions
This file was deleted.

‎examples/.idea/workspace.xml‎

Lines changed: 0 additions & 78 deletions
This file was deleted.
Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
#pragma once
2+
3+
#include <Stream.h>
4+
5+
namespace Eloquent {
6+
namespace ImageProcessing {
7+
8+
/**
9+
*
10+
* @tparam width
11+
* @tparam height
12+
*/
13+
template<size_t width, size_t height>
14+
class AsciiArt {
15+
public:
16+
AsciiArt(const uint8_t *data) {
17+
_data = data;
18+
}
19+
20+
/**
21+
* Get pixel at given coordinates
22+
* @param x
23+
* @param y
24+
* @return
25+
*/
26+
uint8_t at(size_t x, size_t y) {
27+
return _data[y * width + x];
28+
}
29+
30+
/**
31+
* Print as ASCII art picture
32+
* @param stream
33+
*/
34+
void print(Stream *stream, uint8_t frameSize = 0) {
35+
const char glyphs[] = " .,:;xyYX";
36+
const uint8_t glyphsCount = 9;
37+
38+
printAsciiArtHorizontalFrame(stream, frameSize);
39+
40+
for (size_t y = 0; y < height; y++) {
41+
// vertical frame
42+
for (uint8_t k = 0; k < frameSize; k++)
43+
Serial.print('|');
44+
45+
for (size_t x = 0; x < width; x++) {
46+
const uint8_t glyph = floor(((uint16_t) at(x, y)) * glyphsCount / 256);
47+
48+
stream->print(glyphs[glyph]);
49+
}
50+
51+
// vertical frame
52+
for (uint8_t k = 0; k < frameSize; k++)
53+
Serial.print('|');
54+
55+
stream->print('\n');
56+
stream->flush();
57+
}
58+
59+
printAsciiArtHorizontalFrame(stream, frameSize);
60+
}
61+
62+
protected:
63+
const uint8_t *_data;
64+
65+
/**
66+
*
67+
* @param stream
68+
* @param frameSize
69+
*/
70+
void printAsciiArtHorizontalFrame(Stream *stream, uint8_t frameSize) {
71+
for (uint8_t i = 0; i < frameSize; i++) {
72+
for (size_t j = 0; j < width + 2 * frameSize; j++)
73+
stream->print('-');
74+
stream->print('\n');
75+
stream->flush();
76+
}
77+
}
78+
};
79+
}
80+
}
Lines changed: 117 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,117 @@
1+
#pragma once
2+
3+
#include <Wire.h>
4+
#include <MLX90640_API.h>
5+
#include <MLX90640_I2C_Driver.h>
6+
7+
#ifndef TA_SHIFT
8+
//Default shift for MLX90640 in open air
9+
#define TA_SHIFT 8
10+
#endif
11+
12+
namespace Eloquent {
13+
namespace Sensors {
14+
15+
enum class MLX90640Status {
16+
OK,
17+
NOT_CONNECTED,
18+
DUMP_ERROR,
19+
PARAMETER_ERROR,
20+
FRAME_ERROR
21+
};
22+
23+
class MLX90640 {
24+
public:
25+
/**
26+
*
27+
* @param address
28+
*/
29+
MLX90640(uint8_t address = 0x33) :
30+
_address(address),
31+
_status(MLX90640Status::OK) {
32+
33+
}
34+
35+
/**
36+
*
37+
* @return
38+
*/
39+
bool begin() {
40+
Wire.begin();
41+
Wire.setClock(400000);
42+
43+
return isConnected() && loadParams();
44+
}
45+
46+
/**
47+
*
48+
* @return
49+
*/
50+
bool read(float result[768]) {
51+
for (byte x = 0 ; x < 2 ; x++) {
52+
uint16_t frame[834];
53+
int status = MLX90640_GetFrameData(_address, frame);
54+
55+
if (status < 0)
56+
return fail(MLX90640Status::FRAME_ERROR);
57+
58+
float vdd = MLX90640_GetVdd(frame, &_params);
59+
float Ta = MLX90640_GetTa(frame, &_params);
60+
float tr = Ta - TA_SHIFT;
61+
float emissivity = 0.95;
62+
63+
MLX90640_CalculateTo(frame, &_params, emissivity, tr, result);
64+
}
65+
}
66+
67+
protected:
68+
uint8_t _address;
69+
paramsMLX90640 _params;
70+
MLX90640Status _status;
71+
72+
/**
73+
* Test if device is connected
74+
* @return
75+
*/
76+
bool isConnected() {
77+
Wire.beginTransmission(_address);
78+
79+
if (Wire.endTransmission() == 0) {
80+
return true;
81+
}
82+
83+
return fail(MLX90640Status::NOT_CONNECTED);
84+
}
85+
86+
/**
87+
*
88+
* @return
89+
*/
90+
bool loadParams() {
91+
uint16_t ee[832];
92+
int status = MLX90640_DumpEE(_address, ee);
93+
94+
if (status != 0)
95+
return fail(MLX90640Status::DUMP_ERROR);
96+
97+
status = MLX90640_ExtractParameters(ee, &_params);
98+
99+
if (status != 0)
100+
return fail(MLX90640Status::PARAMETER_ERROR);
101+
102+
return true;
103+
}
104+
105+
/**
106+
* Mark a failure
107+
* @param status
108+
* @return
109+
*/
110+
bool fail(MLX90640Status status) {
111+
_status = status;
112+
113+
return false;
114+
}
115+
};
116+
}
117+
}

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /