-
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathfx.h
100 lines (88 loc) · 4.33 KB
/
fx.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
// luminosity reducer, taken from Bodmer's antialiased font
static uint16_t luminance(uint16_t color, uint8_t luminance)
{
// Extract rgb colours and stretch range to 0 - 255
uint16_t r = (color & 0xF800) >> 8; r |= (r >> 5);
uint16_t g = (color & 0x07E0) >> 3; g |= (g >> 6);
uint16_t b = (color & 0x001F) << 3; b |= (b >> 5);
b = ((b * (uint16_t)luminance + 255) >> 8) & 0x00F8;
g = ((g * (uint16_t)luminance + 255) >> 8) & 0x00FC;
r = ((r * (uint16_t)luminance + 255) >> 8) & 0x00F8;
return (r << 8) | (g << 3) | (b >> 3);
}
// Use as a gfx replacement for tft.fillScreen(TFT_BLACK).
// Produces a strobe effect by reducing luminosity on all non-black pixels.
// Limitations:
// - 16bits colors only
// - Only fades to black
// - frame rate must be >15fps
// - Sluggish when the sprite has too many (>50%) non black pixels
static void spriteFadeOut( LGFX_Sprite *sprite, uint8_t strength )
{
int32_t w = sprite->width();
int32_t h = sprite->height();
int32_t l = w*h;
uint16_t* framebuf = (uint16_t*)sprite->getBuffer();
for( uint32_t i=0;i<l;i++) {
if( framebuf[i]!=TFT_BLACK ) {
uint16_t pixcolor = (framebuf[i] >> 8) | (framebuf[i] << 8);
pixcolor = luminance( pixcolor, strength );
framebuf[i] = pixcolor<<8 | pixcolor>>8;
}
}
}
uint16_t getHeatMapColor( int minimum, int maximum, int value, RGBColor *colors, size_t palette_size )
{
float indexFloat = float(value-minimum) / float(maximum-minimum) * float(palette_size-1);
int paletteIndex = int(indexFloat/1);
float distance = indexFloat - float(paletteIndex);
if( distance < std::numeric_limits<float>::epsilon() ) {
return tft.color565( colors[paletteIndex].r, colors[paletteIndex].g, colors[paletteIndex].b );
} else {
uint8_t r1 = colors[paletteIndex].r;
uint8_t g1 = colors[paletteIndex].g;
uint8_t b1 = colors[paletteIndex].b;
uint8_t r2 = colors[paletteIndex+1].r;
uint8_t g2 = colors[paletteIndex+1].g;
uint8_t b2 = colors[paletteIndex+1].b;
return tft.color565( uint8_t(r1 + distance*float(r2-r1)), uint8_t(g1 + distance*float(g2-g1)), uint8_t(b1 + distance*float(b2-b1)) );
}
}
RGBColor heatMapColors[] = { {0, 0xff, 0}, {0xff, 0xff, 0}, {0xff, 0x80, 0}, {0xff, 0, 0}, {0x80, 0, 0} }; // green => yellow => orange => red => dark red
RGBColor greyscaleColors[] = { {0,0,0}, {0xff,0xff,0xff} };
const unsigned int qr_code_png_len = 261;
const unsigned char qr_code_png[qr_code_png_len] =
{
0x89, 0x50, 0x4e, 0x47, 0x0d, 0x0a, 0x1a, 0x0a, 0x00, 0x00, 0x00, 0x0d,
0x49, 0x48, 0x44, 0x52, 0x00, 0x00, 0x00, 0x32, 0x00, 0x00, 0x00, 0x32,
0x01, 0x03, 0x00, 0x00, 0x00, 0x24, 0xf1, 0x1a, 0xf2, 0x00, 0x00, 0x00,
0x06, 0x50, 0x4c, 0x54, 0x45, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xa5,
0x67, 0xb9, 0xcf, 0x00, 0x00, 0x00, 0x02, 0x74, 0x52, 0x4e, 0x53, 0xff,
0x00, 0xe5, 0xb7, 0x30, 0x4a, 0x00, 0x00, 0x00, 0x09, 0x70, 0x48, 0x59,
0x73, 0x00, 0x00, 0x0e, 0xc4, 0x00, 0x00, 0x0e, 0xc4, 0x01, 0x95, 0x2b,
0x0e, 0x1b, 0x00, 0x00, 0x00, 0x97, 0x49, 0x44, 0x41, 0x54, 0x18, 0x95,
0x55, 0xd0, 0x41, 0x0a, 0x05, 0x21, 0x08, 0x06, 0x60, 0xc1, 0xed, 0x80,
0x57, 0x09, 0xdc, 0x06, 0x5e, 0x5d, 0x68, 0x1b, 0x74, 0x95, 0xc0, 0x6d,
0xe0, 0xd4, 0xab, 0xa9, 0x9e, 0x9b, 0x0f, 0x04, 0xf5, 0x47, 0x00, 0x94,
0x14, 0xa0, 0xd7, 0x52, 0x0c, 0x98, 0xfd, 0x18, 0xb8, 0x91, 0xe1, 0x2d,
0xe3, 0xbf, 0x66, 0x7c, 0x29, 0x66, 0x34, 0xe7, 0xa7, 0x80, 0xcc, 0x73,
0xff, 0xd4, 0x9d, 0x9a, 0xbb, 0x6e, 0x83, 0xf6, 0x43, 0x19, 0xb6, 0x20,
0xf2, 0xc4, 0xa6, 0x5b, 0xab, 0xb9, 0x80, 0x1f, 0xe5, 0xd1, 0x5c, 0xd2,
0x31, 0xa2, 0xfa, 0x08, 0xfe, 0x59, 0x4b, 0xd3, 0x2a, 0xc7, 0x82, 0xc4,
0x25, 0xe8, 0x36, 0xb8, 0x51, 0xe8, 0xfd, 0x4f, 0xc3, 0xda, 0x46, 0xbc,
0x4f, 0x77, 0x21, 0xe1, 0x23, 0x20, 0xc8, 0x2f, 0xf8, 0x52, 0x8c, 0xa3,
0x44, 0xdd, 0x06, 0xce, 0x04, 0xcf, 0x2d, 0xa1, 0x01, 0x5c, 0x46, 0xc2,
0x71, 0x77, 0x29, 0x96, 0x3c, 0xf1, 0x71, 0xfc, 0xa5, 0xad, 0xff, 0x74,
0x5f, 0xd6, 0x73, 0x88, 0x3f, 0x85, 0x22, 0xee, 0x13, 0x00, 0x00, 0x00,
0x00, 0x49, 0x45, 0x4e, 0x44, 0xae, 0x42, 0x60, 0x82
};
void drawCaption( const char* str, uint32_t x, uint32_t y, uint32_t w, uint32_t h )
{
tft.setFont( &Font8x8C64 );
tft.setTextDatum( MC_DATUM );
tft.setTextColor( TFT_WHITE );
tft.setTextSize(1);
tft.drawRect( x-1, y-1, w, h, TFT_WHITE );
tft.fillRect( x, y, w-2, h-2, TFT_BLACK );
tft.drawString(str, x+w/2, y+h/2 );
}