mirror of
https://github.com/letscontrolit/ESPEasy.git
synced 2026-07-28 04:07:47 +00:00
Compare commits
1032
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
49a0476487 | ||
|
|
f606d2c55d | ||
|
|
4f9a383d93 | ||
|
|
d4d0ee3b30 | ||
|
|
9705702f4c | ||
|
|
c3e015342c | ||
|
|
209484554e | ||
|
|
27377ab3ed | ||
|
|
7055d24693 | ||
|
|
62e6317a23 | ||
|
|
29f89b687d | ||
|
|
697d20a028 | ||
|
|
e9df0e75b9 | ||
|
|
f23f49931b | ||
|
|
4af29c405b | ||
|
|
d780f1a07f | ||
|
|
f9be283cb7 | ||
|
|
3f1cda7b81 | ||
|
|
2fd226d6bd | ||
|
|
3d1edcf33e | ||
|
|
cc740b46f1 | ||
|
|
e829058c92 | ||
|
|
685438c35d | ||
|
|
f8a4ef389f | ||
|
|
7e9c31131c | ||
|
|
99150c4214 | ||
|
|
ec7e6f80b0 | ||
|
|
dada682ed6 | ||
|
|
ab31b33a2c | ||
|
|
621585901f | ||
|
|
eaaf1fe888 | ||
|
|
41e4705198 | ||
|
|
c35fe3d500 | ||
|
|
e2da8ecbb9 | ||
|
|
3dad26a58a | ||
|
|
ae930a1d36 | ||
|
|
45e980beda | ||
|
|
8723e177df | ||
|
|
8454994023 | ||
|
|
50732aed8a | ||
|
|
f2888951dc | ||
|
|
56ac640986 | ||
|
|
df2d7be30b | ||
|
|
9e06cf4dc7 | ||
|
|
cd27339b8e | ||
|
|
ec38ba1fb7 | ||
|
|
b8fa42925f | ||
|
|
4169ca0ee8 | ||
|
|
578477bf6d | ||
|
|
0803e946b0 | ||
|
|
06001bbc94 | ||
|
|
f171d5b211 | ||
|
|
360b552424 | ||
|
|
d9597febf8 | ||
|
|
6aa21ea6f8 | ||
|
|
b1de652b62 | ||
|
|
5c3bf9e894 | ||
|
|
0acd7b0e70 | ||
|
|
8bbaffdeb0 | ||
|
|
19e86e7df3 | ||
|
|
311d6f01df | ||
|
|
61f47d5ffc | ||
|
|
72f0f95471 | ||
|
|
4e33472d81 | ||
|
|
69c4f970a9 | ||
|
|
28866bd08c | ||
|
|
0f93e3ed3c | ||
|
|
59a82ee17f | ||
|
|
e8af00f99f | ||
|
|
ad4b0f8008 | ||
|
|
ae2a0b5208 | ||
|
|
785266bd39 | ||
|
|
2e63e764b2 | ||
|
|
f7eaecf5d4 | ||
|
|
1bee80d0ec | ||
|
|
504a9aa295 | ||
|
|
059530a6b7 | ||
|
|
5b83c634e9 | ||
|
|
ff7ab3837e | ||
|
|
badad651de | ||
|
|
8a767b77e8 | ||
|
|
072a1a4080 | ||
|
|
394e4b095d | ||
|
|
ae1e62c8c6 | ||
|
|
0efb7823d7 | ||
|
|
3ee7d4d04e | ||
|
|
f2d3a5d222 | ||
|
|
904a5cc612 | ||
|
|
5241f93f5f | ||
|
|
6d33d21f70 | ||
|
|
045e2ef9f4 | ||
|
|
527267de62 | ||
|
|
29c01eeb38 | ||
|
|
1c5a1d3656 | ||
|
|
d6fe76750a | ||
|
|
1889c0f9e5 | ||
|
|
ebc16044e2 | ||
|
|
5695ea8fa8 | ||
|
|
16cc9aaa6b | ||
|
|
7f393af2a0 | ||
|
|
3e22607276 | ||
|
|
4de720382d | ||
|
|
a718572688 | ||
|
|
2d66c9fefa | ||
|
|
de51a130b3 | ||
|
|
a8020c9011 | ||
|
|
a2cbc6d474 | ||
|
|
ea5c99431c | ||
|
|
6f68d87f50 | ||
|
|
4aa9c5e0ba | ||
|
|
7e4666afed | ||
|
|
7651a07efc | ||
|
|
f961a9f331 | ||
|
|
bb49cbdc89 | ||
|
|
7fe1b41ea5 | ||
|
|
358e9f1e24 | ||
|
|
8f77ffc871 | ||
|
|
60faa58894 | ||
|
|
aba095b25d | ||
|
|
617ebe96de | ||
|
|
a1bf42dde1 | ||
|
|
b0b83543eb | ||
|
|
b97be9c718 | ||
|
|
33831b072b | ||
|
|
a5f94298d8 | ||
|
|
d0dc959d31 | ||
|
|
644aa2f65e | ||
|
|
e457fe7597 | ||
|
|
dcd409e9d9 | ||
|
|
c227c13ba2 | ||
|
|
c64566ce49 | ||
|
|
a9366c8f23 | ||
|
|
bbf470c61d | ||
|
|
1c1211c4f3 | ||
|
|
7da0bc4a44 | ||
|
|
91a0c51ff8 | ||
|
|
0aa523a329 | ||
|
|
cac7275eb9 | ||
|
|
109eaf7d25 | ||
|
|
9ba15f2c19 | ||
|
|
1c07d787c5 | ||
|
|
b7ae2ea5fe | ||
|
|
b75bb204e3 | ||
|
|
bfc8006205 | ||
|
|
aab2e4a442 | ||
|
|
abfdfe014e | ||
|
|
f82040d2ef | ||
|
|
56f2cf3121 | ||
|
|
6349f07d1a | ||
|
|
1b44559d3e | ||
|
|
a151e60755 | ||
|
|
ce11c84e74 | ||
|
|
9808bf86c4 | ||
|
|
cfae636e55 | ||
|
|
ebaaf50df6 | ||
|
|
5c0be9e89f | ||
|
|
36468663f7 | ||
|
|
fba32608ee | ||
|
|
06848e50c3 | ||
|
|
879d0d4916 | ||
|
|
d083a58cd7 | ||
|
|
b1e9ff9fdc | ||
|
|
304280f415 | ||
|
|
2c8ca1421f | ||
|
|
3ce0fb9f75 | ||
|
|
8a71d2abd6 | ||
|
|
1b174f4eac | ||
|
|
f1d18c7b41 | ||
|
|
204d4607ba | ||
|
|
51f7ce0cb6 | ||
|
|
8f73deb133 | ||
|
|
1d4147309c | ||
|
|
a68e4c1456 | ||
|
|
2ee51363dd | ||
|
|
172eb37b5b | ||
|
|
68e1d8ea69 | ||
|
|
ac8e8db0e7 | ||
|
|
d72bf9b76c | ||
|
|
6d3f535d16 | ||
|
|
0709763f3a | ||
|
|
538d843643 | ||
|
|
2339ee928c | ||
|
|
9550b951d5 | ||
|
|
0491af8a2f | ||
|
|
806a2757b2 | ||
|
|
3931b71d00 | ||
|
|
af0c3d5f62 | ||
|
|
c7a6ca4555 | ||
|
|
4a01e2eb49 | ||
|
|
d6ff20b35d | ||
|
|
0ada9aa105 | ||
|
|
6b04539571 | ||
|
|
9380ec13dc | ||
|
|
ae946c27c0 | ||
|
|
86cf00759f | ||
|
|
0eb5f55d63 | ||
|
|
f27d2aa7eb | ||
|
|
2d3285aaaf | ||
|
|
5bd2532853 | ||
|
|
765c56ccef | ||
|
|
4c755d83a6 | ||
|
|
1b9e1b92aa | ||
|
|
a4c73cc91e | ||
|
|
736fe2111a | ||
|
|
767b0af733 | ||
|
|
02255180e9 | ||
|
|
c3bde94f7a | ||
|
|
886958d479 | ||
|
|
84cbc19f38 | ||
|
|
178ec9dfa9 | ||
|
|
080be1ad0a | ||
|
|
232ca4f215 | ||
|
|
bfa6eac538 | ||
|
|
0ca06782b9 | ||
|
|
2079b0f28b | ||
|
|
32bf45e817 | ||
|
|
5d41bf9e73 | ||
|
|
dc5a2fd956 | ||
|
|
b20f05305b | ||
|
|
46586e5355 | ||
|
|
7e8a751657 | ||
|
|
7d61e55d34 | ||
|
|
2f663429a3 | ||
|
|
492791a4ac | ||
|
|
52e75ade78 | ||
|
|
525a0ba0a1 | ||
|
|
52c7e5012e | ||
|
|
4dd733eb63 | ||
|
|
02a065d623 | ||
|
|
e774ef5751 | ||
|
|
0afee4fafb | ||
|
|
eba1fb3388 | ||
|
|
b2c866edeb | ||
|
|
3583db3e22 | ||
|
|
5d3f8bf073 | ||
|
|
1a72444b0a | ||
|
|
dd88db1913 | ||
|
|
aab00567fc | ||
|
|
21cb6135dd | ||
|
|
f613bb4572 | ||
|
|
51059f0c18 | ||
|
|
dec6598f49 | ||
|
|
f8f6767bec | ||
|
|
07948c87aa | ||
|
|
5c475b98db | ||
|
|
58fb8dc42b | ||
|
|
cb2b11a41a | ||
|
|
ac4f3c4cd4 | ||
|
|
c651e29d2a | ||
|
|
d7e886a841 | ||
|
|
eec7647782 | ||
|
|
6f9d120ff0 | ||
|
|
28ddc2d9c0 | ||
|
|
cc54354ac3 | ||
|
|
3929390629 | ||
|
|
5f4685337e | ||
|
|
08c158aa9c | ||
|
|
e9d71a8f35 | ||
|
|
3e3173cbb0 | ||
|
|
3a26ebf7b1 | ||
|
|
1685bead52 | ||
|
|
3a2fe35e5c | ||
|
|
29ce7f774f | ||
|
|
cc85327356 | ||
|
|
0851bb655e | ||
|
|
d4bc10d8f1 | ||
|
|
0672f32f4b | ||
|
|
a17f7b679c | ||
|
|
425bd85c83 | ||
|
|
3be005e1ee | ||
|
|
174f9e6e03 | ||
|
|
51a14a174f | ||
|
|
7cb1f453d3 | ||
|
|
23a6caab89 | ||
|
|
6b4300bd46 | ||
|
|
04a9069db0 | ||
|
|
dd636903c8 | ||
|
|
4543a10739 | ||
|
|
940b65e86a | ||
|
|
6344de0649 | ||
|
|
8ccd7c3e8d | ||
|
|
22371649a4 | ||
|
|
2a48d5033e | ||
|
|
f064da797d | ||
|
|
b0b8edf935 | ||
|
|
8cbd9a0822 | ||
|
|
93f9d11738 | ||
|
|
cf3e0a3f0a | ||
|
|
ccfd14dbd3 | ||
|
|
3034738ad4 | ||
|
|
178d1c46a2 | ||
|
|
cdfd1d986e | ||
|
|
4b7aa53692 | ||
|
|
7959a5133f | ||
|
|
941fb5c29c | ||
|
|
c43c9ea2b3 | ||
|
|
967103bcad | ||
|
|
efe637ec70 | ||
|
|
00450eb260 | ||
|
|
cc02fa4481 | ||
|
|
1c5f8af083 | ||
|
|
fccc31a7c6 | ||
|
|
b84d905a0b | ||
|
|
94aa951cba | ||
|
|
2a23dcd011 | ||
|
|
ab3a406706 | ||
|
|
e7a9ee7eee | ||
|
|
3edfdbf5f7 | ||
|
|
27bac2ca00 | ||
|
|
373f74e9f8 | ||
|
|
1220c565c8 | ||
|
|
1931fe9e53 | ||
|
|
0eab6293dc | ||
|
|
f0987dab41 | ||
|
|
51bd52603f | ||
|
|
47f1fa145a | ||
|
|
605055d95a | ||
|
|
af3e353181 | ||
|
|
c711d6ea51 | ||
|
|
20c23a2935 | ||
|
|
bbfe254232 | ||
|
|
882c888f6d | ||
|
|
0a754f072c | ||
|
|
1f084c51cc | ||
|
|
89df0932c5 | ||
|
|
429fd3e4d0 | ||
|
|
85e8d98da8 | ||
|
|
6d52a7e03a | ||
|
|
fa513b52f9 | ||
|
|
f98401524f | ||
|
|
4090b4f23c | ||
|
|
b89c00008d | ||
|
|
d57a617138 | ||
|
|
cefe6b4b7c | ||
|
|
2432740b41 | ||
|
|
44a934651c | ||
|
|
95fb0d6e6c | ||
|
|
8ccbdcadf0 | ||
|
|
433aa6910a | ||
|
|
f135c63d84 | ||
|
|
2ebc733b63 | ||
|
|
21bc1a7814 | ||
|
|
53b8009df6 | ||
|
|
68a8e5982e | ||
|
|
08acfeac97 | ||
|
|
999a561515 | ||
|
|
3ee1a4ed2e | ||
|
|
05801db47c | ||
|
|
7bec632f15 | ||
|
|
3f8fe11b47 | ||
|
|
4b8f1e4c1b | ||
|
|
573fd0f320 | ||
|
|
4fa5203c5b | ||
|
|
9c9617f6ed | ||
|
|
bbbf6c483f | ||
|
|
668909e7b3 | ||
|
|
c642848ef2 | ||
|
|
6eea35aa81 | ||
|
|
738a48213c | ||
|
|
d1c093d109 | ||
|
|
00166a1aad | ||
|
|
589238324b | ||
|
|
6787bc8c0e | ||
|
|
6845a03741 | ||
|
|
6a4284f189 | ||
|
|
cf644b45b1 | ||
|
|
e6fe1c63a9 | ||
|
|
df978036f0 | ||
|
|
7cb375833d | ||
|
|
41c57f1ef9 | ||
|
|
808b40bdba | ||
|
|
58b20615da | ||
|
|
13026b1cc4 | ||
|
|
7f3460e492 | ||
|
|
a222391f81 | ||
|
|
a8165531d5 | ||
|
|
3218ea9839 | ||
|
|
eca8901fca | ||
|
|
6635eafe91 | ||
|
|
fe4d1f952f | ||
|
|
1abd31b421 | ||
|
|
72fe49d905 | ||
|
|
9dd9f3befa | ||
|
|
471d76dbe6 | ||
|
|
4475a225cc | ||
|
|
8b047490c4 | ||
|
|
455f77d0ed | ||
|
|
836fc4a875 | ||
|
|
2aece1c143 | ||
|
|
70df225e7e | ||
|
|
19af52a3ef | ||
|
|
3d396575ff | ||
|
|
873f8474b5 | ||
|
|
826deaac89 | ||
|
|
cce621cff8 | ||
|
|
57eb38dbd0 | ||
|
|
fd2451bb07 | ||
|
|
c94e5cb903 | ||
|
|
27699f7192 | ||
|
|
2eff001b14 | ||
|
|
bd499c7a94 | ||
|
|
4da1e4fbdd | ||
|
|
1d14770ea7 | ||
|
|
8b7574d298 | ||
|
|
14d87d95f6 | ||
|
|
daecf2017e | ||
|
|
37122bc619 | ||
|
|
5a15288d80 | ||
|
|
869dff12ce | ||
|
|
cc0b3dac26 | ||
|
|
4208048fc1 | ||
|
|
06a2f47812 | ||
|
|
d3434eb4d2 | ||
|
|
bd2665041f | ||
|
|
1fd429a029 | ||
|
|
7b3a71bcc9 | ||
|
|
18e612dea2 | ||
|
|
f99593ed62 | ||
|
|
2f7e96fa5b | ||
|
|
25b4392dd5 | ||
|
|
ad4130a547 | ||
|
|
e4d4463eab | ||
|
|
991384822f | ||
|
|
b29f56c6f4 | ||
|
|
779514481d | ||
|
|
82ed319e59 | ||
|
|
0a752dd26f | ||
|
|
2e4af86a99 | ||
|
|
8112e0e67a | ||
|
|
89a9f842fd | ||
|
|
b4791d3421 | ||
|
|
885c5394a3 | ||
|
|
e35304e4e7 | ||
|
|
6561d577d4 | ||
|
|
92932fddb2 | ||
|
|
02d8834763 | ||
|
|
e82080dc52 | ||
|
|
89581fd0fb | ||
|
|
cfbf972c1b | ||
|
|
e25ea52edc | ||
|
|
3f84a961ad | ||
|
|
7d8e5e5175 | ||
|
|
3d39dec686 | ||
|
|
ff656593ec | ||
|
|
96bfaa27f5 | ||
|
|
bcca0514dd | ||
|
|
90b4e3438d | ||
|
|
139f8905d0 | ||
|
|
6c1806fae6 | ||
|
|
e6b581e7ff | ||
|
|
bb9f8fc809 | ||
|
|
4d9504bce0 | ||
|
|
ff3a769033 | ||
|
|
e3de56a7a8 | ||
|
|
873d639461 | ||
|
|
edb2a6d3f6 | ||
|
|
2682b0bd2f | ||
|
|
5097157a09 | ||
|
|
02ea957894 | ||
|
|
c2b0d76595 | ||
|
|
91b7cbe075 | ||
|
|
bff60a2e27 | ||
|
|
61831e5962 | ||
|
|
d105b47d44 | ||
|
|
449568bcc4 | ||
|
|
3144077103 | ||
|
|
8f056be0a8 | ||
|
|
e9cdc5693d | ||
|
|
64b38df187 | ||
|
|
377c50ec36 | ||
|
|
76f6dfdc59 | ||
|
|
3a6f7acd15 | ||
|
|
d65b126f84 | ||
|
|
90a2a799da | ||
|
|
feb419b6ae | ||
|
|
e83d8468b0 | ||
|
|
6eabaaa62d | ||
|
|
8299e38b24 | ||
|
|
b0169b4aa7 | ||
|
|
786ec4714a | ||
|
|
67a28a7f97 | ||
|
|
18b8e61d32 | ||
|
|
5821b0709c | ||
|
|
ec783fe03b | ||
|
|
4d749b19fd | ||
|
|
6a66440a5f | ||
|
|
1b23efe48c | ||
|
|
9a9d39763f | ||
|
|
9f94ef073c | ||
|
|
9122565431 | ||
|
|
000d2d7c77 | ||
|
|
64a0f79e02 | ||
|
|
c1b945e6c1 | ||
|
|
dbbe6b65dd | ||
|
|
92e4a8da9b | ||
|
|
4611ef5d87 | ||
|
|
807cc1796d | ||
|
|
4bca2c6361 | ||
|
|
40e2d7ec8e | ||
|
|
7318e87965 | ||
|
|
9c3a28439f | ||
|
|
82933ae170 | ||
|
|
503fd3555e | ||
|
|
127627a22c | ||
|
|
e59401e24f | ||
|
|
769f76d3dc | ||
|
|
4eb7cf0859 | ||
|
|
a464f638ad | ||
|
|
f31cce4182 | ||
|
|
a5cfe1beec | ||
|
|
f36fada375 | ||
|
|
d51bce97f5 | ||
|
|
0368aa4d43 | ||
|
|
3c4aa7564f | ||
|
|
f46b89f1bd | ||
|
|
4e2b78056a | ||
|
|
d94ce17fd4 | ||
|
|
cd2c59ba5b | ||
|
|
b6a6943668 | ||
|
|
a8fcb420e7 | ||
|
|
e1e894d540 | ||
|
|
d15311e70a | ||
|
|
3ed6564063 | ||
|
|
5f575c0224 | ||
|
|
34c1ba158f | ||
|
|
04ca424085 | ||
|
|
7a8f476e05 | ||
|
|
eef8391ffc | ||
|
|
d47751c31f | ||
|
|
e42ab85f4b | ||
|
|
b048d3f1f8 | ||
|
|
f94ab3a04a | ||
|
|
1b9375f83b | ||
|
|
a77798d18f | ||
|
|
3094cb5260 | ||
|
|
ec4dd09968 | ||
|
|
d68a5fb9d4 | ||
|
|
0e67480f46 | ||
|
|
c32f2cc89d | ||
|
|
ad489f0db2 | ||
|
|
d9267fa9c2 | ||
|
|
e82fb37870 | ||
|
|
635c149f12 | ||
|
|
26f00dcdec | ||
|
|
b2bb1d039b | ||
|
|
57e256a5fa | ||
|
|
c58e975b7e | ||
|
|
7d16ffa4a4 | ||
|
|
856e370ba0 | ||
|
|
4df9e7d065 | ||
|
|
edb3857e04 | ||
|
|
08312cbcb7 | ||
|
|
fb1cc219ee | ||
|
|
da7329891d | ||
|
|
953a53bb9a | ||
|
|
e9fac7926f | ||
|
|
810a0b2aa9 | ||
|
|
7f897bc856 | ||
|
|
5d9137d1d2 | ||
|
|
8de49cd38e | ||
|
|
0092ba92b5 | ||
|
|
fe1c44f6b3 | ||
|
|
e39d588530 | ||
|
|
7a4e3d954d | ||
|
|
9dc4fefa0b | ||
|
|
4ca318f5a6 | ||
|
|
695bb58d64 | ||
|
|
608a7212eb | ||
|
|
37a24933f5 | ||
|
|
a6b447600f | ||
|
|
5fbb900e5b | ||
|
|
aa5dee01fb | ||
|
|
4e2a5d3b3d | ||
|
|
1a44ed6578 | ||
|
|
e86667e37e | ||
|
|
0db1f78421 | ||
|
|
780c34846e | ||
|
|
a4dcc304a9 | ||
|
|
a938bc78c1 | ||
|
|
d2c7743197 | ||
|
|
f0fc20de57 | ||
|
|
d35a50be17 | ||
|
|
537d4cd1e9 | ||
|
|
62422f4924 | ||
|
|
04de145dbb | ||
|
|
21840d0b26 | ||
|
|
076ce0127b | ||
|
|
226c0a6f83 | ||
|
|
6ffa8d92a6 | ||
|
|
dae2cc2f4a | ||
|
|
555ccbe229 | ||
|
|
d277d22914 | ||
|
|
b5e4994392 | ||
|
|
cbdddf8c06 | ||
|
|
8b5d22a081 | ||
|
|
88fc0a8445 | ||
|
|
ec9187d038 | ||
|
|
51ede17d2a | ||
|
|
97ee69b371 | ||
|
|
f77ce9c8f7 | ||
|
|
99cc6f72af | ||
|
|
848f43b704 | ||
|
|
3a5ef5da81 | ||
|
|
3527b69718 | ||
|
|
54628bfca9 | ||
|
|
72ff745eff | ||
|
|
aed566b6db | ||
|
|
504ea0c813 | ||
|
|
4ca5ef3f72 | ||
|
|
dd9db3b557 | ||
|
|
9c531b30bc | ||
|
|
67c8477a61 | ||
|
|
cd30b81202 | ||
|
|
550881faa5 | ||
|
|
3d07466904 | ||
|
|
ed45945f21 | ||
|
|
f13abe8922 | ||
|
|
34b0a683a9 | ||
|
|
9ab10437b5 | ||
|
|
b0b7408522 | ||
|
|
b104942db9 | ||
|
|
a694b658b1 | ||
|
|
cb07a0d342 | ||
|
|
1ceaad04ec | ||
|
|
5cbf0c1e38 | ||
|
|
4951f294b9 | ||
|
|
ef0ef092f0 | ||
|
|
46d3ae6a2b | ||
|
|
ef1bf646ab | ||
|
|
f72a48ffc2 | ||
|
|
da54ddda78 | ||
|
|
03ee569510 | ||
|
|
c24205713d | ||
|
|
52d4cb804e | ||
|
|
ae077de72b | ||
|
|
86fa5ec6ae | ||
|
|
41c9d68422 | ||
|
|
e713da5d79 | ||
|
|
edc261ca2b | ||
|
|
8f4a52a6f1 | ||
|
|
af519748a6 | ||
|
|
c04b80b2f1 | ||
|
|
cdbc2498c1 | ||
|
|
78997b4329 | ||
|
|
2bece45712 | ||
|
|
10c73a001a | ||
|
|
790a946cf6 | ||
|
|
69c5be6489 | ||
|
|
233ca2bf43 | ||
|
|
3de400fc91 | ||
|
|
edeea02f71 | ||
|
|
6fae1f79d8 | ||
|
|
1222e04caf | ||
|
|
f38973aad6 | ||
|
|
b31b1d913f | ||
|
|
fa3d4af8cb | ||
|
|
29320aab90 | ||
|
|
3bc8609611 | ||
|
|
c43d6b3769 | ||
|
|
e9e2ea32ed | ||
|
|
24b7d1f438 | ||
|
|
4febf08501 | ||
|
|
7f4eae19f4 | ||
|
|
c13952d04c | ||
|
|
3032463917 | ||
|
|
f5e84a155e | ||
|
|
bbb97bfc7e | ||
|
|
e51f7683a5 | ||
|
|
e747756dd2 | ||
|
|
1ad6fd6ea0 | ||
|
|
d2ec15a4bf | ||
|
|
f23d9fa3d3 | ||
|
|
6df5840db9 | ||
|
|
5f79e4b922 | ||
|
|
e058507b9a | ||
|
|
3cea522ec4 | ||
|
|
5c4defdf6e | ||
|
|
e58ea2a3fe | ||
|
|
a93a078c0b | ||
|
|
0e0e7be95a | ||
|
|
2b7a61469f | ||
|
|
ce02c9e039 | ||
|
|
1e9dc1d14c | ||
|
|
75f1c6c140 | ||
|
|
9a6f7360da | ||
|
|
e3cd057ad8 | ||
|
|
fec069ba00 | ||
|
|
d835ef679c | ||
|
|
9144e7901b | ||
|
|
858ce397c3 | ||
|
|
78c9ff70be | ||
|
|
b2db97e808 | ||
|
|
4e537461f2 | ||
|
|
dc7bb12581 | ||
|
|
0c80cdc119 | ||
|
|
37210031b7 | ||
|
|
40eb3e7ceb | ||
|
|
d7134e6b87 | ||
|
|
8dc1924059 | ||
|
|
a7b77b6008 | ||
|
|
88320d25fc | ||
|
|
649305a2dd | ||
|
|
d49197a621 | ||
|
|
2371b0f315 | ||
|
|
9abdd097c9 | ||
|
|
f8849cb601 | ||
|
|
b293e8fee0 | ||
|
|
11b1c8505a | ||
|
|
9cb3ceed83 | ||
|
|
2ac1df9482 | ||
|
|
59b7768722 | ||
|
|
d4e5742b1c | ||
|
|
baa1df620f | ||
|
|
a310811919 | ||
|
|
e9dd5da690 | ||
|
|
f9c25489d1 | ||
|
|
46ee928b07 | ||
|
|
3af102f2ad | ||
|
|
ca53ec0263 | ||
|
|
5ca7c073f1 | ||
|
|
f815564dc7 | ||
|
|
b320c2a1e2 | ||
|
|
2b51a4d7c4 | ||
|
|
01d0723424 | ||
|
|
3f68154819 | ||
|
|
7b1c4483bb | ||
|
|
572d9c0714 | ||
|
|
b85010006b | ||
|
|
48643cf87e | ||
|
|
9ea594afeb | ||
|
|
aec539be43 | ||
|
|
749c8cd931 | ||
|
|
49a783c381 | ||
|
|
c9b81f7ab9 | ||
|
|
eb2dbb5b90 | ||
|
|
e49f31121c | ||
|
|
91c6e3af61 | ||
|
|
faeb921bcf | ||
|
|
9928f56ad3 | ||
|
|
61d27084c1 | ||
|
|
e5393a9fa4 | ||
|
|
1cbc49021a | ||
|
|
84f389b44e | ||
|
|
765775e22f | ||
|
|
02c97c4513 | ||
|
|
bd874c4a13 | ||
|
|
d87cd7eafe | ||
|
|
58bb62cc1a | ||
|
|
6b8ea6c15b | ||
|
|
a62dd5ce8f | ||
|
|
92889b6cf1 | ||
|
|
b5479575eb | ||
|
|
201d013230 | ||
|
|
6fead68f34 | ||
|
|
9a77b1727c | ||
|
|
2f26cd13bc | ||
|
|
f0d35527df | ||
|
|
3a9ef290e8 | ||
|
|
9cbaa4d7e7 | ||
|
|
af4ad9fbcb | ||
|
|
36a9bdae72 | ||
|
|
ebfa0a45a6 | ||
|
|
c2e70360c4 | ||
|
|
8bdfa656de | ||
|
|
952bf68b93 | ||
|
|
712a5e80d0 | ||
|
|
a44069ae26 | ||
|
|
13f73c0156 | ||
|
|
bb88225cab | ||
|
|
3089b288b2 | ||
|
|
6abea46eb5 | ||
|
|
ffa73aee59 | ||
|
|
f4b7e97997 | ||
|
|
b32212b061 | ||
|
|
66d0de684a | ||
|
|
cae3baf71e | ||
|
|
27db33f1bd | ||
|
|
23d5709957 | ||
|
|
b96e12f217 | ||
|
|
16eb08afa0 | ||
|
|
ad8e229c06 | ||
|
|
b9b7ceccb6 | ||
|
|
5c4bf52b66 | ||
|
|
34369d268e | ||
|
|
0ec7085022 | ||
|
|
913cd67eee | ||
|
|
3292051bae | ||
|
|
2586b94e28 | ||
|
|
d492347f31 | ||
|
|
b811b13483 | ||
|
|
56f9bc9c3a | ||
|
|
c149888bed | ||
|
|
82cea3db2e | ||
|
|
8aea298854 | ||
|
|
5617fbe0a0 | ||
|
|
6a643da8ee | ||
|
|
2f32799b67 | ||
|
|
ee568a76c1 | ||
|
|
beaf077b06 | ||
|
|
fd5da94f9c | ||
|
|
0694fcc5fb | ||
|
|
e36a9f163e | ||
|
|
17f0f6637a | ||
|
|
bc91939757 | ||
|
|
eb743f95cf | ||
|
|
0ec770fc51 | ||
|
|
ed4cdc3d90 | ||
|
|
9da5f465d1 | ||
|
|
8e72ace3b5 | ||
|
|
5230a4fe4f | ||
|
|
b236887718 | ||
|
|
2527cbe097 | ||
|
|
cbca4c3efa | ||
|
|
5b0e9d934c | ||
|
|
19429e8507 | ||
|
|
a67f92176f | ||
|
|
3922827fad | ||
|
|
0c637da19f | ||
|
|
48f168da9d | ||
|
|
3357eb287c | ||
|
|
5da1c54b70 | ||
|
|
c5bbdb401a | ||
|
|
f69b84d24b | ||
|
|
1250e09fef | ||
|
|
fbf22ba7af | ||
|
|
5c26d50227 | ||
|
|
47be037be9 | ||
|
|
bc4f7d390c | ||
|
|
9fe64834f9 | ||
|
|
4d943c2386 | ||
|
|
4b298d6e31 | ||
|
|
c0c65364e5 | ||
|
|
51b76682cf | ||
|
|
5f89698308 | ||
|
|
400ee82686 | ||
|
|
485f97bdc2 | ||
|
|
5821377b6c | ||
|
|
e6e3c1ddee | ||
|
|
a6ea35ef9c | ||
|
|
fe9a579dc3 | ||
|
|
017aad051e | ||
|
|
8a30659015 | ||
|
|
ed7f597b3d | ||
|
|
6700030d7c | ||
|
|
f45c7650de | ||
|
|
a36ee65865 | ||
|
|
b61c638f0a | ||
|
|
dfb5b8a4c5 | ||
|
|
09e5d6abcd | ||
|
|
2aafbb57a8 | ||
|
|
9d3dd49e9d | ||
|
|
744f22112b | ||
|
|
b38edfb672 | ||
|
|
a73875a2e2 | ||
|
|
0833029c82 | ||
|
|
71cf207bf7 | ||
|
|
f7ea185f80 | ||
|
|
3d3a035822 | ||
|
|
11a94aae25 | ||
|
|
af3bf5217d | ||
|
|
11f47f26e6 | ||
|
|
57c6fbbaab | ||
|
|
f7b37306aa | ||
|
|
8b3d8f6ad4 | ||
|
|
7a9726063d | ||
|
|
d6680b604f | ||
|
|
25ef1803e0 | ||
|
|
2bc72151bc | ||
|
|
93ceae3bef | ||
|
|
b5cad22afd | ||
|
|
2bf31a1985 | ||
|
|
5796f50439 | ||
|
|
36415d424e | ||
|
|
76be5dd8d9 | ||
|
|
407dae03ca | ||
|
|
6e760cd25b | ||
|
|
69c03cafb9 | ||
|
|
c17e683834 | ||
|
|
311abeabd0 | ||
|
|
b20d4a10ba | ||
|
|
548bf8b867 | ||
|
|
0b68e16894 | ||
|
|
33e46addbb | ||
|
|
04f27e0d03 | ||
|
|
628ff925b7 | ||
|
|
6fddf25a39 | ||
|
|
84e58285af | ||
|
|
fc5103de8d | ||
|
|
14b6345277 | ||
|
|
9a70037e32 | ||
|
|
3a8323faab | ||
|
|
fe1944922c | ||
|
|
7ea0c767fa | ||
|
|
ec18e5c530 | ||
|
|
885781850b | ||
|
|
443b46f383 | ||
|
|
8ce1aa0092 | ||
|
|
801a591282 | ||
|
|
740efcb763 | ||
|
|
67fa39f4ed | ||
|
|
7a8bb7c0e0 | ||
|
|
961b1106aa | ||
|
|
9dc549e62d | ||
|
|
c1a11ff6e4 | ||
|
|
151bf18cc6 | ||
|
|
d2e2522c07 | ||
|
|
4a212302e0 | ||
|
|
993dd7ade3 | ||
|
|
e4d68b9d0e | ||
|
|
b5e093bc80 | ||
|
|
d544fc84e8 | ||
|
|
e6dba4456c | ||
|
|
a0a0c31a49 | ||
|
|
d2777a9b15 | ||
|
|
c7d12bb798 | ||
|
|
901d87ad1d | ||
|
|
ef912a4484 | ||
|
|
b4debd9559 | ||
|
|
d7277649dd | ||
|
|
f177ff9e11 | ||
|
|
53a2008a0a | ||
|
|
2525b0e502 | ||
|
|
b7e7c0bb0b | ||
|
|
a397796188 | ||
|
|
33ec7e5240 | ||
|
|
d62b692b3b | ||
|
|
493bfd56b9 | ||
|
|
0f0bc30052 | ||
|
|
abbfa24ca6 | ||
|
|
fae1edc859 | ||
|
|
a9a741f775 | ||
|
|
c0d482e4fc | ||
|
|
2b256389dd | ||
|
|
b5cabdc775 | ||
|
|
e103cc38f7 | ||
|
|
c71a43c3a6 | ||
|
|
cd01283ac6 | ||
|
|
7ce1077bd6 | ||
|
|
f9701d1c7b | ||
|
|
e764830113 | ||
|
|
28eceffedf | ||
|
|
57a1b0dd6f | ||
|
|
9646457b50 | ||
|
|
7346e55e0d | ||
|
|
ae38a8cb4f | ||
|
|
df46a4a5fc | ||
|
|
a0b546e416 | ||
|
|
7c6797a141 | ||
|
|
83abac8c5e | ||
|
|
5ba6b2f335 | ||
|
|
64caeac9ee | ||
|
|
0d4ba7c6f1 | ||
|
|
a1fc351183 | ||
|
|
3131a075f5 | ||
|
|
33a6c39fc4 | ||
|
|
f853f6ef25 | ||
|
|
7a2d114360 | ||
|
|
0157f387ee | ||
|
|
3418f2b708 | ||
|
|
5a0f588344 | ||
|
|
d362446451 | ||
|
|
c23be231e1 | ||
|
|
00f5c36919 | ||
|
|
c960175ec1 | ||
|
|
e456604436 | ||
|
|
ac4657e77f | ||
|
|
3817427e79 | ||
|
|
0200b3c63e | ||
|
|
972a1a5703 | ||
|
|
73c22176b8 | ||
|
|
4db036f350 | ||
|
|
52223f0a20 | ||
|
|
907ad0faf6 | ||
|
|
887e10c947 | ||
|
|
b4c463e452 | ||
|
|
66ba9b1f46 | ||
|
|
7db50811ba | ||
|
|
17d20705ff | ||
|
|
e3bd782a42 | ||
|
|
b073379fff | ||
|
|
b89d8ff946 | ||
|
|
22ad971c8e | ||
|
|
ab06cc3703 | ||
|
|
8a5cc5f2bd | ||
|
|
6919baf23c | ||
|
|
ddedb215c4 | ||
|
|
3dc5f1e160 | ||
|
|
08d4d817f6 | ||
|
|
e8bdcfbaf2 | ||
|
|
743fb4494e | ||
|
|
0a4bc7fad6 | ||
|
|
49d0b16324 | ||
|
|
de479d6188 | ||
|
|
3fd3e13dc7 | ||
|
|
d7d913d439 | ||
|
|
5c4ae3820b | ||
|
|
38774a20c6 | ||
|
|
9fc58bb4df | ||
|
|
ca936ca42f | ||
|
|
840fb6b647 | ||
|
|
34f54c51e4 | ||
|
|
cda973a54f | ||
|
|
8d77c29d75 | ||
|
|
c80b5d6d78 | ||
|
|
0454926d68 | ||
|
|
40067c514f | ||
|
|
77e5d8f00e | ||
|
|
e33f9c1709 | ||
|
|
31ba3aad85 | ||
|
|
3c591f146e | ||
|
|
35f82ea616 | ||
|
|
60f5bdb069 | ||
|
|
7be9f321a2 | ||
|
|
eee55a92d9 | ||
|
|
00998a8d3e | ||
|
|
1f5d0f1968 | ||
|
|
ec83cf39cd | ||
|
|
7c8487632d | ||
|
|
e6bd9adc03 | ||
|
|
6f0c10dcd7 | ||
|
|
ddb3d1a0dd | ||
|
|
c187e7edc3 | ||
|
|
9735e33e51 | ||
|
|
4eeb22110d | ||
|
|
b190a43e7e | ||
|
|
20b95c425e | ||
|
|
5ba05ff769 | ||
|
|
21398fbf8a | ||
|
|
051f7c9f52 | ||
|
|
0fa7817b2a | ||
|
|
95d5dd3c68 | ||
|
|
139ae36d3e |
@@ -0,0 +1,22 @@
|
||||
# cmd: "cd {PROJECT_PATH}; platformio"
|
||||
cmd: "platformio"
|
||||
name: "Build with error highlighting (dev_ESP8266_4096)"
|
||||
args:
|
||||
- run --environment dev_ESP8266_4096
|
||||
sh: true
|
||||
cwd: "{PROJECT_PATH}"
|
||||
# env:
|
||||
# VARIABLE1: "VALUE1"
|
||||
# VARIABLE2: "VALUE2"
|
||||
errorMatch:
|
||||
- "(?<file>[\\/0-9a-zA-Z\\._]+):(?<line>\\d+):(?<col>\\d+):\\s+error:\\s+(?<message>.+)"
|
||||
|
||||
warningMatch:
|
||||
- "(?<file>[\\/0-9a-zA-Z\\._]+):(?<line>\\d+):(?<col>\\d+):\\s+warning:\\s+(?<message>.+)"
|
||||
# keymap: <keymap string>
|
||||
# atomCommandName: namespace:command
|
||||
# targets:
|
||||
# extraTargetName:
|
||||
# cmd: "<command to execute>"
|
||||
# args:
|
||||
# # (any previous options are viable here except `targets` itself)
|
||||
+11
-7
@@ -15,15 +15,19 @@ Also there are more people on the forum that can help you with support.
|
||||
## Pull requests
|
||||
|
||||
* Make sure your code compiles.
|
||||
|
||||
* Try to create different pull requests for different features/fixes.
|
||||
|
||||
|
||||
* Make sure your code does not have warnings. (Warnings will be treated as errors by our Travis system.)
|
||||
|
||||
* Try to create different pull requests for different features/fixes.
|
||||
|
||||
* Dont combine a lot of different stuff in one huge pull request.
|
||||
|
||||
* The v2.0 branch should get only fixes, new stuff should go into the mega-branch. (We will merge those fixes from v2.0 to mega)
|
||||
|
||||
* Incomplete or unstable plugins should have a PLUGIN_BUILD_DEV #ifdef around them. Also add [DEVELOPMENT] to the name.
|
||||
|
||||
* New plugins that seem to be working correctly should have a PLUGIN_BUILD_TESTING around until they are tested enough.
|
||||
|
||||
* Do not modify any of the variables passed to your PLUGIN_WRITE handler.
|
||||
|
||||
* New plugins that seem to be working correctly should have a PLUGIN_BUILD_TESTING around until they are tested enough. Also add [TESTING] to the name
|
||||
|
||||
* Also see our general guidelines at: https://www.letscontrolit.com/wiki/index.php/ESPEasyDevelopmentGuidelines
|
||||
|
||||
|
||||
|
||||
@@ -1,18 +1,43 @@
|
||||
**NOTE: This is not a support forum! For questions and support go here: https://www.letscontrolit.com/forum/viewforum.php?f=1**
|
||||
<!--- NOTE: This is not a support forum! For questions and support go here: --->
|
||||
<!--- https://www.letscontrolit.com/forum/viewforum.php?f=1 --->
|
||||
<!--- Remove topics that are not applicable to your feature request of issue --->
|
||||
<!--- Remember to have a "to the point" TITLE --->
|
||||
|
||||
### Steps to reproduce
|
||||
How can we trigger this problem?
|
||||
|
||||
Does the problem presist after powering off and on? (just resetting isnt enough sometimes)
|
||||
### Summarize of the problem/feature request
|
||||
<!--- Describe the problem or feature request --->
|
||||
YOUR TEXT GOES HERE
|
||||
|
||||
### Expected behavior
|
||||
Tell us what should happen?
|
||||
<!--- Tell us what should happen? --->
|
||||
YOUR TEXT GOES HERE
|
||||
|
||||
### Actual behavior
|
||||
Tell us what happens instead?
|
||||
<!--- Tell us what happens instead? --->
|
||||
YOUR TEXT GOES HERE
|
||||
|
||||
### Steps to reproduce
|
||||
<!--- How can we trigger this problem? --->
|
||||
1.
|
||||
2.
|
||||
3.
|
||||
|
||||
<!--- Does the problem persists after powering off and on? (just resetting isn't enough sometimes) --->
|
||||
<!--- Please document if you have restarted the unit and if the problem is then gone etc. etc. --->
|
||||
### System configuration
|
||||
|
||||
<!--- Please add as much information and screenshots as possible --->
|
||||
Hardware:
|
||||
|
||||
Software or git version:
|
||||
<!--- You should also provide links to hardware pages etc where we can find more info --->
|
||||
<!--- If you self compile, please state this and PLEASE try to ONLY REPORT ISSUES WITH OFFICIAL BUILDS! --->
|
||||
ESP Easy version:
|
||||
|
||||
<!--- In order to have a better readablity of your issue then you should place screenshots here --->
|
||||
<!--- Simply drag and drop them onto this template, move the text string below the "ESP Easy settings/screenshots" topic --->
|
||||
ESP Easy settings/screenshots:
|
||||
|
||||
### Rules or log data
|
||||
<!--- place your code/rules between the two ``` rows --->
|
||||
<!--- remove if not applicable! --->
|
||||
```
|
||||
|
||||
```
|
||||
|
||||
+13
@@ -1,6 +1,19 @@
|
||||
## OS Specific Hidden Files ####
|
||||
|
||||
# MacOSX Finder *****
|
||||
.DS_Store
|
||||
|
||||
# Fuse FileSystem ***
|
||||
.fuse_hidden*
|
||||
|
||||
|
||||
## PlatformIO ##################
|
||||
.pioenvs
|
||||
.clang_complete
|
||||
.gcc-flags.json
|
||||
.piolibdeps
|
||||
|
||||
## Project #####################
|
||||
lib/readme.txt
|
||||
src/Custom.h
|
||||
test/output_export.cpp
|
||||
|
||||
+8
-3
@@ -25,9 +25,14 @@ install:
|
||||
- pip install -U platformio
|
||||
|
||||
script:
|
||||
- cppcheck --enable=warning src/*.ino -q --force -I src --include=src/ESPEasy.ino --error-exitcode=1
|
||||
- ./memanalyzer.py ~/.platformio/packages/toolchain-xtensa/bin/xtensa-lx106-elf-objdump
|
||||
- platformio run -s
|
||||
# - cppcheck --enable=warning src/*.ino -q --force -I src --include=src/ESPEasy.ino --error-exitcode=1
|
||||
# - ./memanalyzer.py ~/.platformio/packages/toolchain-xtensa/bin/xtensa-lx106-elf-objdump
|
||||
- PLATFORMIO_BUILD_FLAGS="-D CONTINUOUS_INTEGRATION" platformio run
|
||||
|
||||
# patch platformio core libs for PUYA bug (https://github.com/letscontrolit/ESPEasy/issues/650)
|
||||
- cd patches; ./check_puya_patch; cd ..
|
||||
- PLATFORMIO_BUILD_FLAGS="-D CONTINUOUS_INTEGRATION" platformio run -s --environment dev_ESP8266PUYA_1024
|
||||
|
||||
|
||||
before_deploy:
|
||||
- ./before_deploy
|
||||
|
||||
@@ -1,43 +1,39 @@
|
||||
# ESPEasy (mega branch)
|
||||
# ESPEasy (development branch)
|
||||
|
||||
Build status: [](https://travis-ci.org/letscontrolit/ESPEasy)
|
||||
|
||||
Introduction and wiki: https://www.letscontrolit.com/wiki/index.php/ESPEasy#Introduction
|
||||
|
||||
This is the development branch for the next upcoming release (2.0.0). This is also known as ESPEasyMega.
|
||||
**MEGA**
|
||||
:warning:This is the development branch of ESPEasy. All new untested features go into this branch. If you want to do a bugfix, do it on the stable branch, we will merge the fix to the development branch as well.:warning:
|
||||
|
||||
Next stable branch: https://github.com/letscontrolit/ESPEasy/tree/v2.0 (bug fixes only, since oct 2017))
|
||||
|
||||
Check here to learn how to use this branch and help us improving ESPEasy: http://www.letscontrolit.com/wiki/index.php/ESPEasy#Source_code_development
|
||||
|
||||
## Versions
|
||||
|
||||
* v2.0.0-devX: these are the current development releases. use these if you want bleeding edge features, or if you want to help us testing and developing. new release every month.
|
||||
* v2.0.0-betaX: as soon as we think its stable/complete enough for real testing, we will start numbering beta's.
|
||||
* v2.0.0-rcX: release candidates (probably stable)
|
||||
* v2.0.0: This will be the first stable release. After this we will use more standard numbering. Next bugfix release will probably be 2.0.1.
|
||||
## Automated binary releases
|
||||
|
||||
## Firmware binary releases
|
||||
Every night our build-bot will build a new binary release: https://github.com/letscontrolit/ESPEasy/releases
|
||||
|
||||
Binary development releases are here: https://github.com/letscontrolit/ESPEasy/releases
|
||||
The releases are named something like 'mega-20180102' (last number is the build date)
|
||||
|
||||
Depending on your needs, we release different types of files.
|
||||
Depending on your needs, we release different types of files:
|
||||
|
||||
For version 2.0.0-dev9 and higer:
|
||||
|
||||
Firmware name | Hardware | Included plugins |
|
||||
-------------------------------------|-------------------------|-----------------------------|
|
||||
ESPEasy_v2.0.0-dev9_dev_1024.bin | ESP8266 with 1Mb flash | Stable + Test + Development |
|
||||
ESPEasy_v2.0.0-dev9_test_1024.bin | ESP8266 with 1Mb flash | Stable + Test |
|
||||
ESPEasy_v2.0.0-dev9_normal_1024.bin | ESP8266 with 1Mb flash | Stable |
|
||||
ESPEasy_v2.0.0-dev9_dev_4096.bin | ESP8266 with 4Mb flash | Stable + Test + Development |
|
||||
ESPEasy_v2.0.0-dev9_test_4096.bin | ESP8266 with 4Mb flash | Stable + Test |
|
||||
ESPEasy_v2.0.0-dev9_normal_4096.bin | ESP8266 with 4Mb flash | Stable |
|
||||
ESPEasy_v2.0.0-dev9_dev_8285.bin | ESP8285 | Stable + Test + Development |
|
||||
ESPEasy_v2.0.0-dev9_test_8285.bin | ESP8285 | Stable + Test |
|
||||
ESPEasy_v2.0.0-dev9_normal_8285.bin | ESP8285 | Stable |
|
||||
Firmware name | Hardware | Included plugins |
|
||||
----------------------------------------------|-------------------------|-----------------------------|
|
||||
ESPEasy_mega-20180102_normal_ESP8266_1024.bin | ESP8266 with 1Mb flash | Stable |
|
||||
ESPEasy_mega-20180102_test_ESP8266_1024.bin | ESP8266 with 1Mb flash | Stable + Test |
|
||||
ESPEasy_mega-20180102_dev_ESP8266_1024.bin | ESP8266 with 1Mb flash | Stable + Test + Development |
|
||||
ESPEasy_mega-20180102_normal_ESP8266_4096.bin | ESP8266 with 4Mb flash | Stable |
|
||||
ESPEasy_mega-20180102_test_ESP8266_4096.bin | ESP8266 with 4Mb flash | Stable + Test |
|
||||
ESPEasy_mega-20180102_dev_ESP8266_4096.bin | ESP8266 with 4Mb flash | Stable + Test + Development |
|
||||
ESPEasy_mega-20180102_normal_ESP8285_1024.bin | ESP8285 with 1Mb flash | Stable |
|
||||
ESPEasy_mega-20180102_test_ESP8285_1024.bin | ESP8285 with 1Mb flash | Stable + Test |
|
||||
ESPEasy_mega-20180102_dev_ESP8285_1024.bin | ESP8285 with 1Mb flash | Stable + Test + Development |
|
||||
|
||||
## More info
|
||||
|
||||
Details and discussion are on the Experimental forum: https://www.letscontrolit.com/forum/viewforum.php?f=18
|
||||
|
||||
We're also on IRC: #ESPEasy @freenode
|
||||
|
||||
|
||||
+26
-12
@@ -1,21 +1,32 @@
|
||||
#!/bin/bash
|
||||
|
||||
VERSION=$(git describe)
|
||||
echo "Creating release archives for $VERSION ..."
|
||||
#binaries
|
||||
# cp .pioenvs/mini_512/firmware.bin dist/"ESPEasy_$VERSION""_mini_512.bin"
|
||||
|
||||
cp .pioenvs/normal_1024/firmware.bin dist/"ESPEasy_$VERSION""_normal_1024.bin"
|
||||
cp .pioenvs/normal_4096/firmware.bin dist/"ESPEasy_$VERSION""_normal_4096.bin"
|
||||
cp .pioenvs/normal_8285/firmware.bin dist/"ESPEasy_$VERSION""_normal_8285.bin"
|
||||
#Naming convention:
|
||||
# ESP_Easy_[github version]_[plugin set]_[chip type]_[flash memory].bin
|
||||
|
||||
cp .pioenvs/test_1024/firmware.bin dist/"ESPEasy_$VERSION""_test_1024.bin"
|
||||
cp .pioenvs/test_4096/firmware.bin dist/"ESPEasy_$VERSION""_test_4096.bin"
|
||||
cp .pioenvs/test_8285/firmware.bin dist/"ESPEasy_$VERSION""_test_8285.bin"
|
||||
|
||||
cp .pioenvs/dev_1024/firmware.bin dist/"ESPEasy_$VERSION""_dev_1024.bin"
|
||||
cp .pioenvs/dev_4096/firmware.bin dist/"ESPEasy_$VERSION""_dev_4096.bin"
|
||||
cp .pioenvs/dev_8285/firmware.bin dist/"ESPEasy_$VERSION""_dev_8285.bin"
|
||||
for ENV in \
|
||||
normal_ESP8266_1024 \
|
||||
normal_ESP8266_4096 \
|
||||
normal_ESP8285_1024 \
|
||||
test_ESP8266_1024\
|
||||
test_ESP8266_4096\
|
||||
test_ESP8266_4096_VCC\
|
||||
test_ESP8285_1024\
|
||||
dev_ESP8266_1024\
|
||||
dev_ESP8266_4096\
|
||||
dev_ESP8285_1024\
|
||||
dev_ESP8266PUYA_1024\
|
||||
dev_ESP8266PUYA_1024_VCC;\
|
||||
do
|
||||
echo
|
||||
echo "### Deploying environment $ENV for version $VERSION"
|
||||
BIN=.pioenvs/$ENV/firmware.bin
|
||||
python2 crc2.py $BIN
|
||||
cp $BIN dist/"ESP_Easy_$VERSION""_$ENV.bin"
|
||||
done
|
||||
|
||||
|
||||
#create a source structure that is the same as the original ESPEasy project (and works with the howto on the wiki)
|
||||
rm -rf dist/Source 2>/dev/null
|
||||
@@ -25,4 +36,7 @@ cp -r src dist/Source/
|
||||
cp platformio.ini dist/Source/
|
||||
|
||||
cd dist
|
||||
|
||||
echo
|
||||
echo "### Creating zip archive"
|
||||
zip ../ESPEasy_$VERSION.zip -r .
|
||||
|
||||
@@ -0,0 +1,116 @@
|
||||
|
||||
import sys
|
||||
import binascii
|
||||
import struct
|
||||
import md5
|
||||
import os
|
||||
MD5DUMMY = "MD5_MD5_MD5_MD5_BoundariesOfTheSegmentsGoHere..." #48 chars
|
||||
FILENAMEDUMMY = "ThisIsTheDummyPlaceHolderForTheBinaryFilename..." #48 chars
|
||||
|
||||
MemorySegmentStart,MemorySegmentEnd,MemoryContent=[],[],[]
|
||||
|
||||
##################################################################
|
||||
# this subroutine shows the segments of a part
|
||||
##################################################################
|
||||
def showSegments (fileContent,offset):
|
||||
global MemorySegmentStart, MemorySegmentEnd, MemoryContent
|
||||
header = struct.unpack("ii", fileContent[offset:offset+8])
|
||||
herestr =""
|
||||
herestr2 =""
|
||||
MemorySegmentStart.append(struct.pack("I",header[0]))
|
||||
MemorySegmentEnd.append(struct.pack("I",header[0]+header[1]))
|
||||
MemoryContent.append(fileContent[offset+8:offset+8+header[1]])
|
||||
if fileContent.find( MD5DUMMY, offset+8, offset+8+header[1]) >0 :
|
||||
herestr= " <-- CRC is here."
|
||||
if fileContent.find( FILENAMEDUMMY, offset+8, offset+8+header[1]) >0 :
|
||||
herestr2= " <-- filename is here."
|
||||
print ("SEGMENT "+ str(len(MemorySegmentStart)-1)+ ": memory position: " + hex(header[0])+" to " + hex(header[0]+header[1]) + " length: " + hex(header[1])+herestr+herestr2)
|
||||
#print ("first byte positoin in file: " + hex( offset+8))
|
||||
#print ("last byte postion in file: " + hex(offset+8+header[1]-1))
|
||||
return (8+offset+ header[1]); # return start of next segment
|
||||
|
||||
##################################################################
|
||||
# this subroutine shows the parts of a binary file
|
||||
##################################################################
|
||||
def showParts(fileContent, offset):
|
||||
header = struct.unpack("BBBBi", fileContent[offset:offset+8])
|
||||
print ('\n\nBINARY PART\nSegments: ') + (hex(header[1]))
|
||||
nextpos =offset+8
|
||||
for x in range (0,header[1]):
|
||||
nextpos = showSegments(fileContent,nextpos)
|
||||
nextSegmentOffset = (fileContent.find("\xe9", nextpos))
|
||||
return nextSegmentOffset
|
||||
|
||||
##################################################################
|
||||
# MAIN
|
||||
##################################################################
|
||||
|
||||
#if len(sys.argv) !=2 :
|
||||
# print ("please give a filename")
|
||||
# k=input("press close to exit")
|
||||
# sys.exit(1)
|
||||
FileName = sys.argv[1]#"C:/ArduinoPortable/sketchbooks/build/sketch_jan15a.ino.bin"
|
||||
#FileName = "C:/ArduinoPortable/sketchbooks/build/sketch_jan15a.ino.bin"
|
||||
print( "\n\nReplacing dummy MD5 checksum in .bin file")
|
||||
|
||||
|
||||
|
||||
with open(FileName, mode='rb') as file: # b is important -> binary
|
||||
nextpos =0;
|
||||
fileContent = file.read()
|
||||
while nextpos >=0:
|
||||
nextpos = showParts(fileContent,nextpos)
|
||||
|
||||
startArray,endArray,hashString = "","",""
|
||||
includeStr = "hash includes segments:"
|
||||
# memory sections:
|
||||
# 0: bootloader (not readable)
|
||||
# 1: program memory (SPI flash)
|
||||
# 2: unknown but stable
|
||||
# 3: RAM (initialized by bin file. Can be read but changes as you go :-( )
|
||||
# 4: RAM
|
||||
|
||||
for i in (1,2 ): # use only stable segments, must be 4 in total. We use 2.
|
||||
startArray =startArray + MemorySegmentStart[i]
|
||||
endArray = endArray + MemorySegmentEnd[i]
|
||||
hashString =hashString + MemoryContent[i]
|
||||
with open(FileName+str(i), mode='wb') as file: # b is important -> binary
|
||||
file.write(MemoryContent[i])
|
||||
includeStr = includeStr +" "+ str(i)
|
||||
print (includeStr)
|
||||
# IMPORTANT: pad array with zeros if you use only 3 segments (see above)
|
||||
while len(startArray) < 16 :
|
||||
startArray =startArray + struct.pack("I",0)
|
||||
endArray = endArray + struct.pack("I",0)
|
||||
# debug print (binascii.hexlify(startArray))
|
||||
# debug print (binascii.hexlify(endArray))
|
||||
if (len(endArray) + len (startArray)) != 32 :
|
||||
print("ERROR: please make sure you add / remove padding if you change the semgents.")
|
||||
|
||||
BinaryFileName = "";
|
||||
if fileContent.find( FILENAMEDUMMY) < 0:
|
||||
print("ERROR: FILENAMEDUMMY dummy not found in binary")
|
||||
else:
|
||||
BinaryFileName=os.path.basename(FileName) +"\0"
|
||||
if len(BinaryFileName) >48: # check that filename is <48 chars
|
||||
BinaryFileName=BinaryFileName[0:48] # truncate if necessary. 49th char in ESP is zero already
|
||||
else:
|
||||
BinaryFileName= BinaryFileName.ljust(48,'\0'); # pad with zeros.
|
||||
|
||||
|
||||
if fileContent.find( MD5DUMMY) < 0:
|
||||
print("ERROR: MD5 dummy not found in binary")
|
||||
else:
|
||||
hashString=hashString.replace (MD5DUMMY,"",1)
|
||||
m = md5.new()
|
||||
m.update (hashString) #use segment 1
|
||||
md5hash = m.digest()
|
||||
print("MD5 hash: "+ m.hexdigest())
|
||||
print("\nwriting output file:\n" + FileName)
|
||||
|
||||
fileContent=fileContent.replace(MD5DUMMY,md5hash+startArray+endArray)
|
||||
fileContent=fileContent.replace(FILENAMEDUMMY,BinaryFileName)
|
||||
|
||||
with open(FileName, mode='wb') as file: # b is important -> binary
|
||||
file.write(fileContent)
|
||||
#k=input("press close to exit")
|
||||
Vendored
+1874
File diff suppressed because it is too large
Load Diff
Vendored
BIN
Binary file not shown.
@@ -1,16 +1,16 @@
|
||||
/***************************************************
|
||||
/***************************************************
|
||||
This is a library for the MPR121 I2C 12-chan Capacitive Sensor
|
||||
|
||||
Designed specifically to work with the MPR121 sensor from Adafruit
|
||||
----> https://www.adafruit.com/products/1982
|
||||
|
||||
These sensors use I2C to communicate, 2+ pins are required to
|
||||
These sensors use I2C to communicate, 2+ pins are required to
|
||||
interface
|
||||
Adafruit invests time and resources providing this open source code,
|
||||
please support Adafruit and open-source hardware by purchasing
|
||||
Adafruit invests time and resources providing this open source code,
|
||||
please support Adafruit and open-source hardware by purchasing
|
||||
products from Adafruit!
|
||||
|
||||
Written by Limor Fried/Ladyada for Adafruit Industries.
|
||||
Written by Limor Fried/Ladyada for Adafruit Industries.
|
||||
BSD license, all text above must be included in any redistribution
|
||||
****************************************************/
|
||||
|
||||
@@ -21,26 +21,26 @@ Adafruit_MPR121::Adafruit_MPR121() {
|
||||
|
||||
boolean Adafruit_MPR121::begin(uint8_t i2caddr) {
|
||||
Wire.begin();
|
||||
|
||||
|
||||
_i2caddr = i2caddr;
|
||||
|
||||
// soft reset
|
||||
writeRegister(MPR121_SOFTRESET, 0x63);
|
||||
delay(1);
|
||||
for (uint8_t i=0; i<0x7F; i++) {
|
||||
// Serial.print("$"); Serial.print(i, HEX);
|
||||
// Serial.print("$"); Serial.print(i, HEX);
|
||||
// Serial.print(": 0x"); Serial.println(readRegister8(i));
|
||||
}
|
||||
|
||||
|
||||
|
||||
writeRegister(MPR121_ECR, 0x0);
|
||||
|
||||
uint8_t c = readRegister8(MPR121_CONFIG2);
|
||||
|
||||
|
||||
if (c != 0x24) return false;
|
||||
|
||||
|
||||
setThreshholds(12, 6);
|
||||
setThresholds(12, 6);
|
||||
writeRegister(MPR121_MHDR, 0x01);
|
||||
writeRegister(MPR121_NHDR, 0x01);
|
||||
writeRegister(MPR121_NCLR, 0x0E);
|
||||
|
||||
@@ -1,14 +1,14 @@
|
||||
/******************************************************************
|
||||
This is the library for the Adafruit Motor Shield V2 for Arduino.
|
||||
This is the library for the Adafruit Motor Shield V2 for Arduino.
|
||||
It supports DC motors & Stepper motors with microstepping as well
|
||||
as stacking-support. It is *not* compatible with the V1 library!
|
||||
|
||||
It will only work with https://www.adafruit.com/products/1483
|
||||
|
||||
|
||||
Adafruit invests time and resources providing this open
|
||||
source code, please support Adafruit and open-source hardware
|
||||
by purchasing products from Adafruit!
|
||||
|
||||
|
||||
Written by Limor Fried/Ladyada for Adafruit Industries.
|
||||
BSD license, check license.txt for more information.
|
||||
All text above must be included in any redistribution.
|
||||
@@ -48,14 +48,14 @@ void Adafruit_MotorShield::begin(uint16_t freq) {
|
||||
_pwm.begin();
|
||||
_freq = freq;
|
||||
_pwm.setPWMFreq(_freq); // This is the maximum PWM frequency
|
||||
for (uint8_t i=0; i<16; i++)
|
||||
for (uint8_t i=0; i<16; i++)
|
||||
_pwm.setPWM(i, 0, 0);
|
||||
}
|
||||
|
||||
void Adafruit_MotorShield::setPWM(uint8_t pin, uint16_t value) {
|
||||
if (value > 4095) {
|
||||
_pwm.setPWM(pin, 4096, 0);
|
||||
} else
|
||||
} else
|
||||
_pwm.setPWM(pin, 0, value);
|
||||
}
|
||||
void Adafruit_MotorShield::setPin(uint8_t pin, boolean value) {
|
||||
@@ -170,7 +170,7 @@ uint16_t steps, Adafruit_MotorShield controller) {
|
||||
if (steppernum == 1) {
|
||||
latch_state &= ~_BV(MOTOR1_A) & ~_BV(MOTOR1_B) &
|
||||
~_BV(MOTOR2_A) & ~_BV(MOTOR2_B); // all motor pins to 0
|
||||
|
||||
|
||||
// enable both H bridges
|
||||
pinMode(11, OUTPUT);
|
||||
pinMode(3, OUTPUT);
|
||||
@@ -282,7 +282,7 @@ uint8_t Adafruit_StepperMotor::onestep(uint8_t dir, uint8_t style) {
|
||||
} else {
|
||||
currentstep -= MICROSTEPS/2;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (style == MICROSTEP) {
|
||||
if (dir == FORWARD) {
|
||||
@@ -316,12 +316,12 @@ uint8_t Adafruit_StepperMotor::onestep(uint8_t dir, uint8_t style) {
|
||||
|
||||
#ifdef MOTORDEBUG
|
||||
Serial.print("current step: "); Serial.println(currentstep, DEC);
|
||||
Serial.print(" pwmA = "); Serial.print(ocra, DEC);
|
||||
Serial.print(" pwmB = "); Serial.println(ocrb, DEC);
|
||||
Serial.print(" pwmA = "); Serial.print(ocra, DEC);
|
||||
Serial.print(" pwmB = "); Serial.println(ocrb, DEC);
|
||||
#endif
|
||||
MC->setPWM(PWMApin, ocra*16);
|
||||
MC->setPWM(PWMBpin, ocrb*16);
|
||||
|
||||
|
||||
|
||||
// release all
|
||||
uint8_t latch_state = 0; // all motor pins to 0
|
||||
@@ -352,7 +352,7 @@ uint8_t Adafruit_StepperMotor::onestep(uint8_t dir, uint8_t style) {
|
||||
break;
|
||||
case 4:
|
||||
latch_state |= 0x4; // energize coil 3 only
|
||||
break;
|
||||
break;
|
||||
case 5:
|
||||
latch_state |= 0xC; // energize coil 3+4
|
||||
break;
|
||||
@@ -395,4 +395,3 @@ uint8_t Adafruit_StepperMotor::onestep(uint8_t dir, uint8_t style) {
|
||||
|
||||
return currentstep;
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,154 @@
|
||||
/*
|
||||
* Copyright (C) 2008 The Android Open Source Project
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software< /span>
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
/* Update by K. Townsend (Adafruit Industries) for lighter typedefs, and
|
||||
* extended sensor support to include color, voltage and current */
|
||||
|
||||
#ifndef _ADAFRUIT_SENSOR_H
|
||||
#define _ADAFRUIT_SENSOR_H
|
||||
|
||||
#if ARDUINO >= 100
|
||||
#include "Arduino.h"
|
||||
#include "Print.h"
|
||||
#else
|
||||
#include "WProgram.h"
|
||||
#endif
|
||||
|
||||
/* Intentionally modeled after sensors.h in the Android API:
|
||||
* https://github.com/android/platform_hardware_libhardware/blob/master/include/hardware/sensors.h */
|
||||
|
||||
/* Constants */
|
||||
#define SENSORS_GRAVITY_EARTH (9.80665F) /**< Earth's gravity in m/s^2 */
|
||||
#define SENSORS_GRAVITY_MOON (1.6F) /**< The moon's gravity in m/s^2 */
|
||||
#define SENSORS_GRAVITY_SUN (275.0F) /**< The sun's gravity in m/s^2 */
|
||||
#define SENSORS_GRAVITY_STANDARD (SENSORS_GRAVITY_EARTH)
|
||||
#define SENSORS_MAGFIELD_EARTH_MAX (60.0F) /**< Maximum magnetic field on Earth's surface */
|
||||
#define SENSORS_MAGFIELD_EARTH_MIN (30.0F) /**< Minimum magnetic field on Earth's surface */
|
||||
#define SENSORS_PRESSURE_SEALEVELHPA (1013.25F) /**< Average sea level pressure is 1013.25 hPa */
|
||||
#define SENSORS_DPS_TO_RADS (0.017453293F) /**< Degrees/s to rad/s multiplier */
|
||||
#define SENSORS_GAUSS_TO_MICROTESLA (100) /**< Gauss to micro-Tesla multiplier */
|
||||
|
||||
/** Sensor types */
|
||||
typedef enum
|
||||
{
|
||||
SENSOR_TYPE_ACCELEROMETER = (1), /**< Gravity + linear acceleration */
|
||||
SENSOR_TYPE_MAGNETIC_FIELD = (2),
|
||||
SENSOR_TYPE_ORIENTATION = (3),
|
||||
SENSOR_TYPE_GYROSCOPE = (4),
|
||||
SENSOR_TYPE_LIGHT = (5),
|
||||
SENSOR_TYPE_PRESSURE = (6),
|
||||
SENSOR_TYPE_PROXIMITY = (8),
|
||||
SENSOR_TYPE_GRAVITY = (9),
|
||||
SENSOR_TYPE_LINEAR_ACCELERATION = (10), /**< Acceleration not including gravity */
|
||||
SENSOR_TYPE_ROTATION_VECTOR = (11),
|
||||
SENSOR_TYPE_RELATIVE_HUMIDITY = (12),
|
||||
SENSOR_TYPE_AMBIENT_TEMPERATURE = (13),
|
||||
SENSOR_TYPE_VOLTAGE = (15),
|
||||
SENSOR_TYPE_CURRENT = (16),
|
||||
SENSOR_TYPE_COLOR = (17)
|
||||
} sensors_type_t;
|
||||
|
||||
/** struct sensors_vec_s is used to return a vector in a common format. */
|
||||
typedef struct {
|
||||
union {
|
||||
float v[3];
|
||||
struct {
|
||||
float x;
|
||||
float y;
|
||||
float z;
|
||||
};
|
||||
/* Orientation sensors */
|
||||
struct {
|
||||
float roll; /**< Rotation around the longitudinal axis (the plane body, 'X axis'). Roll is positive and increasing when moving downward. -90°<=roll<=90° */
|
||||
float pitch; /**< Rotation around the lateral axis (the wing span, 'Y axis'). Pitch is positive and increasing when moving upwards. -180°<=pitch<=180°) */
|
||||
float heading; /**< Angle between the longitudinal axis (the plane body) and magnetic north, measured clockwise when viewing from the top of the device. 0-359° */
|
||||
};
|
||||
};
|
||||
int8_t status;
|
||||
uint8_t reserved[3];
|
||||
} sensors_vec_t;
|
||||
|
||||
/** struct sensors_color_s is used to return color data in a common format. */
|
||||
typedef struct {
|
||||
union {
|
||||
float c[3];
|
||||
/* RGB color space */
|
||||
struct {
|
||||
float r; /**< Red component */
|
||||
float g; /**< Green component */
|
||||
float b; /**< Blue component */
|
||||
};
|
||||
};
|
||||
uint32_t rgba; /**< 24-bit RGBA value */
|
||||
} sensors_color_t;
|
||||
|
||||
/* Sensor event (36 bytes) */
|
||||
/** struct sensor_event_s is used to provide a single sensor event in a common format. */
|
||||
typedef struct
|
||||
{
|
||||
int32_t version; /**< must be sizeof(struct sensors_event_t) */
|
||||
int32_t sensor_id; /**< unique sensor identifier */
|
||||
int32_t type; /**< sensor type */
|
||||
int32_t reserved0; /**< reserved */
|
||||
int32_t timestamp; /**< time is in milliseconds */
|
||||
union
|
||||
{
|
||||
float data[4];
|
||||
sensors_vec_t acceleration; /**< acceleration values are in meter per second per second (m/s^2) */
|
||||
sensors_vec_t magnetic; /**< magnetic vector values are in micro-Tesla (uT) */
|
||||
sensors_vec_t orientation; /**< orientation values are in degrees */
|
||||
sensors_vec_t gyro; /**< gyroscope values are in rad/s */
|
||||
float temperature; /**< temperature is in degrees centigrade (Celsius) */
|
||||
float distance; /**< distance in centimeters */
|
||||
float light; /**< light in SI lux units */
|
||||
float pressure; /**< pressure in hectopascal (hPa) */
|
||||
float relative_humidity; /**< relative humidity in percent */
|
||||
float current; /**< current in milliamps (mA) */
|
||||
float voltage; /**< voltage in volts (V) */
|
||||
sensors_color_t color; /**< color in RGB component values */
|
||||
};
|
||||
} sensors_event_t;
|
||||
|
||||
/* Sensor details (40 bytes) */
|
||||
/** struct sensor_s is used to describe basic information about a specific sensor. */
|
||||
typedef struct
|
||||
{
|
||||
char name[12]; /**< sensor name */
|
||||
int32_t version; /**< version of the hardware + driver */
|
||||
int32_t sensor_id; /**< unique sensor identifier */
|
||||
int32_t type; /**< this sensor's type (ex. SENSOR_TYPE_LIGHT) */
|
||||
float max_value; /**< maximum value of this sensor's value in SI units */
|
||||
float min_value; /**< minimum value of this sensor's value in SI units */
|
||||
float resolution; /**< smallest difference between two values reported by this sensor */
|
||||
int32_t min_delay; /**< min delay in microseconds between events. zero = not a constant rate */
|
||||
} sensor_t;
|
||||
|
||||
class Adafruit_Sensor {
|
||||
public:
|
||||
// Constructor(s)
|
||||
Adafruit_Sensor() {}
|
||||
virtual ~Adafruit_Sensor() {}
|
||||
|
||||
// These must be defined by the subclass
|
||||
virtual void enableAutoRange(bool enabled) {};
|
||||
virtual bool getEvent(sensors_event_t*) = 0;
|
||||
virtual void getSensor(sensor_t*) = 0;
|
||||
|
||||
private:
|
||||
bool _autoRange;
|
||||
};
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,221 @@
|
||||
# Adafruit Unified Sensor Driver #
|
||||
|
||||
Many small embedded systems exist to collect data from sensors, analyse the data, and either take an appropriate action or send that sensor data to another system for processing.
|
||||
|
||||
One of the many challenges of embedded systems design is the fact that parts you used today may be out of production tomorrow, or system requirements may change and you may need to choose a different sensor down the road.
|
||||
|
||||
Creating new drivers is a relatively easy task, but integrating them into existing systems is both error prone and time consuming since sensors rarely use the exact same units of measurement.
|
||||
|
||||
By reducing all data to a single **sensors\_event\_t** 'type' and settling on specific, **standardised SI units** for each sensor family the same sensor types return values that are comparable with any other similar sensor. This enables you to switch sensor models with very little impact on the rest of the system, which can help mitigate some of the risks and problems of sensor availability and code reuse.
|
||||
|
||||
The unified sensor abstraction layer is also useful for data-logging and data-transmission since you only have one well-known type to log or transmit over the air or wire.
|
||||
|
||||
## Unified Sensor Drivers ##
|
||||
|
||||
The following drivers are based on the Adafruit Unified Sensor Driver:
|
||||
|
||||
**Accelerometers**
|
||||
- [Adafruit\_ADXL345](https://github.com/adafruit/Adafruit_ADXL345)
|
||||
- [Adafruit\_LSM303DLHC](https://github.com/adafruit/Adafruit_LSM303DLHC)
|
||||
- [Adafruit\_MMA8451\_Library](https://github.com/adafruit/Adafruit_MMA8451_Library)
|
||||
|
||||
**Gyroscope**
|
||||
- [Adafruit\_L3GD20\_U](https://github.com/adafruit/Adafruit_L3GD20_U)
|
||||
|
||||
**Light**
|
||||
- [Adafruit\_TSL2561](https://github.com/adafruit/Adafruit_TSL2561)
|
||||
- [Adafruit\_TSL2591\_Library](https://github.com/adafruit/Adafruit_TSL2591_Library)
|
||||
|
||||
**Magnetometers**
|
||||
- [Adafruit\_LSM303DLHC](https://github.com/adafruit/Adafruit_LSM303DLHC)
|
||||
- [Adafruit\_HMC5883\_Unified](https://github.com/adafruit/Adafruit_HMC5883_Unified)
|
||||
|
||||
**Barometric Pressure**
|
||||
- [Adafruit\_BMP085\_Unified](https://github.com/adafruit/Adafruit_BMP085_Unified)
|
||||
- [Adafruit\_BMP183\_Unified\_Library](https://github.com/adafruit/Adafruit_BMP183_Unified_Library)
|
||||
|
||||
**Humidity & Temperature**
|
||||
- [DHT-sensor-library](https://github.com/adafruit/DHT-sensor-library)
|
||||
|
||||
**Orientation**
|
||||
- [Adafruit_BNO055](https://github.com/adafruit/Adafruit_BNO055)
|
||||
|
||||
## How Does it Work? ##
|
||||
|
||||
Any driver that supports the Adafruit unified sensor abstraction layer will implement the Adafruit\_Sensor base class. There are two main typedefs and one enum defined in Adafruit_Sensor.h that are used to 'abstract' away the sensor details and values:
|
||||
|
||||
**Sensor Types (sensors\_type\_t)**
|
||||
|
||||
These pre-defined sensor types are used to properly handle the two related typedefs below, and allows us determine what types of units the sensor uses, etc.
|
||||
|
||||
```
|
||||
/** Sensor types */
|
||||
typedef enum
|
||||
{
|
||||
SENSOR_TYPE_ACCELEROMETER = (1),
|
||||
SENSOR_TYPE_MAGNETIC_FIELD = (2),
|
||||
SENSOR_TYPE_ORIENTATION = (3),
|
||||
SENSOR_TYPE_GYROSCOPE = (4),
|
||||
SENSOR_TYPE_LIGHT = (5),
|
||||
SENSOR_TYPE_PRESSURE = (6),
|
||||
SENSOR_TYPE_PROXIMITY = (8),
|
||||
SENSOR_TYPE_GRAVITY = (9),
|
||||
SENSOR_TYPE_LINEAR_ACCELERATION = (10),
|
||||
SENSOR_TYPE_ROTATION_VECTOR = (11),
|
||||
SENSOR_TYPE_RELATIVE_HUMIDITY = (12),
|
||||
SENSOR_TYPE_AMBIENT_TEMPERATURE = (13),
|
||||
SENSOR_TYPE_VOLTAGE = (15),
|
||||
SENSOR_TYPE_CURRENT = (16),
|
||||
SENSOR_TYPE_COLOR = (17)
|
||||
} sensors_type_t;
|
||||
```
|
||||
|
||||
**Sensor Details (sensor\_t)**
|
||||
|
||||
This typedef describes the specific capabilities of this sensor, and allows us to know what sensor we are using beneath the abstraction layer.
|
||||
|
||||
```
|
||||
/* Sensor details (40 bytes) */
|
||||
/** struct sensor_s is used to describe basic information about a specific sensor. */
|
||||
typedef struct
|
||||
{
|
||||
char name[12];
|
||||
int32_t version;
|
||||
int32_t sensor_id;
|
||||
int32_t type;
|
||||
float max_value;
|
||||
float min_value;
|
||||
float resolution;
|
||||
int32_t min_delay;
|
||||
} sensor_t;
|
||||
```
|
||||
|
||||
The individual fields are intended to be used as follows:
|
||||
|
||||
- **name**: The sensor name or ID, up to a maximum of twelve characters (ex. "MPL115A2")
|
||||
- **version**: The version of the sensor HW and the driver to allow us to differentiate versions of the board or driver
|
||||
- **sensor\_id**: A unique sensor identifier that is used to differentiate this specific sensor instance from any others that are present on the system or in the sensor network
|
||||
- **type**: The sensor type, based on **sensors\_type\_t** in sensors.h
|
||||
- **max\_value**: The maximum value that this sensor can return (in the appropriate SI unit)
|
||||
- **min\_value**: The minimum value that this sensor can return (in the appropriate SI unit)
|
||||
- **resolution**: The smallest difference between two values that this sensor can report (in the appropriate SI unit)
|
||||
- **min\_delay**: The minimum delay in microseconds between two sensor events, or '0' if there is no constant sensor rate
|
||||
|
||||
**Sensor Data/Events (sensors\_event\_t)**
|
||||
|
||||
This typedef is used to return sensor data from any sensor supported by the abstraction layer, using standard SI units and scales.
|
||||
|
||||
```
|
||||
/* Sensor event (36 bytes) */
|
||||
/** struct sensor_event_s is used to provide a single sensor event in a common format. */
|
||||
typedef struct
|
||||
{
|
||||
int32_t version;
|
||||
int32_t sensor_id;
|
||||
int32_t type;
|
||||
int32_t reserved0;
|
||||
int32_t timestamp;
|
||||
union
|
||||
{
|
||||
float data[4];
|
||||
sensors_vec_t acceleration;
|
||||
sensors_vec_t magnetic;
|
||||
sensors_vec_t orientation;
|
||||
sensors_vec_t gyro;
|
||||
float temperature;
|
||||
float distance;
|
||||
float light;
|
||||
float pressure;
|
||||
float relative_humidity;
|
||||
float current;
|
||||
float voltage;
|
||||
sensors_color_t color;
|
||||
};
|
||||
} sensors_event_t;
|
||||
```
|
||||
It includes the following fields:
|
||||
|
||||
- **version**: Contain 'sizeof(sensors\_event\_t)' to identify which version of the API we're using in case this changes in the future
|
||||
- **sensor\_id**: A unique sensor identifier that is used to differentiate this specific sensor instance from any others that are present on the system or in the sensor network (must match the sensor\_id value in the corresponding sensor\_t enum above!)
|
||||
- **type**: the sensor type, based on **sensors\_type\_t** in sensors.h
|
||||
- **timestamp**: time in milliseconds when the sensor value was read
|
||||
- **data[4]**: An array of four 32-bit values that allows us to encapsulate any type of sensor data via a simple union (further described below)
|
||||
|
||||
**Required Functions**
|
||||
|
||||
In addition to the two standard types and the sensor type enum, all drivers based on Adafruit_Sensor must also implement the following two functions:
|
||||
|
||||
```
|
||||
bool getEvent(sensors_event_t*);
|
||||
```
|
||||
Calling this function will populate the supplied sensors\_event\_t reference with the latest available sensor data. You should call this function as often as you want to update your data.
|
||||
|
||||
```
|
||||
void getSensor(sensor_t*);
|
||||
```
|
||||
Calling this function will provide some basic information about the sensor (the sensor name, driver version, min and max values, etc.
|
||||
|
||||
**Standardised SI values for sensors\_event\_t**
|
||||
|
||||
A key part of the abstraction layer is the standardisation of values on SI units of a particular scale, which is accomplished via the data[4] union in sensors\_event\_t above. This 16 byte union includes fields for each main sensor type, and uses the following SI units and scales:
|
||||
|
||||
- **acceleration**: values are in **meter per second per second** (m/s^2)
|
||||
- **magnetic**: values are in **micro-Tesla** (uT)
|
||||
- **orientation**: values are in **degrees**
|
||||
- **gyro**: values are in **rad/s**
|
||||
- **temperature**: values in **degrees centigrade** (Celsius)
|
||||
- **distance**: values are in **centimeters**
|
||||
- **light**: values are in **SI lux** units
|
||||
- **pressure**: values are in **hectopascal** (hPa)
|
||||
- **relative\_humidity**: values are in **percent**
|
||||
- **current**: values are in **milliamps** (mA)
|
||||
- **voltage**: values are in **volts** (V)
|
||||
- **color**: values are in 0..1.0 RGB channel luminosity and 32-bit RGBA format
|
||||
|
||||
## The Unified Driver Abstraction Layer in Practice ##
|
||||
|
||||
Using the unified sensor abstraction layer is relatively easy once a compliant driver has been created.
|
||||
|
||||
Every compliant sensor can now be read using a single, well-known 'type' (sensors\_event\_t), and there is a standardised way of interrogating a sensor about its specific capabilities (via sensor\_t).
|
||||
|
||||
An example of reading the [TSL2561](https://github.com/adafruit/Adafruit_TSL2561) light sensor can be seen below:
|
||||
|
||||
```
|
||||
Adafruit_TSL2561 tsl = Adafruit_TSL2561(TSL2561_ADDR_FLOAT, 12345);
|
||||
...
|
||||
/* Get a new sensor event */
|
||||
sensors_event_t event;
|
||||
tsl.getEvent(&event);
|
||||
|
||||
/* Display the results (light is measured in lux) */
|
||||
if (event.light)
|
||||
{
|
||||
Serial.print(event.light); Serial.println(" lux");
|
||||
}
|
||||
else
|
||||
{
|
||||
/* If event.light = 0 lux the sensor is probably saturated
|
||||
and no reliable data could be generated! */
|
||||
Serial.println("Sensor overload");
|
||||
}
|
||||
```
|
||||
|
||||
Similarly, we can get the basic technical capabilities of this sensor with the following code:
|
||||
|
||||
```
|
||||
sensor_t sensor;
|
||||
|
||||
sensor_t sensor;
|
||||
tsl.getSensor(&sensor);
|
||||
|
||||
/* Display the sensor details */
|
||||
Serial.println("------------------------------------");
|
||||
Serial.print ("Sensor: "); Serial.println(sensor.name);
|
||||
Serial.print ("Driver Ver: "); Serial.println(sensor.version);
|
||||
Serial.print ("Unique ID: "); Serial.println(sensor.sensor_id);
|
||||
Serial.print ("Max Value: "); Serial.print(sensor.max_value); Serial.println(" lux");
|
||||
Serial.print ("Min Value: "); Serial.print(sensor.min_value); Serial.println(" lux");
|
||||
Serial.print ("Resolution: "); Serial.print(sensor.resolution); Serial.println(" lux");
|
||||
Serial.println("------------------------------------");
|
||||
Serial.println("");
|
||||
```
|
||||
@@ -0,0 +1,9 @@
|
||||
name=Adafruit Unified Sensor
|
||||
version=1.0.2
|
||||
author=Adafruit <info@adafruit.com>
|
||||
maintainer=Adafruit <info@adafruit.com>
|
||||
sentence=Required for all Adafruit Unified Sensor based libraries.
|
||||
paragraph=A unified sensor abstraction layer used by many Adafruit sensor libraries.
|
||||
category=Sensors
|
||||
url=https://github.com/adafruit/Adafruit_Sensor
|
||||
architectures=*
|
||||
+46
@@ -0,0 +1,46 @@
|
||||
Thank you for opening an issue on an Adafruit Arduino library repository. To
|
||||
improve the speed of resolution please review the following guidelines and
|
||||
common troubleshooting steps below before creating the issue:
|
||||
|
||||
- **Do not use GitHub issues for troubleshooting projects and issues.** Instead use
|
||||
the forums at http://forums.adafruit.com to ask questions and troubleshoot why
|
||||
something isn't working as expected. In many cases the problem is a common issue
|
||||
that you will more quickly receive help from the forum community. GitHub issues
|
||||
are meant for known defects in the code. If you don't know if there is a defect
|
||||
in the code then start with troubleshooting on the forum first.
|
||||
|
||||
- **If following a tutorial or guide be sure you didn't miss a step.** Carefully
|
||||
check all of the steps and commands to run have been followed. Consult the
|
||||
forum if you're unsure or have questions about steps in a guide/tutorial.
|
||||
|
||||
- **For Arduino projects check these very common issues to ensure they don't apply**:
|
||||
|
||||
- For uploading sketches or communicating with the board make sure you're using
|
||||
a **USB data cable** and **not** a **USB charge-only cable**. It is sometimes
|
||||
very hard to tell the difference between a data and charge cable! Try using the
|
||||
cable with other devices or swapping to another cable to confirm it is not
|
||||
the problem.
|
||||
|
||||
- **Be sure you are supplying adequate power to the board.** Check the specs of
|
||||
your board and plug in an external power supply. In many cases just
|
||||
plugging a board into your computer is not enough to power it and other
|
||||
peripherals.
|
||||
|
||||
- **Double check all soldering joints and connections.** Flakey connections
|
||||
cause many mysterious problems. See the [guide to excellent soldering](https://learn.adafruit.com/adafruit-guide-excellent-soldering/tools) for examples of good solder joints.
|
||||
|
||||
- **Ensure you are using an official Arduino or Adafruit board.** We can't
|
||||
guarantee a clone board will have the same functionality and work as expected
|
||||
with this code and don't support them.
|
||||
|
||||
If you're sure this issue is a defect in the code and checked the steps above
|
||||
please fill in the following fields to provide enough troubleshooting information.
|
||||
You may delete the guideline and text above to just leave the following details:
|
||||
|
||||
- Arduino board: **INSERT ARDUINO BOARD NAME/TYPE HERE**
|
||||
|
||||
- Arduino IDE version (found in Arduino -> About Arduino menu): **INSERT ARDUINO
|
||||
VERSION HERE**
|
||||
|
||||
- List the steps to reproduce the problem below (if possible attach a sketch or
|
||||
copy the sketch code in too): **LIST REPRO STEPS BELOW**
|
||||
@@ -0,0 +1,26 @@
|
||||
Thank you for creating a pull request to contribute to Adafruit's GitHub code!
|
||||
Before you open the request please review the following guidelines and tips to
|
||||
help it be more easily integrated:
|
||||
|
||||
- **Describe the scope of your change--i.e. what the change does and what parts
|
||||
of the code were modified.** This will help us understand any risks of integrating
|
||||
the code.
|
||||
|
||||
- **Describe any known limitations with your change.** For example if the change
|
||||
doesn't apply to a supported platform of the library please mention it.
|
||||
|
||||
- **Please run any tests or examples that can exercise your modified code.** We
|
||||
strive to not break users of the code and running tests/examples helps with this
|
||||
process.
|
||||
|
||||
Thank you again for contributing! We will try to test and integrate the change
|
||||
as soon as we can, but be aware we have many GitHub repositories to manage and
|
||||
can't immediately respond to every request. There is no need to bump or check in
|
||||
on a pull request (it will clutter the discussion of the request).
|
||||
|
||||
Also don't be worried if the request is closed or not integrated--sometimes the
|
||||
priorities of Adafruit's GitHub code (education, ease of use) might not match the
|
||||
priorities of the pull request. Don't fret, the open source community thrives on
|
||||
forks and GitHub makes it easy to keep your changes in a forked repo.
|
||||
|
||||
After reviewing the guidelines above you can delete this text from the pull request.
|
||||
@@ -0,0 +1,504 @@
|
||||
/**************************************************************************/
|
||||
/*!
|
||||
@file Adafruit_TSL2591.cpp
|
||||
@author KT0WN (adafruit.com)
|
||||
|
||||
This is a library for the Adafruit TSL2591 breakout board
|
||||
This library works with the Adafruit TSL2591 breakout
|
||||
----> https://www.adafruit.com/products/1980
|
||||
|
||||
Check out the links above for our tutorials and wiring diagrams
|
||||
These chips use I2C to communicate
|
||||
|
||||
Adafruit invests time and resources providing this open source code,
|
||||
please support Adafruit and open-source hardware by purchasing
|
||||
products from Adafruit!
|
||||
|
||||
@section LICENSE
|
||||
|
||||
Software License Agreement (BSD License)
|
||||
|
||||
Copyright (c) 2014 Adafruit Industries
|
||||
All rights reserved.
|
||||
|
||||
Redistribution and use in source and binary forms, with or without
|
||||
modification, are permitted provided that the following conditions are met:
|
||||
1. Redistributions of source code must retain the above copyright
|
||||
notice, this list of conditions and the following disclaimer.
|
||||
2. Redistributions in binary form must reproduce the above copyright
|
||||
notice, this list of conditions and the following disclaimer in the
|
||||
documentation and/or other materials provided with the distribution.
|
||||
3. Neither the name of the copyright holders nor the
|
||||
names of its contributors may be used to endorse or promote products
|
||||
derived from this software without specific prior written permission.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ''AS IS'' AND ANY
|
||||
EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
||||
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER BE LIABLE FOR ANY
|
||||
DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
|
||||
ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
/**************************************************************************/
|
||||
#if defined(ESP8266) || defined(ESP32)
|
||||
#include <pgmspace.h>
|
||||
#else
|
||||
#include <avr/pgmspace.h>
|
||||
#endif
|
||||
#if defined(__AVR__)
|
||||
#include <util/delay.h>
|
||||
#endif
|
||||
#include <stdlib.h>
|
||||
|
||||
#include "Adafruit_TSL2591.h"
|
||||
|
||||
Adafruit_TSL2591::Adafruit_TSL2591(int32_t sensorID)
|
||||
{
|
||||
_initialized = false;
|
||||
_integration = TSL2591_INTEGRATIONTIME_100MS;
|
||||
_gain = TSL2591_GAIN_MED;
|
||||
_sensorID = sensorID;
|
||||
|
||||
// we cant do wire initialization till later, because we havent loaded Wire yet
|
||||
}
|
||||
|
||||
boolean Adafruit_TSL2591::begin(void)
|
||||
{
|
||||
Wire.begin();
|
||||
|
||||
/*
|
||||
for (uint8_t i=0; i<0x20; i++)
|
||||
{
|
||||
uint8_t id = read8(0x12);
|
||||
Serial.print("$"); Serial.print(i, HEX);
|
||||
Serial.print(" = 0x"); Serial.println(read8(i), HEX);
|
||||
}
|
||||
*/
|
||||
|
||||
uint8_t id = read8(TSL2591_COMMAND_BIT | TSL2591_REGISTER_DEVICE_ID);
|
||||
if (id == 0x50 )
|
||||
{
|
||||
// Serial.println("Found Adafruit_TSL2591");
|
||||
}
|
||||
else
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
_initialized = true;
|
||||
|
||||
// Set default integration time and gain
|
||||
setTiming(_integration);
|
||||
setGain(_gain);
|
||||
|
||||
// Note: by default, the device is in power down mode on bootup
|
||||
disable();
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
void Adafruit_TSL2591::enable(void)
|
||||
{
|
||||
if (!_initialized)
|
||||
{
|
||||
if (!begin())
|
||||
{
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
// Enable the device by setting the control bit to 0x01
|
||||
write8(TSL2591_COMMAND_BIT | TSL2591_REGISTER_ENABLE, TSL2591_ENABLE_POWERON | TSL2591_ENABLE_AEN | TSL2591_ENABLE_AIEN | TSL2591_ENABLE_NPIEN);
|
||||
}
|
||||
|
||||
void Adafruit_TSL2591::disable(void)
|
||||
{
|
||||
if (!_initialized)
|
||||
{
|
||||
if (!begin())
|
||||
{
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
// Disable the device by setting the control bit to 0x00
|
||||
write8(TSL2591_COMMAND_BIT | TSL2591_REGISTER_ENABLE, TSL2591_ENABLE_POWEROFF);
|
||||
}
|
||||
|
||||
void Adafruit_TSL2591::setGain(tsl2591Gain_t gain)
|
||||
{
|
||||
if (!_initialized)
|
||||
{
|
||||
if (!begin())
|
||||
{
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
enable();
|
||||
_gain = gain;
|
||||
write8(TSL2591_COMMAND_BIT | TSL2591_REGISTER_CONTROL, _integration | _gain);
|
||||
disable();
|
||||
}
|
||||
|
||||
tsl2591Gain_t Adafruit_TSL2591::getGain()
|
||||
{
|
||||
return _gain;
|
||||
}
|
||||
|
||||
void Adafruit_TSL2591::setTiming(tsl2591IntegrationTime_t integration)
|
||||
{
|
||||
if (!_initialized)
|
||||
{
|
||||
if (!begin())
|
||||
{
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
enable();
|
||||
_integration = integration;
|
||||
write8(TSL2591_COMMAND_BIT | TSL2591_REGISTER_CONTROL, _integration | _gain);
|
||||
disable();
|
||||
}
|
||||
|
||||
tsl2591IntegrationTime_t Adafruit_TSL2591::getTiming()
|
||||
{
|
||||
return _integration;
|
||||
}
|
||||
|
||||
float Adafruit_TSL2591::calculateLuxf(uint16_t ch0, uint16_t ch1)
|
||||
{
|
||||
float atime, again;
|
||||
float cpl, lux1, lux2, lux;
|
||||
uint32_t chan0, chan1;
|
||||
|
||||
// Check for overflow conditions first
|
||||
if ((ch0 == 0xFFFF) | (ch1 == 0xFFFF))
|
||||
{
|
||||
// Signal an overflow
|
||||
return 0;
|
||||
}
|
||||
|
||||
// Note: This algorithm is based on preliminary coefficients
|
||||
// provided by AMS and may need to be updated in the future
|
||||
|
||||
switch (_integration)
|
||||
{
|
||||
case TSL2591_INTEGRATIONTIME_100MS :
|
||||
atime = 100.0F;
|
||||
break;
|
||||
case TSL2591_INTEGRATIONTIME_200MS :
|
||||
atime = 200.0F;
|
||||
break;
|
||||
case TSL2591_INTEGRATIONTIME_300MS :
|
||||
atime = 300.0F;
|
||||
break;
|
||||
case TSL2591_INTEGRATIONTIME_400MS :
|
||||
atime = 400.0F;
|
||||
break;
|
||||
case TSL2591_INTEGRATIONTIME_500MS :
|
||||
atime = 500.0F;
|
||||
break;
|
||||
case TSL2591_INTEGRATIONTIME_600MS :
|
||||
atime = 600.0F;
|
||||
break;
|
||||
default: // 100ms
|
||||
atime = 100.0F;
|
||||
break;
|
||||
}
|
||||
|
||||
switch (_gain)
|
||||
{
|
||||
case TSL2591_GAIN_LOW :
|
||||
again = 1.0F;
|
||||
break;
|
||||
case TSL2591_GAIN_MED :
|
||||
again = 25.0F;
|
||||
break;
|
||||
case TSL2591_GAIN_HIGH :
|
||||
again = 428.0F;
|
||||
break;
|
||||
case TSL2591_GAIN_MAX :
|
||||
again = 9876.0F;
|
||||
break;
|
||||
default:
|
||||
again = 1.0F;
|
||||
break;
|
||||
}
|
||||
|
||||
// cpl = (ATIME * AGAIN) / DF
|
||||
cpl = (atime * again) / TSL2591_LUX_DF;
|
||||
|
||||
lux1 = (((float) ch0 - (float) ch1)) * (1.0F - ((float) ch1 / (float) ch0)) / cpl;//( (float)ch0 - (TSL2591_LUX_COEFB * (float)ch1) ) / cpl;
|
||||
lux2 = ((TSL2591_LUX_COEFC * (float) ch0) - (TSL2591_LUX_COEFD * (float) ch1)) / cpl;
|
||||
lux = lux1 > lux2 ? lux1 : lux2;
|
||||
|
||||
// Alternate lux calculation
|
||||
//lux = ( (float)ch0 - ( 1.7F * (float)ch1 ) ) / cpl;
|
||||
|
||||
// Signal I2C had no errors
|
||||
return lux;
|
||||
}
|
||||
|
||||
uint32_t Adafruit_TSL2591::calculateLux(uint16_t ch0, uint16_t ch1)
|
||||
{
|
||||
return (uint32_t) calculateLuxf(ch0, ch1);
|
||||
}
|
||||
|
||||
uint32_t Adafruit_TSL2591::getFullLuminosity (void)
|
||||
{
|
||||
if (!_initialized)
|
||||
{
|
||||
if (!begin())
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
// Enable the device
|
||||
enable();
|
||||
|
||||
// Wait x ms for ADC to complete
|
||||
for (uint8_t d=0; d<=_integration; d++)
|
||||
{
|
||||
delay(120);
|
||||
}
|
||||
|
||||
uint32_t x;
|
||||
uint16_t y;
|
||||
y |= read16(TSL2591_COMMAND_BIT | TSL2591_REGISTER_CHAN0_LOW);
|
||||
x = read16(TSL2591_COMMAND_BIT | TSL2591_REGISTER_CHAN1_LOW);
|
||||
x <<= 16;
|
||||
x |= y;
|
||||
|
||||
disable();
|
||||
|
||||
return x;
|
||||
}
|
||||
|
||||
uint16_t Adafruit_TSL2591::getLuminosity (uint8_t channel)
|
||||
{
|
||||
uint32_t x = getFullLuminosity();
|
||||
|
||||
if (channel == TSL2591_FULLSPECTRUM)
|
||||
{
|
||||
// Reads two byte value from channel 0 (visible + infrared)
|
||||
return (x & 0xFFFF);
|
||||
}
|
||||
else if (channel == TSL2591_INFRARED)
|
||||
{
|
||||
// Reads two byte value from channel 1 (infrared)
|
||||
return (x >> 16);
|
||||
}
|
||||
else if (channel == TSL2591_VISIBLE)
|
||||
{
|
||||
// Reads all and subtracts out just the visible!
|
||||
return ( (x & 0xFFFF) - (x >> 16));
|
||||
}
|
||||
|
||||
// unknown channel!
|
||||
return 0;
|
||||
}
|
||||
|
||||
void Adafruit_TSL2591::registerInterrupt(uint16_t lowerThreshold, uint16_t upperThreshold)
|
||||
{
|
||||
if (!_initialized)
|
||||
{
|
||||
if (!begin())
|
||||
{
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
enable();
|
||||
write8(TSL2591_COMMAND_BIT | TSL2591_REGISTER_THRESHOLD_NPAILTL, lowerThreshold);
|
||||
write8(TSL2591_COMMAND_BIT | TSL2591_REGISTER_THRESHOLD_NPAILTH, lowerThreshold >> 8);
|
||||
write8(TSL2591_COMMAND_BIT | TSL2591_REGISTER_THRESHOLD_NPAIHTL, upperThreshold);
|
||||
write8(TSL2591_COMMAND_BIT | TSL2591_REGISTER_THRESHOLD_NPAIHTH, upperThreshold >> 8);
|
||||
disable();
|
||||
}
|
||||
|
||||
void Adafruit_TSL2591::registerInterrupt(uint16_t lowerThreshold, uint16_t upperThreshold, tsl2591Persist_t persist)
|
||||
{
|
||||
if (!_initialized)
|
||||
{
|
||||
if (!begin())
|
||||
{
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
enable();
|
||||
write8(TSL2591_COMMAND_BIT | TSL2591_REGISTER_PERSIST_FILTER, persist);
|
||||
write8(TSL2591_COMMAND_BIT | TSL2591_REGISTER_THRESHOLD_AILTL, lowerThreshold);
|
||||
write8(TSL2591_COMMAND_BIT | TSL2591_REGISTER_THRESHOLD_AILTH, lowerThreshold >> 8);
|
||||
write8(TSL2591_COMMAND_BIT | TSL2591_REGISTER_THRESHOLD_AIHTL, upperThreshold);
|
||||
write8(TSL2591_COMMAND_BIT | TSL2591_REGISTER_THRESHOLD_AIHTH, upperThreshold >> 8);
|
||||
disable();
|
||||
}
|
||||
|
||||
void Adafruit_TSL2591::clearInterrupt()
|
||||
{
|
||||
if (!_initialized)
|
||||
{
|
||||
if (!begin())
|
||||
{
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
enable();
|
||||
write8(TSL2591_CLEAR_INT);
|
||||
disable();
|
||||
}
|
||||
|
||||
|
||||
uint8_t Adafruit_TSL2591::getStatus()
|
||||
{
|
||||
if (!_initialized)
|
||||
{
|
||||
if (!begin())
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
// Enable the device
|
||||
enable();
|
||||
uint8_t x;
|
||||
x = read8(TSL2591_COMMAND_BIT | TSL2591_REGISTER_DEVICE_STATUS);
|
||||
disable();
|
||||
return x;
|
||||
}
|
||||
|
||||
|
||||
uint8_t Adafruit_TSL2591::read8(uint8_t reg)
|
||||
{
|
||||
uint8_t x;
|
||||
|
||||
Wire.beginTransmission(TSL2591_ADDR);
|
||||
#if ARDUINO >= 100
|
||||
Wire.write(reg);
|
||||
#else
|
||||
Wire.send(reg);
|
||||
#endif
|
||||
Wire.endTransmission();
|
||||
|
||||
Wire.requestFrom(TSL2591_ADDR, 1);
|
||||
#if ARDUINO >= 100
|
||||
x = Wire.read();
|
||||
#else
|
||||
x = Wire.receive();
|
||||
#endif
|
||||
// while (! Wire.available());
|
||||
// return Wire.read();
|
||||
return x;
|
||||
}
|
||||
|
||||
uint16_t Adafruit_TSL2591::read16(uint8_t reg)
|
||||
{
|
||||
uint16_t x;
|
||||
uint16_t t;
|
||||
|
||||
Wire.beginTransmission(TSL2591_ADDR);
|
||||
#if ARDUINO >= 100
|
||||
Wire.write(reg);
|
||||
#else
|
||||
Wire.send(reg);
|
||||
#endif
|
||||
Wire.endTransmission();
|
||||
|
||||
Wire.requestFrom(TSL2591_ADDR, 2);
|
||||
#if ARDUINO >= 100
|
||||
t = Wire.read();
|
||||
x = Wire.read();
|
||||
#else
|
||||
t = Wire.receive();
|
||||
x = Wire.receive();
|
||||
#endif
|
||||
x <<= 8;
|
||||
x |= t;
|
||||
return x;
|
||||
}
|
||||
|
||||
void Adafruit_TSL2591::write8 (uint8_t reg, uint8_t value)
|
||||
{
|
||||
Wire.beginTransmission(TSL2591_ADDR);
|
||||
#if ARDUINO >= 100
|
||||
Wire.write(reg);
|
||||
Wire.write(value);
|
||||
#else
|
||||
Wire.send(reg);
|
||||
Wire.send(value);
|
||||
#endif
|
||||
Wire.endTransmission();
|
||||
}
|
||||
|
||||
|
||||
void Adafruit_TSL2591::write8 (uint8_t reg)
|
||||
{
|
||||
Wire.beginTransmission(TSL2591_ADDR);
|
||||
#if ARDUINO >= 100
|
||||
Wire.write(reg);
|
||||
#else
|
||||
Wire.send(reg);
|
||||
#endif
|
||||
Wire.endTransmission();
|
||||
}
|
||||
|
||||
/**************************************************************************/
|
||||
/*!
|
||||
@brief Gets the most recent sensor event
|
||||
*/
|
||||
/**************************************************************************/
|
||||
bool Adafruit_TSL2591::getEvent(sensors_event_t *event)
|
||||
{
|
||||
uint16_t ir, full;
|
||||
uint32_t lum = getFullLuminosity();
|
||||
/* Early silicon seems to have issues when there is a sudden jump in */
|
||||
/* light levels. :( To work around this for now sample the sensor 2x */
|
||||
lum = getFullLuminosity();
|
||||
ir = lum >> 16;
|
||||
full = lum & 0xFFFF;
|
||||
|
||||
/* Clear the event */
|
||||
memset(event, 0, sizeof(sensors_event_t));
|
||||
|
||||
event->version = sizeof(sensors_event_t);
|
||||
event->sensor_id = _sensorID;
|
||||
event->type = SENSOR_TYPE_LIGHT;
|
||||
event->timestamp = millis();
|
||||
|
||||
/* Calculate the actual lux value */
|
||||
/* 0 = sensor overflow (too much light) */
|
||||
event->light = calculateLux(full, ir);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**************************************************************************/
|
||||
/*!
|
||||
@brief Gets the sensor_t data
|
||||
*/
|
||||
/**************************************************************************/
|
||||
void Adafruit_TSL2591::getSensor(sensor_t *sensor)
|
||||
{
|
||||
/* Clear the sensor_t object */
|
||||
memset(sensor, 0, sizeof(sensor_t));
|
||||
|
||||
/* Insert the sensor name in the fixed length char array */
|
||||
strncpy (sensor->name, "TSL2591", sizeof(sensor->name) - 1);
|
||||
sensor->name[sizeof(sensor->name)- 1] = 0;
|
||||
sensor->version = 1;
|
||||
sensor->sensor_id = _sensorID;
|
||||
sensor->type = SENSOR_TYPE_LIGHT;
|
||||
sensor->min_delay = 0;
|
||||
sensor->max_value = 88000.0;
|
||||
sensor->min_value = 0.0;
|
||||
sensor->resolution = 1.0;
|
||||
}
|
||||
@@ -0,0 +1,187 @@
|
||||
/**************************************************************************/
|
||||
/*!
|
||||
@file Adafruit_TSL2591.h
|
||||
@author KT0WN (adafruit.com)
|
||||
|
||||
This is a library for the Adafruit TSL2591 breakout board
|
||||
This library works with the Adafruit TSL2591 breakout
|
||||
----> https://www.adafruit.com/products/1980
|
||||
|
||||
Check out the links above for our tutorials and wiring diagrams
|
||||
These chips use I2C to communicate
|
||||
|
||||
Adafruit invests time and resources providing this open source code,
|
||||
please support Adafruit and open-source hardware by purchasing
|
||||
products from Adafruit!
|
||||
|
||||
@section LICENSE
|
||||
|
||||
Software License Agreement (BSD License)
|
||||
|
||||
Copyright (c) 2014 Adafruit Industries
|
||||
All rights reserved.
|
||||
|
||||
Redistribution and use in source and binary forms, with or without
|
||||
modification, are permitted provided that the following conditions are met:
|
||||
1. Redistributions of source code must retain the above copyright
|
||||
notice, this list of conditions and the following disclaimer.
|
||||
2. Redistributions in binary form must reproduce the above copyright
|
||||
notice, this list of conditions and the following disclaimer in the
|
||||
documentation and/or other materials provided with the distribution.
|
||||
3. Neither the name of the copyright holders nor the
|
||||
names of its contributors may be used to endorse or promote products
|
||||
derived from this software without specific prior written permission.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ''AS IS'' AND ANY
|
||||
EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
||||
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER BE LIABLE FOR ANY
|
||||
DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
|
||||
ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
/**************************************************************************/
|
||||
|
||||
#ifndef _TSL2591_H_
|
||||
#define _TSL2591_H_
|
||||
|
||||
#if ARDUINO >= 100
|
||||
#include <Arduino.h>
|
||||
#else
|
||||
#include <WProgram.h>
|
||||
#endif
|
||||
#include <Adafruit_Sensor.h>
|
||||
#include <Wire.h>
|
||||
|
||||
#define TSL2591_VISIBLE (2) // channel 0 - channel 1
|
||||
#define TSL2591_INFRARED (1) // channel 1
|
||||
#define TSL2591_FULLSPECTRUM (0) // channel 0
|
||||
|
||||
#define TSL2591_ADDR (0x29)
|
||||
#define TSL2591_READBIT (0x01)
|
||||
|
||||
#define TSL2591_COMMAND_BIT (0xA0) // 1010 0000: bits 7 and 5 for 'command normal'
|
||||
#define TSL2591_CLEAR_INT (0xE7)
|
||||
#define TSL2591_TEST_INT (0xE4)
|
||||
#define TSL2591_WORD_BIT (0x20) // 1 = read/write word (rather than byte)
|
||||
#define TSL2591_BLOCK_BIT (0x10) // 1 = using block read/write
|
||||
|
||||
#define TSL2591_ENABLE_POWEROFF (0x00)
|
||||
#define TSL2591_ENABLE_POWERON (0x01)
|
||||
#define TSL2591_ENABLE_AEN (0x02) // ALS Enable. This field activates ALS function. Writing a one activates the ALS. Writing a zero disables the ALS.
|
||||
#define TSL2591_ENABLE_AIEN (0x10) // ALS Interrupt Enable. When asserted permits ALS interrupts to be generated, subject to the persist filter.
|
||||
#define TSL2591_ENABLE_NPIEN (0x80) // No Persist Interrupt Enable. When asserted NP Threshold conditions will generate an interrupt, bypassing the persist filter
|
||||
|
||||
#define TSL2591_LUX_DF (408.0F)
|
||||
#define TSL2591_LUX_COEFB (1.64F) // CH0 coefficient
|
||||
#define TSL2591_LUX_COEFC (0.59F) // CH1 coefficient A
|
||||
#define TSL2591_LUX_COEFD (0.86F) // CH2 coefficient B
|
||||
|
||||
enum
|
||||
{
|
||||
TSL2591_REGISTER_ENABLE = 0x00,
|
||||
TSL2591_REGISTER_CONTROL = 0x01,
|
||||
TSL2591_REGISTER_THRESHOLD_AILTL = 0x04, // ALS low threshold lower byte
|
||||
TSL2591_REGISTER_THRESHOLD_AILTH = 0x05, // ALS low threshold upper byte
|
||||
TSL2591_REGISTER_THRESHOLD_AIHTL = 0x06, // ALS high threshold lower byte
|
||||
TSL2591_REGISTER_THRESHOLD_AIHTH = 0x07, // ALS high threshold upper byte
|
||||
TSL2591_REGISTER_THRESHOLD_NPAILTL = 0x08, // No Persist ALS low threshold lower byte
|
||||
TSL2591_REGISTER_THRESHOLD_NPAILTH = 0x09, // etc
|
||||
TSL2591_REGISTER_THRESHOLD_NPAIHTL = 0x0A,
|
||||
TSL2591_REGISTER_THRESHOLD_NPAIHTH = 0x0B,
|
||||
TSL2591_REGISTER_PERSIST_FILTER = 0x0C,
|
||||
TSL2591_REGISTER_PACKAGE_PID = 0x11,
|
||||
TSL2591_REGISTER_DEVICE_ID = 0x12,
|
||||
TSL2591_REGISTER_DEVICE_STATUS = 0x13,
|
||||
TSL2591_REGISTER_CHAN0_LOW = 0x14,
|
||||
TSL2591_REGISTER_CHAN0_HIGH = 0x15,
|
||||
TSL2591_REGISTER_CHAN1_LOW = 0x16,
|
||||
TSL2591_REGISTER_CHAN1_HIGH = 0x17
|
||||
};
|
||||
|
||||
typedef enum
|
||||
{
|
||||
TSL2591_INTEGRATIONTIME_100MS = 0x00,
|
||||
TSL2591_INTEGRATIONTIME_200MS = 0x01,
|
||||
TSL2591_INTEGRATIONTIME_300MS = 0x02,
|
||||
TSL2591_INTEGRATIONTIME_400MS = 0x03,
|
||||
TSL2591_INTEGRATIONTIME_500MS = 0x04,
|
||||
TSL2591_INTEGRATIONTIME_600MS = 0x05,
|
||||
}
|
||||
tsl2591IntegrationTime_t;
|
||||
|
||||
typedef enum
|
||||
{
|
||||
// bit 7:4: 0
|
||||
TSL2591_PERSIST_EVERY = 0x00, // Every ALS cycle generates an interrupt
|
||||
TSL2591_PERSIST_ANY = 0x01, // Any value outside of threshold range
|
||||
TSL2591_PERSIST_2 = 0x02, // 2 consecutive values out of range
|
||||
TSL2591_PERSIST_3 = 0x03, // 3 consecutive values out of range
|
||||
TSL2591_PERSIST_5 = 0x04, // 5 consecutive values out of range
|
||||
TSL2591_PERSIST_10 = 0x05, // 10 consecutive values out of range
|
||||
TSL2591_PERSIST_15 = 0x06, // 15 consecutive values out of range
|
||||
TSL2591_PERSIST_20 = 0x07, // 20 consecutive values out of range
|
||||
TSL2591_PERSIST_25 = 0x08, // 25 consecutive values out of range
|
||||
TSL2591_PERSIST_30 = 0x09, // 30 consecutive values out of range
|
||||
TSL2591_PERSIST_35 = 0x0A, // 35 consecutive values out of range
|
||||
TSL2591_PERSIST_40 = 0x0B, // 40 consecutive values out of range
|
||||
TSL2591_PERSIST_45 = 0x0C, // 45 consecutive values out of range
|
||||
TSL2591_PERSIST_50 = 0x0D, // 50 consecutive values out of range
|
||||
TSL2591_PERSIST_55 = 0x0E, // 55 consecutive values out of range
|
||||
TSL2591_PERSIST_60 = 0x0F, // 60 consecutive values out of range
|
||||
}
|
||||
tsl2591Persist_t;
|
||||
|
||||
typedef enum
|
||||
{
|
||||
TSL2591_GAIN_LOW = 0x00, // low gain (1x)
|
||||
TSL2591_GAIN_MED = 0x10, // medium gain (25x)
|
||||
TSL2591_GAIN_HIGH = 0x20, // medium gain (428x)
|
||||
TSL2591_GAIN_MAX = 0x30, // max gain (9876x)
|
||||
}
|
||||
tsl2591Gain_t;
|
||||
|
||||
class Adafruit_TSL2591 : public Adafruit_Sensor
|
||||
{
|
||||
public:
|
||||
Adafruit_TSL2591(int32_t sensorID = -1);
|
||||
|
||||
boolean begin ( void );
|
||||
void enable ( void );
|
||||
void disable ( void );
|
||||
void write8 ( uint8_t r);
|
||||
void write8 ( uint8_t r, uint8_t v );
|
||||
uint16_t read16 ( uint8_t reg );
|
||||
uint8_t read8 ( uint8_t reg );
|
||||
|
||||
uint32_t calculateLux ( uint16_t ch0, uint16_t ch1 );
|
||||
float calculateLuxf ( uint16_t ch0, uint16_t ch1 );
|
||||
void setGain ( tsl2591Gain_t gain );
|
||||
void setTiming ( tsl2591IntegrationTime_t integration );
|
||||
uint16_t getLuminosity (uint8_t channel );
|
||||
uint32_t getFullLuminosity ( );
|
||||
|
||||
tsl2591IntegrationTime_t getTiming();
|
||||
tsl2591Gain_t getGain();
|
||||
|
||||
// Interrupt
|
||||
void clearInterrupt(void);
|
||||
void registerInterrupt(uint16_t lowerThreshold, uint16_t upperThreshold);
|
||||
void registerInterrupt(uint16_t lowerThreshold, uint16_t upperThreshold, tsl2591Persist_t persist);
|
||||
uint8_t getStatus();
|
||||
|
||||
/* Unified Sensor API Functions */
|
||||
bool getEvent ( sensors_event_t* );
|
||||
void getSensor ( sensor_t* );
|
||||
|
||||
private:
|
||||
tsl2591IntegrationTime_t _integration;
|
||||
tsl2591Gain_t _gain;
|
||||
int32_t _sensorID;
|
||||
|
||||
boolean _initialized;
|
||||
};
|
||||
#endif
|
||||
@@ -0,0 +1,9 @@
|
||||
This is an Arduino library for the TSL2591 digital luminosity (light) sensors.
|
||||
|
||||
Pick one up at http://www.adafruit.com/products/1980
|
||||
|
||||
To download. click the DOWNLOADS button in the top right corner, rename the uncompressed folder Adafruit_TSL2591. Check that the Adafruit_TSL2591 folder contains Adafruit_TSL2591.cpp and Adafruit_TSL2591.h
|
||||
|
||||
Place the Adafruit_TSL2591 library folder your <arduinosketchfolder>/libraries/ folder. You may need to create the libraries subfolder if its your first library. Restart the IDE.
|
||||
|
||||
You'll also need the Adafruit_Sensor library from https://github.com/adafruit/Adafruit_Sensor
|
||||
@@ -0,0 +1,200 @@
|
||||
/* TSL2591 Digital Light Sensor */
|
||||
/* Dynamic Range: 600M:1 */
|
||||
/* Maximum Lux: 88K */
|
||||
|
||||
#include <Wire.h>
|
||||
#include <Adafruit_Sensor.h>
|
||||
#include "Adafruit_TSL2591.h"
|
||||
|
||||
// Example for demonstrating the TSL2591 library - public domain!
|
||||
|
||||
// connect SCL to analog 5
|
||||
// connect SDA to analog 4
|
||||
// connect Vin to 3.3-5V DC
|
||||
// connect GROUND to common ground
|
||||
|
||||
Adafruit_TSL2591 tsl = Adafruit_TSL2591(2591); // pass in a number for the sensor identifier (for your use later)
|
||||
|
||||
/**************************************************************************/
|
||||
/*
|
||||
Displays some basic information on this sensor from the unified
|
||||
sensor API sensor_t type (see Adafruit_Sensor for more information)
|
||||
*/
|
||||
/**************************************************************************/
|
||||
void displaySensorDetails(void)
|
||||
{
|
||||
sensor_t sensor;
|
||||
tsl.getSensor(&sensor);
|
||||
Serial.println(F("------------------------------------"));
|
||||
Serial.print (F("Sensor: ")); Serial.println(sensor.name);
|
||||
Serial.print (F("Driver Ver: ")); Serial.println(sensor.version);
|
||||
Serial.print (F("Unique ID: ")); Serial.println(sensor.sensor_id);
|
||||
Serial.print (F("Max Value: ")); Serial.print(sensor.max_value); Serial.println(F(" lux"));
|
||||
Serial.print (F("Min Value: ")); Serial.print(sensor.min_value); Serial.println(F(" lux"));
|
||||
Serial.print (F("Resolution: ")); Serial.print(sensor.resolution); Serial.println(F(" lux"));
|
||||
Serial.println(F("------------------------------------"));
|
||||
Serial.println(F(""));
|
||||
delay(500);
|
||||
}
|
||||
|
||||
/**************************************************************************/
|
||||
/*
|
||||
Configures the gain and integration time for the TSL2591
|
||||
*/
|
||||
/**************************************************************************/
|
||||
void configureSensor(void)
|
||||
{
|
||||
// You can change the gain on the fly, to adapt to brighter/dimmer light situations
|
||||
//tsl.setGain(TSL2591_GAIN_LOW); // 1x gain (bright light)
|
||||
tsl.setGain(TSL2591_GAIN_MED); // 25x gain
|
||||
// tsl.setGain(TSL2591_GAIN_HIGH); // 428x gain
|
||||
|
||||
// Changing the integration time gives you a longer time over which to sense light
|
||||
// longer timelines are slower, but are good in very low light situtations!
|
||||
tsl.setTiming(TSL2591_INTEGRATIONTIME_100MS); // shortest integration time (bright light)
|
||||
// tsl.setTiming(TSL2591_INTEGRATIONTIME_200MS);
|
||||
// tsl.setTiming(TSL2591_INTEGRATIONTIME_300MS);
|
||||
// tsl.setTiming(TSL2591_INTEGRATIONTIME_400MS);
|
||||
// tsl.setTiming(TSL2591_INTEGRATIONTIME_500MS);
|
||||
// tsl.setTiming(TSL2591_INTEGRATIONTIME_600MS); // longest integration time (dim light)
|
||||
|
||||
/* Display the gain and integration time for reference sake */
|
||||
Serial.println(F("------------------------------------"));
|
||||
Serial.print (F("Gain: "));
|
||||
tsl2591Gain_t gain = tsl.getGain();
|
||||
switch(gain)
|
||||
{
|
||||
case TSL2591_GAIN_LOW:
|
||||
Serial.println(F("1x (Low)"));
|
||||
break;
|
||||
case TSL2591_GAIN_MED:
|
||||
Serial.println(F("25x (Medium)"));
|
||||
break;
|
||||
case TSL2591_GAIN_HIGH:
|
||||
Serial.println(F("428x (High)"));
|
||||
break;
|
||||
case TSL2591_GAIN_MAX:
|
||||
Serial.println(F("9876x (Max)"));
|
||||
break;
|
||||
}
|
||||
Serial.print (F("Timing: "));
|
||||
Serial.print((tsl.getTiming() + 1) * 100, DEC);
|
||||
Serial.println(F(" ms"));
|
||||
Serial.println(F("------------------------------------"));
|
||||
Serial.println(F(""));
|
||||
}
|
||||
|
||||
|
||||
/**************************************************************************/
|
||||
/*
|
||||
Program entry point for the Arduino sketch
|
||||
*/
|
||||
/**************************************************************************/
|
||||
void setup(void)
|
||||
{
|
||||
Serial.begin(9600);
|
||||
|
||||
Serial.println(F("Starting Adafruit TSL2591 Test!"));
|
||||
|
||||
if (tsl.begin())
|
||||
{
|
||||
Serial.println(F("Found a TSL2591 sensor"));
|
||||
}
|
||||
else
|
||||
{
|
||||
Serial.println(F("No sensor found ... check your wiring?"));
|
||||
while (1);
|
||||
}
|
||||
|
||||
/* Display some basic information on this sensor */
|
||||
displaySensorDetails();
|
||||
|
||||
/* Configure the sensor */
|
||||
configureSensor();
|
||||
|
||||
// Now we're ready to get readings ... move on to loop()!
|
||||
}
|
||||
|
||||
/**************************************************************************/
|
||||
/*
|
||||
Shows how to perform a basic read on visible, full spectrum or
|
||||
infrared light (returns raw 16-bit ADC values)
|
||||
*/
|
||||
/**************************************************************************/
|
||||
void simpleRead(void)
|
||||
{
|
||||
// Simple data read example. Just read the infrared, fullspecrtrum diode
|
||||
// or 'visible' (difference between the two) channels.
|
||||
// This can take 100-600 milliseconds! Uncomment whichever of the following you want to read
|
||||
uint16_t x = tsl.getLuminosity(TSL2591_VISIBLE);
|
||||
//uint16_t x = tsl.getLuminosity(TSL2591_FULLSPECTRUM);
|
||||
//uint16_t x = tsl.getLuminosity(TSL2591_INFRARED);
|
||||
|
||||
Serial.print(F("[ ")); Serial.print(millis()); Serial.print(F(" ms ] "));
|
||||
Serial.print(F("Luminosity: "));
|
||||
Serial.println(x, DEC);
|
||||
}
|
||||
|
||||
/**************************************************************************/
|
||||
/*
|
||||
Show how to read IR and Full Spectrum at once and convert to lux
|
||||
*/
|
||||
/**************************************************************************/
|
||||
void advancedRead(void)
|
||||
{
|
||||
// More advanced data read example. Read 32 bits with top 16 bits IR, bottom 16 bits full spectrum
|
||||
// That way you can do whatever math and comparisons you want!
|
||||
uint32_t lum = tsl.getFullLuminosity();
|
||||
uint16_t ir, full;
|
||||
ir = lum >> 16;
|
||||
full = lum & 0xFFFF;
|
||||
Serial.print(F("[ ")); Serial.print(millis()); Serial.print(F(" ms ] "));
|
||||
Serial.print(F("IR: ")); Serial.print(ir); Serial.print(F(" "));
|
||||
Serial.print(F("Full: ")); Serial.print(full); Serial.print(F(" "));
|
||||
Serial.print(F("Visible: ")); Serial.print(full - ir); Serial.print(F(" "));
|
||||
Serial.print(F("Lux: ")); Serial.println(tsl.calculateLux(full, ir));
|
||||
}
|
||||
|
||||
/**************************************************************************/
|
||||
/*
|
||||
Performs a read using the Adafruit Unified Sensor API.
|
||||
*/
|
||||
/**************************************************************************/
|
||||
void unifiedSensorAPIRead(void)
|
||||
{
|
||||
/* Get a new sensor event */
|
||||
sensors_event_t event;
|
||||
tsl.getEvent(&event);
|
||||
|
||||
/* Display the results (light is measured in lux) */
|
||||
Serial.print(F("[ ")); Serial.print(event.timestamp); Serial.print(F(" ms ] "));
|
||||
if ((event.light == 0) |
|
||||
(event.light > 4294966000.0) |
|
||||
(event.light <-4294966000.0))
|
||||
{
|
||||
/* If event.light = 0 lux the sensor is probably saturated */
|
||||
/* and no reliable data could be generated! */
|
||||
/* if event.light is +/- 4294967040 there was a float over/underflow */
|
||||
Serial.println(F("Invalid data (adjust gain or timing)"));
|
||||
}
|
||||
else
|
||||
{
|
||||
Serial.print(event.light); Serial.println(F(" lux"));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**************************************************************************/
|
||||
/*
|
||||
Arduino loop function, called once 'setup' is complete (your own code
|
||||
should go here)
|
||||
*/
|
||||
/**************************************************************************/
|
||||
void loop(void)
|
||||
{
|
||||
//simpleRead();
|
||||
advancedRead();
|
||||
// unifiedSensorAPIRead();
|
||||
|
||||
delay(500);
|
||||
}
|
||||
@@ -0,0 +1,229 @@
|
||||
/* TSL2591 Digital Light Sensor, example with (simple) interrupt support */
|
||||
/* Dynamic Range: 600M:1 */
|
||||
/* Maximum Lux: 88K */
|
||||
|
||||
/* This example shows how the interrupt system on the TLS2591
|
||||
* can be used to detect a meaningful change in light levels.
|
||||
*
|
||||
* Two thresholds can be set:
|
||||
*
|
||||
* Lower Threshold - Any light sample on CHAN0 below this value
|
||||
* will trigger an interrupt
|
||||
* Upper Threshold - Any light sample on CHAN0 above this value
|
||||
* will trigger an interrupt
|
||||
*
|
||||
* If CHAN0 (full light) crosses below the low threshold specified,
|
||||
* or above the higher threshold, an interrupt is asserted on the interrupt
|
||||
* pin. The use of the HW pin is optional, though, since the change can
|
||||
* also be detected in software by looking at the status byte via
|
||||
* tsl.getStatus().
|
||||
*
|
||||
* An optional third parameter can be used in the .registerInterrupt
|
||||
* function to indicate the number of samples that must stay outside
|
||||
* the threshold window before the interrupt fires, providing some basic
|
||||
* debouncing of light level data.
|
||||
*
|
||||
* For example, the following code will fire an interrupt on any and every
|
||||
* sample outside the window threshold (meaning a sample below 100 or above
|
||||
* 1500 on CHAN0 or FULL light):
|
||||
*
|
||||
* tsl.registerInterrupt(100, 1500, TSL2591_PERSIST_ANY);
|
||||
*
|
||||
* This code would require five consecutive changes before the interrupt
|
||||
* fires though (see tls2591Persist_t in Adafruit_TLS2591.h for possible
|
||||
* values):
|
||||
*
|
||||
* tsl.registerInterrupt(100, 1500, TSL2591_PERSIST_5);
|
||||
*/
|
||||
|
||||
#include <Wire.h>
|
||||
#include <Adafruit_Sensor.h>
|
||||
#include "Adafruit_TSL2591.h"
|
||||
|
||||
// Example for demonstrating the TSL2591 library - public domain!
|
||||
|
||||
// connect SCL to analog 5
|
||||
// connect SDA to analog 4
|
||||
// connect Vin to 3.3-5V DC
|
||||
// connect GROUND to common ground
|
||||
|
||||
// Interrupt thresholds and persistance
|
||||
#define TLS2591_INT_THRESHOLD_LOWER (100)
|
||||
#define TLS2591_INT_THRESHOLD_UPPER (1500)
|
||||
//#define TLS2591_INT_PERSIST (TSL2591_PERSIST_ANY) // Fire on any valid change
|
||||
#define TLS2591_INT_PERSIST (TSL2591_PERSIST_60) // Require at least 60 samples to fire
|
||||
|
||||
Adafruit_TSL2591 tsl = Adafruit_TSL2591(2591); // pass in a number for the sensor identifier (for your use later)
|
||||
|
||||
/**************************************************************************/
|
||||
/*
|
||||
Displays some basic information on this sensor from the unified
|
||||
sensor API sensor_t type (see Adafruit_Sensor for more information)
|
||||
*/
|
||||
/**************************************************************************/
|
||||
void displaySensorDetails(void)
|
||||
{
|
||||
sensor_t sensor;
|
||||
tsl.getSensor(&sensor);
|
||||
Serial.println("------------------------------------");
|
||||
Serial.print ("Sensor: "); Serial.println(sensor.name);
|
||||
Serial.print ("Driver Ver: "); Serial.println(sensor.version);
|
||||
Serial.print ("Unique ID: "); Serial.println(sensor.sensor_id);
|
||||
Serial.print ("Max Value: "); Serial.print(sensor.max_value); Serial.println(" lux");
|
||||
Serial.print ("Min Value: "); Serial.print(sensor.min_value); Serial.println(" lux");
|
||||
Serial.print ("Resolution: "); Serial.print(sensor.resolution); Serial.println(" lux");
|
||||
Serial.println("------------------------------------");
|
||||
Serial.println("");
|
||||
delay(500);
|
||||
}
|
||||
|
||||
/**************************************************************************/
|
||||
/*
|
||||
Configures the gain and integration time for the TSL2591
|
||||
*/
|
||||
/**************************************************************************/
|
||||
void configureSensor(void)
|
||||
{
|
||||
// You can change the gain on the fly, to adapt to brighter/dimmer light situations
|
||||
//tsl.setGain(TSL2591_GAIN_LOW); // 1x gain (bright light)
|
||||
tsl.setGain(TSL2591_GAIN_MED); // 25x gain
|
||||
// tsl.setGain(TSL2591_GAIN_HIGH); // 428x gain
|
||||
|
||||
// Changing the integration time gives you a longer time over which to sense light
|
||||
// longer timelines are slower, but are good in very low light situtations!
|
||||
tsl.setTiming(TSL2591_INTEGRATIONTIME_100MS); // shortest integration time (bright light)
|
||||
// tsl.setTiming(TSL2591_INTEGRATIONTIME_200MS);
|
||||
// tsl.setTiming(TSL2591_INTEGRATIONTIME_300MS);
|
||||
// tsl.setTiming(TSL2591_INTEGRATIONTIME_400MS);
|
||||
// tsl.setTiming(TSL2591_INTEGRATIONTIME_500MS);
|
||||
// tsl.setTiming(TSL2591_INTEGRATIONTIME_600MS); // longest integration time (dim light)
|
||||
|
||||
/* Display the gain and integration time for reference sake */
|
||||
Serial.println("------------------------------------");
|
||||
Serial.print ("Gain: ");
|
||||
tsl2591Gain_t gain = tsl.getGain();
|
||||
switch (gain)
|
||||
{
|
||||
case TSL2591_GAIN_LOW:
|
||||
Serial.println("1x (Low)");
|
||||
break;
|
||||
case TSL2591_GAIN_MED:
|
||||
Serial.println("25x (Medium)");
|
||||
break;
|
||||
case TSL2591_GAIN_HIGH:
|
||||
Serial.println("428x (High)");
|
||||
break;
|
||||
case TSL2591_GAIN_MAX:
|
||||
Serial.println("9876x (Max)");
|
||||
break;
|
||||
}
|
||||
Serial.print ("Timing: ");
|
||||
Serial.print((tsl.getTiming() + 1) * 100, DEC);
|
||||
Serial.println(" ms");
|
||||
Serial.println("------------------------------------");
|
||||
Serial.println("");
|
||||
|
||||
/* Setup the SW interrupt to trigger between 100 and 1500 lux */
|
||||
/* Threshold values are defined at the top of this sketch */
|
||||
tsl.clearInterrupt();
|
||||
tsl.registerInterrupt(TLS2591_INT_THRESHOLD_LOWER,
|
||||
TLS2591_INT_THRESHOLD_UPPER,
|
||||
TLS2591_INT_PERSIST);
|
||||
|
||||
/* Display the interrupt threshold window */
|
||||
Serial.print("Interrupt Threshold Window: -");
|
||||
Serial.print(TLS2591_INT_THRESHOLD_LOWER, DEC);
|
||||
Serial.print(" to +");
|
||||
Serial.println(TLS2591_INT_THRESHOLD_LOWER, DEC);
|
||||
Serial.println("");
|
||||
}
|
||||
|
||||
|
||||
/**************************************************************************/
|
||||
/*
|
||||
Program entry point for the Arduino sketch
|
||||
*/
|
||||
/**************************************************************************/
|
||||
void setup(void)
|
||||
{
|
||||
Serial.begin(9600);
|
||||
|
||||
// Enable this line for Flora, Zero and Feather boards with no FTDI chip
|
||||
// Waits for the serial port to connect before sending data out
|
||||
// while (!Serial) { delay(1); }
|
||||
|
||||
Serial.println("Starting Adafruit TSL2591 interrupt Test!");
|
||||
|
||||
if (tsl.begin())
|
||||
{
|
||||
Serial.println("Found a TSL2591 sensor");
|
||||
}
|
||||
else
|
||||
{
|
||||
Serial.println("No sensor found ... check your wiring?");
|
||||
while (1);
|
||||
}
|
||||
|
||||
/* Display some basic information on this sensor */
|
||||
displaySensorDetails();
|
||||
|
||||
/* Configure the sensor (including the interrupt threshold) */
|
||||
configureSensor();
|
||||
|
||||
// Now we're ready to get readings ... move on to loop()!
|
||||
}
|
||||
|
||||
/**************************************************************************/
|
||||
/*
|
||||
Show how to read IR and Full Spectrum at once and convert to lux
|
||||
*/
|
||||
/**************************************************************************/
|
||||
void advancedRead(void)
|
||||
{
|
||||
// More advanced data read example. Read 32 bits with top 16 bits IR, bottom 16 bits full spectrum
|
||||
// That way you can do whatever math and comparisons you want!
|
||||
uint32_t lum = tsl.getFullLuminosity();
|
||||
uint16_t ir, full;
|
||||
ir = lum >> 16;
|
||||
full = lum & 0xFFFF;
|
||||
Serial.print("[ "); Serial.print(millis()); Serial.print(" ms ] ");
|
||||
Serial.print("IR: "); Serial.print(ir); Serial.print(" ");
|
||||
Serial.print("Full: "); Serial.print(full); Serial.print(" ");
|
||||
Serial.print("Visible: "); Serial.print(full - ir); Serial.print(" ");
|
||||
Serial.print("Lux: "); Serial.println(tsl.calculateLux(full, ir));
|
||||
}
|
||||
|
||||
|
||||
void getStatus(void)
|
||||
{
|
||||
uint8_t x = tsl.getStatus();
|
||||
// bit 4: ALS Interrupt occured
|
||||
// bit 5: No-persist Interrupt occurence
|
||||
if (x & 0x10) {
|
||||
Serial.print("[ "); Serial.print(millis()); Serial.print(" ms ] ");
|
||||
Serial.println("ALS Interrupt occured");
|
||||
}
|
||||
if (x & 0x20) {
|
||||
Serial.print("[ "); Serial.print(millis()); Serial.print(" ms ] ");
|
||||
Serial.println("No-persist Interrupt occured");
|
||||
}
|
||||
|
||||
// Serial.print("[ "); Serial.print(millis()); Serial.print(" ms ] ");
|
||||
Serial.print("Status: ");
|
||||
Serial.println(x, BIN);
|
||||
tsl.clearInterrupt();
|
||||
}
|
||||
|
||||
|
||||
/**************************************************************************/
|
||||
/*
|
||||
Arduino loop function, called once 'setup' is complete (your own code
|
||||
should go here)
|
||||
*/
|
||||
/**************************************************************************/
|
||||
void loop(void)
|
||||
{
|
||||
advancedRead();
|
||||
getStatus();
|
||||
delay(500);
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
name=Adafruit TSL2591 Library
|
||||
version=1.0.2
|
||||
author=Adafruit
|
||||
maintainer=Adafruit <info@adafruit.com>
|
||||
sentence=Library for the TSL2591 digital luminosity (light) sensors.
|
||||
paragraph=Library for the TSL2591 digital luminosity (light) sensors.
|
||||
category=Sensors
|
||||
url=https://github.com/adafruit/Adafruit_TSL2591_Library
|
||||
architectures=*
|
||||
@@ -0,0 +1,74 @@
|
||||
/*
|
||||
Name: PingTest.ino
|
||||
Created: 05/08/2017 10:20:19
|
||||
Author: pbecc
|
||||
*/
|
||||
#undef PROVA_
|
||||
|
||||
|
||||
#include <WiFi.h>
|
||||
#include "esp32_ping.h"
|
||||
|
||||
// the setup function runs once when you press reset or power the board
|
||||
const char ssid[] = "TP-LINK_C20B"; // your network SSID (name)
|
||||
const char password[] = "paolo-48"; // your network password
|
||||
|
||||
void setup() {
|
||||
|
||||
Serial.begin(115200);
|
||||
Serial.print("Connecting t ");
|
||||
Serial.println(ssid);
|
||||
// WiFi.mode(WIFI_STA);
|
||||
|
||||
WiFi.begin(ssid, password);
|
||||
|
||||
|
||||
while (WiFi.status() != WL_CONNECTED) {
|
||||
delay(500);
|
||||
Serial.print(".");
|
||||
|
||||
|
||||
}
|
||||
Serial.println("Pinging address: 192.168.1.1");
|
||||
}
|
||||
|
||||
// the loop function runs over and over again until power down or reset
|
||||
void loop() {
|
||||
int ia[4] = { 192,168,1,1 };
|
||||
int i = 0;
|
||||
while (Serial.available()) {
|
||||
|
||||
char c = Serial.read();
|
||||
delay(100);
|
||||
int val = 0;
|
||||
while (c != '.' && c != 10 && c!=255) {
|
||||
if (c >= '0'&& c<='9') {
|
||||
val = val*10+(c-'0');
|
||||
}
|
||||
c = Serial.read();
|
||||
}
|
||||
|
||||
ia[i++] =val ;
|
||||
}
|
||||
IPAddress adr = IPAddress(ia[0], ia[1], ia[2], ia[3]);
|
||||
Serial.printf("Ping : %d . %d . %d . %d ->", ia[0], ia[1], ia[2], ia[3]);
|
||||
if (ping_start(adr, 4, 0, 0, 5))
|
||||
Serial.println("OK");
|
||||
else
|
||||
Serial.println("FAILED");
|
||||
delay(10000);
|
||||
|
||||
}
|
||||
int readnu(char s) {
|
||||
char c = Serial.read();
|
||||
Serial.print(c);
|
||||
int digit = 1,val=0;
|
||||
while (c != s && c != 10&&c>0) {
|
||||
if(c>'0') val += digit*(c - '0');
|
||||
digit *= 10;
|
||||
c=Serial.read();
|
||||
Serial.print(int(c));
|
||||
}
|
||||
Serial.println(digit);
|
||||
return digit;
|
||||
}
|
||||
@@ -0,0 +1,4 @@
|
||||
# ESP32_ping
|
||||
Ping library for ESP32
|
||||
|
||||
WORK IN PROGRESS
|
||||
@@ -0,0 +1,366 @@
|
||||
/*
|
||||
* ESP32 Ping library
|
||||
*
|
||||
* All rights reserved.
|
||||
*
|
||||
* Permission to use, copy, modify, and distribute this software
|
||||
* and its documentation for any purpose and without fee is hereby
|
||||
* granted, provided that the above copyright notice appear in all
|
||||
* copies and that both that the copyright notice and this
|
||||
* permission notice and warranty disclaimer appear in supporting
|
||||
* documentation, and that the name of the author not be used in
|
||||
* advertising or publicity pertaining to distribution of the
|
||||
* software without specific, written prior permission.
|
||||
*
|
||||
* The author disclaim all warranties with regard to this
|
||||
* software, including all implied warranties of merchantability
|
||||
* and fitness. In no event shall the author be liable for any
|
||||
* special, indirect or consequential damages or any damages
|
||||
* whatsoever resulting from loss of use, data or profits, whether
|
||||
* in an action of contract, negligence or other tortious action,
|
||||
* arising out of or in connection with the use or performance of
|
||||
* this software.
|
||||
*
|
||||
* --------------------------------------------------------------------------------
|
||||
* Ping Library is based on the following source code:
|
||||
*
|
||||
* Lua RTOS, ping utility
|
||||
*
|
||||
*
|
||||
* Author: Jaume Oliv� (jolive@iberoxarxa.com / jolive@whitecatboard.org)
|
||||
*
|
||||
* --------------------------------------------------------------------------------
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification,
|
||||
* are permitted provided that the following conditions are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright notice,
|
||||
* this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright notice,
|
||||
* this list of conditions and the following disclaimer in the documentation
|
||||
* and/or other materials provided with the distribution.
|
||||
* 3. The name of the author may not be used to endorse or promote products
|
||||
* derived from this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
|
||||
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT
|
||||
* SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
||||
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
|
||||
* OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
||||
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
||||
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
|
||||
* IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
|
||||
* OF SUCH DAMAGE.
|
||||
*
|
||||
* This file is part of the lwIP TCP/IP stack.
|
||||
*
|
||||
*/
|
||||
|
||||
#ifdef ESP32
|
||||
|
||||
#include <Arduino.h>
|
||||
|
||||
#include <math.h>
|
||||
#include <float.h>
|
||||
#include <signal.h>
|
||||
#include <stdint.h>
|
||||
#include <string.h>
|
||||
#include <errno.h>
|
||||
|
||||
#include "esp32_ping.h"
|
||||
|
||||
#include "lwip/inet_chksum.h"
|
||||
#include "lwip/ip.h"
|
||||
#include "lwip/ip4.h"
|
||||
#include "lwip/err.h"
|
||||
#include "lwip/icmp.h"
|
||||
#include "lwip/sockets.h"
|
||||
#include "lwip/sys.h"
|
||||
#include "lwip/netdb.h"
|
||||
#include "lwip/dns.h"
|
||||
|
||||
static uint16_t ping_seq_num;
|
||||
static uint8_t stopped = 0;
|
||||
|
||||
/*
|
||||
* Statistics
|
||||
*/
|
||||
static uint32_t transmitted = 0;
|
||||
static uint32_t received = 0;
|
||||
static float min_time = 0;
|
||||
static float max_time = 0;
|
||||
static float mean_time = 0;
|
||||
static float last_mean_time = 0;
|
||||
static float var_time = 0;
|
||||
|
||||
#define PING_ID 0xAFAF
|
||||
|
||||
#define PING_DEFAULT_COUNT 10
|
||||
#define PING_DEFAULT_INTERVAL 1
|
||||
#define PING_DEFAULT_SIZE 32
|
||||
#define PING_DEFAULT_TIMEOUT 1
|
||||
|
||||
/*
|
||||
* Helper functions
|
||||
*
|
||||
*/
|
||||
static void ping_prepare_echo(struct icmp_echo_hdr *iecho, uint16_t len) {
|
||||
size_t i;
|
||||
size_t data_len = len - sizeof(struct icmp_echo_hdr);
|
||||
|
||||
ICMPH_TYPE_SET(iecho, ICMP_ECHO);
|
||||
ICMPH_CODE_SET(iecho, 0);
|
||||
iecho->chksum = 0;
|
||||
iecho->id = PING_ID;
|
||||
iecho->seqno = htons(++ping_seq_num);
|
||||
|
||||
/* fill the additional data buffer with some data */
|
||||
for (i = 0; i < data_len; i++) {
|
||||
((char*)iecho)[sizeof(struct icmp_echo_hdr) + i] = (char)i;
|
||||
}
|
||||
|
||||
iecho->chksum = inet_chksum(iecho, len);
|
||||
}
|
||||
|
||||
static err_t ping_send(int s, ip4_addr_t *addr, int size) {
|
||||
struct icmp_echo_hdr *iecho;
|
||||
struct sockaddr_in to;
|
||||
size_t ping_size = sizeof(struct icmp_echo_hdr) + size;
|
||||
int err;
|
||||
|
||||
iecho = (struct icmp_echo_hdr *)mem_malloc((mem_size_t)ping_size);
|
||||
if (!iecho) {
|
||||
return ERR_MEM;
|
||||
}
|
||||
|
||||
ping_prepare_echo(iecho, (uint16_t)ping_size);
|
||||
|
||||
to.sin_len = sizeof(to);
|
||||
to.sin_family = AF_INET;
|
||||
inet_addr_from_ipaddr(&to.sin_addr, addr);
|
||||
|
||||
if ((err = sendto(s, iecho, ping_size, 0, (struct sockaddr*)&to, sizeof(to)))) {
|
||||
transmitted++;
|
||||
}
|
||||
|
||||
return (err ? ERR_OK : ERR_VAL);
|
||||
}
|
||||
|
||||
static void ping_recv(int s) {
|
||||
char buf[64];
|
||||
int fromlen, len;
|
||||
struct sockaddr_in from;
|
||||
struct ip_hdr *iphdr;
|
||||
struct icmp_echo_hdr *iecho = NULL;
|
||||
char ipa[16];
|
||||
struct timeval begin;
|
||||
struct timeval end;
|
||||
uint64_t micros_begin;
|
||||
uint64_t micros_end;
|
||||
float elapsed;
|
||||
|
||||
// Register begin time
|
||||
gettimeofday(&begin, NULL);
|
||||
|
||||
// Send
|
||||
while ((len = recvfrom(s, buf, sizeof(buf), 0, (struct sockaddr*)&from, (socklen_t*)&fromlen)) > 0) {
|
||||
if (len >= (int)(sizeof(struct ip_hdr) + sizeof(struct icmp_echo_hdr))) {
|
||||
// Register end time
|
||||
gettimeofday(&end, NULL);
|
||||
|
||||
/// Get from IP address
|
||||
ip4_addr_t fromaddr;
|
||||
inet_addr_to_ipaddr(&fromaddr, &from.sin_addr);
|
||||
|
||||
strcpy(ipa, inet_ntoa(fromaddr));
|
||||
|
||||
// Get echo
|
||||
iphdr = (struct ip_hdr *)buf;
|
||||
iecho = (struct icmp_echo_hdr *)(buf + (IPH_HL(iphdr) * 4));
|
||||
|
||||
// Print ....
|
||||
if ((iecho->id == PING_ID) && (iecho->seqno == htons(ping_seq_num))) {
|
||||
received++;
|
||||
|
||||
// Get elapsed time in milliseconds
|
||||
micros_begin = begin.tv_sec * 1000000;
|
||||
micros_begin += begin.tv_usec;
|
||||
|
||||
micros_end = end.tv_sec * 1000000;
|
||||
micros_end += end.tv_usec;
|
||||
|
||||
elapsed = (float)(micros_end - micros_begin) / (float)1000.0;
|
||||
|
||||
// Update statistics
|
||||
// Mean and variance are computed in an incremental way
|
||||
if (elapsed < min_time) {
|
||||
min_time = elapsed;
|
||||
}
|
||||
|
||||
if (elapsed > max_time) {
|
||||
max_time = elapsed;
|
||||
}
|
||||
|
||||
last_mean_time = mean_time;
|
||||
mean_time = (((received - 1) * mean_time) + elapsed) / received;
|
||||
|
||||
if (received > 1) {
|
||||
var_time = var_time + ((elapsed - last_mean_time) * (elapsed - mean_time));
|
||||
}
|
||||
|
||||
// Print ...
|
||||
log_d("%d bytes from %s: icmp_seq=%d time=%.3f ms\r\n", len, ipa,
|
||||
ntohs(iecho->seqno), elapsed
|
||||
);
|
||||
|
||||
return;
|
||||
}
|
||||
else {
|
||||
// TODO
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (len < 0) {
|
||||
log_d("Request timeout for icmp_seq %d\r\n", ping_seq_num);
|
||||
}
|
||||
}
|
||||
/*
|
||||
static void stop_action(int i) {
|
||||
signal(i, SIG_DFL);
|
||||
|
||||
stopped = 1;
|
||||
}
|
||||
+/
|
||||
/*
|
||||
* Operation functions
|
||||
*
|
||||
*/
|
||||
void ping(const char *name, int count, int interval, int size, int timeout) {
|
||||
// Resolve name
|
||||
hostent * target = gethostbyname(name);
|
||||
IPAddress adr = *target->h_addr_list[0];
|
||||
if (target->h_length == 0) {
|
||||
// TODO: error not found target?????
|
||||
return;
|
||||
}
|
||||
ping_start(adr, count, interval, size, timeout);
|
||||
}
|
||||
bool ping_start(struct ping_option *ping_o) {
|
||||
|
||||
|
||||
return ping_start(ping_o->ip,ping_o->count,0,0,0);
|
||||
|
||||
}
|
||||
bool ping_start(IPAddress adr, int count=0, int interval=0, int size=0, int timeout=0) {
|
||||
// driver_error_t *error;
|
||||
struct sockaddr_in address;
|
||||
ip4_addr_t ping_target;
|
||||
int s;
|
||||
// Get default values if argument are not provided
|
||||
if (count == 0) {
|
||||
count = PING_DEFAULT_COUNT;
|
||||
}
|
||||
|
||||
if (interval == 0) {
|
||||
interval = PING_DEFAULT_INTERVAL;
|
||||
}
|
||||
|
||||
if (size == 0) {
|
||||
size = PING_DEFAULT_SIZE;
|
||||
}
|
||||
|
||||
if (timeout == 0) {
|
||||
timeout = PING_DEFAULT_TIMEOUT;
|
||||
}
|
||||
|
||||
// Create socket
|
||||
if ((s = socket(AF_INET, SOCK_RAW, IP_PROTO_ICMP)) < 0) {
|
||||
// TODO: error
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
address.sin_addr.s_addr = adr;
|
||||
ping_target.addr = address.sin_addr.s_addr;
|
||||
|
||||
// Setup socket
|
||||
struct timeval tout;
|
||||
|
||||
// Timeout
|
||||
tout.tv_sec = timeout;
|
||||
tout.tv_usec = 0;
|
||||
|
||||
if (setsockopt(s, SOL_SOCKET, SO_RCVTIMEO, &tout, sizeof(tout)) < 0) {
|
||||
closesocket(s);
|
||||
// TODO: error
|
||||
return false;
|
||||
}
|
||||
|
||||
stopped = 0;
|
||||
transmitted = 0;
|
||||
received = 0;
|
||||
min_time = 1.E+9;// FLT_MAX;
|
||||
max_time = 0.0;
|
||||
mean_time = 0.0;
|
||||
var_time = 0.0;
|
||||
|
||||
// Register signal for stop ping
|
||||
//signal(SIGINT, stop_action);
|
||||
|
||||
// Begin ping ...
|
||||
char ipa[16];
|
||||
|
||||
strcpy(ipa, inet_ntoa(ping_target));
|
||||
log_i("PING %s: %d data bytes\r\n", ipa, size);
|
||||
|
||||
ping_seq_num = 0;
|
||||
|
||||
while ((ping_seq_num < count) && (!stopped)) {
|
||||
if (ping_send(s, &ping_target, size) == ERR_OK) {
|
||||
ping_recv(s);
|
||||
}
|
||||
delay( interval*1000L);
|
||||
}
|
||||
|
||||
closesocket(s);
|
||||
|
||||
log_i("%d packets transmitted, %d packets received, %.1f%% packet loss\r\n",
|
||||
transmitted,
|
||||
received,
|
||||
((((float)transmitted - (float)received) / (float)transmitted) * 100.0)
|
||||
);
|
||||
|
||||
if (received) {
|
||||
ping_resp pingresp;
|
||||
log_i("round-trip min/avg/max/stddev = %.3f/%.3f/%.3f/%.3f ms\r\n", min_time, mean_time, max_time, sqrt(var_time / received));
|
||||
pingresp.total_count = 10;
|
||||
pingresp.timeout_count = 10;
|
||||
pingresp.total_bytes = 1;
|
||||
pingresp.total_time = mean_time;
|
||||
pingresp.ping_err = 0;
|
||||
return true;
|
||||
// ping_o->sent_function(ping_o, (uint8*)&pingresp);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
bool ping_regist_recv(struct ping_option *ping_opt, ping_recv_function ping_recv)
|
||||
{
|
||||
if (ping_opt == NULL)
|
||||
return false;
|
||||
|
||||
ping_opt->recv_function = ping_recv;
|
||||
return true;
|
||||
}
|
||||
|
||||
bool ping_regist_sent(struct ping_option *ping_opt, ping_sent_function ping_sent)
|
||||
{
|
||||
if (ping_opt == NULL)
|
||||
return false;
|
||||
|
||||
ping_opt->sent_function = ping_sent;
|
||||
return true;
|
||||
}
|
||||
#endif
|
||||
@@ -0,0 +1,36 @@
|
||||
|
||||
#ifndef _PING_
|
||||
#define _PING_
|
||||
#include <Arduino.h>
|
||||
|
||||
#ifdef ESP32
|
||||
|
||||
typedef void(*ping_recv_function)(void* arg, void *pdata);
|
||||
typedef void(*ping_sent_function)(void* arg, void *pdata);
|
||||
|
||||
struct ping_option {
|
||||
uint32_t count;
|
||||
uint32_t ip;
|
||||
uint32_t coarse_time;
|
||||
ping_recv_function recv_function;
|
||||
ping_sent_function sent_function;
|
||||
void* reverse;
|
||||
};
|
||||
|
||||
struct ping_resp {
|
||||
uint32_t total_count;
|
||||
uint32_t resp_time;
|
||||
uint32_t seqno;
|
||||
uint32_t timeout_count;
|
||||
uint32_t bytes;
|
||||
uint32_t total_bytes;
|
||||
uint32_t total_time;
|
||||
int8_t ping_err;
|
||||
};
|
||||
|
||||
bool ping_start(struct ping_option *ping_opt);
|
||||
void ping(const char *name, int count, int interval, int size, int timeout);
|
||||
bool ping_start(IPAddress adr, int count, int interval, int size, int timeout);
|
||||
|
||||
#endif
|
||||
#endif
|
||||
@@ -0,0 +1,241 @@
|
||||
/*
|
||||
|
||||
ESPeasySoftwareSerial.cpp - Implementation of the Arduino software serial for ESP8266.
|
||||
Copyright (c) 2015-2016 Peter Lerup. All rights reserved.
|
||||
|
||||
This library is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU Lesser General Public
|
||||
License as published by the Free Software Foundation; either
|
||||
version 2.1 of the License, or (at your option) any later version.
|
||||
|
||||
This library is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
Lesser General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public
|
||||
License along with this library; if not, write to the Free Software
|
||||
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
|
||||
*/
|
||||
|
||||
#include <Arduino.h>
|
||||
|
||||
// The Arduino standard GPIO routines are not enough,
|
||||
// must use some from the Espressif SDK as well
|
||||
extern "C" {
|
||||
#include "gpio.h"
|
||||
}
|
||||
|
||||
#include <ESPeasySoftwareSerial.h>
|
||||
|
||||
#define MAX_PIN 15
|
||||
#define USABLE_PINS 10
|
||||
#define NR_CONCURRENT_SOFT_SERIALS 3
|
||||
|
||||
// As the Arduino attachInterrupt has no parameter, lists of objects
|
||||
// and callbacks corresponding to each possible GPIO pins have to be defined
|
||||
static ESPeasySoftwareSerial *ObjList[NR_CONCURRENT_SOFT_SERIALS];
|
||||
static uint8_t PinControllerMap[NR_CONCURRENT_SOFT_SERIALS]={}; // Zero all elements
|
||||
|
||||
void ICACHE_RAM_ATTR sws_isr_0() { ObjList[0]->rxRead(); };
|
||||
void ICACHE_RAM_ATTR sws_isr_1() { ObjList[1]->rxRead(); };
|
||||
void ICACHE_RAM_ATTR sws_isr_2() { ObjList[2]->rxRead(); };
|
||||
/*void ICACHE_RAM_ATTR sws_isr_3() { ObjList[3]->rxRead(); };
|
||||
void ICACHE_RAM_ATTR sws_isr_4() { ObjList[4]->rxRead(); };
|
||||
void ICACHE_RAM_ATTR sws_isr_5() { ObjList[5]->rxRead(); };
|
||||
// Pin 6 to 11 can not be used
|
||||
void ICACHE_RAM_ATTR sws_isr_12() { ObjList[6]->rxRead(); };
|
||||
void ICACHE_RAM_ATTR sws_isr_13() { ObjList[7]->rxRead(); };
|
||||
void ICACHE_RAM_ATTR sws_isr_14() { ObjList[8]->rxRead(); };
|
||||
void ICACHE_RAM_ATTR sws_isr_15() { ObjList[9]->rxRead(); };
|
||||
*/
|
||||
|
||||
static void (*ISRList[NR_CONCURRENT_SOFT_SERIALS])() = {
|
||||
sws_isr_0,
|
||||
sws_isr_1,
|
||||
sws_isr_2 /*,
|
||||
sws_isr_3,
|
||||
sws_isr_4,
|
||||
sws_isr_5,
|
||||
// Pin 6 to 11 can not be used
|
||||
sws_isr_12,
|
||||
sws_isr_13,
|
||||
sws_isr_14,
|
||||
sws_isr_15
|
||||
*/
|
||||
};
|
||||
|
||||
ESPeasySoftwareSerial::ESPeasySoftwareSerial(uint8_t receivePin, uint8_t transmitPin, bool inverse_logic, uint16_t buffSize) {
|
||||
m_rxValid = m_txValid = m_txEnableValid = false;
|
||||
m_buffer = NULL;
|
||||
m_invert = inverse_logic;
|
||||
if (isValidGPIOpin(receivePin)) {
|
||||
m_rxPin = receivePin;
|
||||
m_buffSize = buffSize;
|
||||
m_buffer = (uint8_t*)malloc(m_buffSize);
|
||||
if (m_buffer != NULL) {
|
||||
m_rxValid = true;
|
||||
m_inPos = m_outPos = 0;
|
||||
pinMode(m_rxPin, INPUT);
|
||||
const uint8_t index = pinToIndex(m_rxPin);
|
||||
if (index == NR_CONCURRENT_SOFT_SERIALS) {
|
||||
return; // Not possible to add software Serial.
|
||||
}
|
||||
ObjList[index] = this;
|
||||
enableRx(true);
|
||||
}
|
||||
}
|
||||
if (isValidGPIOpin(transmitPin)) {
|
||||
m_txValid = true;
|
||||
m_txPin = transmitPin;
|
||||
pinMode(m_txPin, OUTPUT);
|
||||
digitalWrite(m_txPin, !m_invert);
|
||||
}
|
||||
// Default speed
|
||||
begin(9600);
|
||||
}
|
||||
|
||||
ESPeasySoftwareSerial::~ESPeasySoftwareSerial() {
|
||||
enableRx(false);
|
||||
if (m_rxValid) {
|
||||
const uint8_t index = pinToIndex(m_rxPin);
|
||||
if (index < NR_CONCURRENT_SOFT_SERIALS) {
|
||||
PinControllerMap[index] = 0;
|
||||
ObjList[index] = NULL;
|
||||
}
|
||||
}
|
||||
if (m_buffer)
|
||||
free(m_buffer);
|
||||
}
|
||||
|
||||
bool ESPeasySoftwareSerial::isValidGPIOpin(uint8_t pin) {
|
||||
if (pin >= 0 && pin <= 5) {
|
||||
return true;
|
||||
}
|
||||
if (pin >= 12 && pin <= MAX_PIN) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
uint8_t ESPeasySoftwareSerial::pinToIndex(uint8_t pin) {
|
||||
// Pin will be stored in the map, only "1" will be added,
|
||||
// to allow simple initialize to 0 and still use GPIO-0.
|
||||
const uint8_t stored_pin = pin + 1;
|
||||
for (unsigned i = 0; i < NR_CONCURRENT_SOFT_SERIALS; ++i) {
|
||||
if (PinControllerMap[i] == stored_pin) return i;
|
||||
}
|
||||
// Not found, add as first free option.
|
||||
for (unsigned i = 0; i < NR_CONCURRENT_SOFT_SERIALS; ++i) {
|
||||
if (PinControllerMap[i] == 0) {
|
||||
PinControllerMap[i] = stored_pin;
|
||||
return i;
|
||||
}
|
||||
}
|
||||
// No more controllers available.
|
||||
return NR_CONCURRENT_SOFT_SERIALS;
|
||||
}
|
||||
|
||||
void ESPeasySoftwareSerial::begin(long speed) {
|
||||
// Use getCycleCount() loop to get as exact timing as possible
|
||||
m_bitTime = ESP.getCpuFreqMHz()*1000000/speed;
|
||||
}
|
||||
|
||||
void ESPeasySoftwareSerial::setTransmitEnablePin(uint8_t transmitEnablePin) {
|
||||
if (isValidGPIOpin(transmitEnablePin)) {
|
||||
m_txEnableValid = true;
|
||||
m_txEnablePin = transmitEnablePin;
|
||||
pinMode(m_txEnablePin, OUTPUT);
|
||||
digitalWrite(m_txEnablePin, LOW);
|
||||
} else {
|
||||
m_txEnableValid = false;
|
||||
}
|
||||
}
|
||||
|
||||
void ESPeasySoftwareSerial::enableRx(bool on) {
|
||||
if (m_rxValid) {
|
||||
if (on) {
|
||||
attachInterrupt(m_rxPin, ISRList[pinToIndex(m_rxPin)], m_invert ? RISING : FALLING);
|
||||
} else {
|
||||
detachInterrupt(m_rxPin);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
int ESPeasySoftwareSerial::read() {
|
||||
if (!m_rxValid || (m_inPos == m_outPos)) return -1;
|
||||
uint8_t ch = m_buffer[m_outPos];
|
||||
m_outPos = (m_outPos+1) % m_buffSize;
|
||||
return ch;
|
||||
}
|
||||
|
||||
int ESPeasySoftwareSerial::available() {
|
||||
if (!m_rxValid) return 0;
|
||||
int avail = m_inPos - m_outPos;
|
||||
if (avail < 0) avail += m_buffSize;
|
||||
return avail;
|
||||
}
|
||||
|
||||
#define WAIT { while (ESP.getCycleCount()-start < wait); wait += m_bitTime; }
|
||||
|
||||
size_t ESPeasySoftwareSerial::write(uint8_t b) {
|
||||
if (!m_txValid) return 0;
|
||||
|
||||
if (m_invert) b = ~b;
|
||||
// Disable interrupts in order to get a clean transmit
|
||||
cli();
|
||||
if (m_txEnableValid) digitalWrite(m_txEnablePin, HIGH);
|
||||
unsigned long wait = m_bitTime;
|
||||
digitalWrite(m_txPin, HIGH);
|
||||
unsigned long start = ESP.getCycleCount();
|
||||
// Start bit;
|
||||
digitalWrite(m_txPin, LOW);
|
||||
WAIT;
|
||||
for (int i = 0; i < 8; i++) {
|
||||
digitalWrite(m_txPin, (b & 1) ? HIGH : LOW);
|
||||
WAIT;
|
||||
b >>= 1;
|
||||
}
|
||||
// Stop bit
|
||||
digitalWrite(m_txPin, HIGH);
|
||||
WAIT;
|
||||
if (m_txEnableValid) digitalWrite(m_txEnablePin, LOW);
|
||||
sei();
|
||||
return 1;
|
||||
}
|
||||
|
||||
void ESPeasySoftwareSerial::flush() {
|
||||
m_inPos = m_outPos = 0;
|
||||
}
|
||||
|
||||
int ESPeasySoftwareSerial::peek() {
|
||||
if (!m_rxValid || (m_inPos == m_outPos)) return -1;
|
||||
return m_buffer[m_outPos];
|
||||
}
|
||||
|
||||
void ICACHE_RAM_ATTR ESPeasySoftwareSerial::rxRead() {
|
||||
// Advance the starting point for the samples but compensate for the
|
||||
// initial delay which occurs before the interrupt is delivered
|
||||
unsigned long wait = m_bitTime + m_bitTime/3 - 500;
|
||||
unsigned long start = ESP.getCycleCount();
|
||||
uint8_t rec = 0;
|
||||
for (uint8_t i = 0; i < 8; i++) {
|
||||
WAIT;
|
||||
rec >>= 1;
|
||||
if (digitalRead(m_rxPin))
|
||||
rec |= 0x80;
|
||||
}
|
||||
if (m_invert) rec = ~rec;
|
||||
// Stop bit
|
||||
WAIT;
|
||||
// Store the received value in the buffer unless we have an overflow
|
||||
uint16_t next = (m_inPos+1) % m_buffSize;
|
||||
if (next != m_inPos) {
|
||||
m_buffer[m_inPos] = rec;
|
||||
m_inPos = next;
|
||||
}
|
||||
// Must clear this bit in the interrupt register,
|
||||
// it gets set even when interrupts are disabled
|
||||
GPIO_REG_WRITE(GPIO_STATUS_W1TC_ADDRESS, 1 << m_rxPin);
|
||||
}
|
||||
@@ -0,0 +1,78 @@
|
||||
/*
|
||||
ESPeasySoftwareSerial.h
|
||||
|
||||
ESPeasySoftwareSerial.cpp - Implementation of the Arduino software serial for ESP8266.
|
||||
Copyright (c) 2015-2016 Peter Lerup. All rights reserved.
|
||||
|
||||
This library is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU Lesser General Public
|
||||
License as published by the Free Software Foundation; either
|
||||
version 2.1 of the License, or (at your option) any later version.
|
||||
|
||||
This library is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
Lesser General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public
|
||||
License along with this library; if not, write to the Free Software
|
||||
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
|
||||
*/
|
||||
|
||||
#ifndef ESPeasySoftwareSerial_h
|
||||
#define ESPeasySoftwareSerial_h
|
||||
|
||||
#include <inttypes.h>
|
||||
#include <Stream.h>
|
||||
|
||||
|
||||
// This class is compatible with the corresponding AVR one,
|
||||
// the constructor however has an optional rx buffer size.
|
||||
// Speed up to 115200 can be used.
|
||||
|
||||
|
||||
class ESPeasySoftwareSerial : public Stream
|
||||
{
|
||||
public:
|
||||
ESPeasySoftwareSerial(uint8_t receivePin, uint8_t transmitPin, bool inverse_logic = false, uint16_t buffSize = 64);
|
||||
virtual ~ESPeasySoftwareSerial();
|
||||
|
||||
void begin(long speed);
|
||||
void setTransmitEnablePin(uint8_t transmitEnablePin);
|
||||
|
||||
int peek();
|
||||
|
||||
virtual size_t write(uint8_t byte);
|
||||
virtual int read();
|
||||
virtual int available();
|
||||
virtual void flush();
|
||||
operator bool() {return m_rxValid || m_txValid;}
|
||||
|
||||
// Disable or enable interrupts on the rx pin
|
||||
void enableRx(bool on);
|
||||
|
||||
void rxRead();
|
||||
|
||||
using Print::write;
|
||||
|
||||
private:
|
||||
bool isValidGPIOpin(uint8_t pin);
|
||||
uint8_t pinToIndex(uint8_t pin);
|
||||
|
||||
// Member variables
|
||||
uint8_t m_rxPin, m_txPin, m_txEnablePin;
|
||||
bool m_rxValid, m_txValid, m_txEnableValid;
|
||||
bool m_invert;
|
||||
unsigned long m_bitTime;
|
||||
uint16_t m_inPos, m_outPos;
|
||||
uint16_t m_buffSize;
|
||||
uint8_t *m_buffer;
|
||||
|
||||
};
|
||||
|
||||
// If only one tx or rx wanted then use this as parameter for the unused pin
|
||||
#define SW_SERIAL_UNUSED_PIN -1
|
||||
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,9 @@
|
||||
# ESPeasySoftwareSerial
|
||||
|
||||
Implementation of the Arduino software serial library for the ESP8266
|
||||
|
||||
Same functionality as the corresponding AVR library but several instances can be active at the same time.
|
||||
Speed up to 115200 baud is supported. The constructor also has an optional input buffer size.
|
||||
|
||||
Please note that due to the fact that the ESP always have other activities ongoing, there will be some inexactness in interrupt
|
||||
timings. This may lead to bit errors when having heavy data traffic in high baud rates.
|
||||
@@ -0,0 +1,27 @@
|
||||
|
||||
#include <ESPeasySoftwareSerial.h>
|
||||
|
||||
ESPeasySoftwareSerial swSer(14, 12, false, 256);
|
||||
|
||||
void setup() {
|
||||
Serial.begin(115200);
|
||||
swSer.begin(115200);
|
||||
|
||||
Serial.println("\nSoftware serial test started");
|
||||
|
||||
for (char ch = ' '; ch <= 'z'; ch++) {
|
||||
swSer.write(ch);
|
||||
}
|
||||
swSer.println("");
|
||||
|
||||
}
|
||||
|
||||
void loop() {
|
||||
while (swSer.available() > 0) {
|
||||
Serial.write(swSer.read());
|
||||
}
|
||||
while (Serial.available() > 0) {
|
||||
swSer.write(Serial.read());
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,31 @@
|
||||
#######################################
|
||||
# Syntax Coloring Map for ESPeasySoftwareSerial
|
||||
# (esp8266)
|
||||
#######################################
|
||||
|
||||
#######################################
|
||||
# Datatypes (KEYWORD1)
|
||||
#######################################
|
||||
|
||||
ESPeasySoftwareSerial KEYWORD1
|
||||
|
||||
#######################################
|
||||
# Methods and Functions (KEYWORD2)
|
||||
#######################################
|
||||
|
||||
begin KEYWORD2
|
||||
read KEYWORD2
|
||||
write KEYWORD2
|
||||
available KEYWORD2
|
||||
flush KEYWORD2
|
||||
overflow KEYWORD2
|
||||
peek KEYWORD2
|
||||
listen KEYWORD2
|
||||
end KEYWORD2
|
||||
isListening KEYWORD2
|
||||
stopListening KEYWORD2
|
||||
|
||||
#######################################
|
||||
# Constants (LITERAL1)
|
||||
#######################################
|
||||
|
||||
@@ -0,0 +1,15 @@
|
||||
{
|
||||
"name": "ESPeasySoftwareSerial",
|
||||
"version": "3.3.1",
|
||||
"keywords": [
|
||||
"serial", "io", "softwareserial"
|
||||
],
|
||||
"description": "Implementation of the Arduino software serial for ESP8266. Adjusted to reduce memory footprint for ESPeasy",
|
||||
"repository":
|
||||
{
|
||||
"type": "git",
|
||||
"url": "https://github.com/plerup/espsoftwareserial"
|
||||
},
|
||||
"frameworks": "arduino",
|
||||
"platforms": "espressif8266"
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
name=ESPeasySoftwareSerial
|
||||
version=1.0
|
||||
author=Peter Lerup
|
||||
maintainer=Peter Lerup <peter@lerup.com>
|
||||
sentence=Implementation of the Arduino software serial for ESP8266.
|
||||
paragraph=
|
||||
category=Signal Input/Output
|
||||
url=
|
||||
architectures=esp8266
|
||||
@@ -0,0 +1,456 @@
|
||||
GNU LESSER GENERAL PUBLIC LICENSE
|
||||
Version 2.1, February 1999
|
||||
|
||||
Copyright (C) 1991, 1999 Free Software Foundation, Inc.
|
||||
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
Everyone is permitted to copy and distribute verbatim copies
|
||||
of this license document, but changing it is not allowed.
|
||||
|
||||
[This is the first released version of the Lesser GPL. It also counts
|
||||
as the successor of the GNU Library Public License, version 2, hence
|
||||
the version number 2.1.]
|
||||
|
||||
Preamble
|
||||
|
||||
The licenses for most software are designed to take away your
|
||||
freedom to share and change it. By contrast, the GNU General Public
|
||||
Licenses are intended to guarantee your freedom to share and change
|
||||
free software--to make sure the software is free for all its users.
|
||||
|
||||
This license, the Lesser General Public License, applies to some
|
||||
specially designated software packages--typically libraries--of the
|
||||
Free Software Foundation and other authors who decide to use it. You
|
||||
can use it too, but we suggest you first think carefully about whether
|
||||
this license or the ordinary General Public License is the better
|
||||
strategy to use in any particular case, based on the explanations below.
|
||||
|
||||
When we speak of free software, we are referring to freedom of use,
|
||||
not price. Our General Public Licenses are designed to make sure that
|
||||
you have the freedom to distribute copies of free software (and charge
|
||||
for this service if you wish); that you receive source code or can get
|
||||
it if you want it; that you can change the software and use pieces of
|
||||
it in new free programs; and that you are informed that you can do
|
||||
these things.
|
||||
|
||||
To protect your rights, we need to make restrictions that forbid
|
||||
distributors to deny you these rights or to ask you to surrender these
|
||||
rights. These restrictions translate to certain responsibilities for
|
||||
you if you distribute copies of the library or if you modify it.
|
||||
|
||||
For example, if you distribute copies of the library, whether gratis
|
||||
or for a fee, you must give the recipients all the rights that we gave
|
||||
you. You must make sure that they, too, receive or can get the source
|
||||
code. If you link other code with the library, you must provide
|
||||
complete object files to the recipients, so that they can relink them
|
||||
with the library after making changes to the library and recompiling
|
||||
it. And you must show them these terms so they know their rights.
|
||||
|
||||
We protect your rights with a two-step method: (1) we copyright the
|
||||
library, and (2) we offer you this license, which gives you legal
|
||||
permission to copy, distribute and/or modify the library.
|
||||
|
||||
To protect each distributor, we want to make it very clear that
|
||||
there is no warranty for the free library. Also, if the library is
|
||||
modified by someone else and passed on, the recipients should know
|
||||
that what they have is not the original version, so that the original
|
||||
author's reputation will not be affected by problems that might be
|
||||
introduced by others.
|
||||
|
||||
Finally, software patents pose a constant threat to the existence of
|
||||
any free program. We wish to make sure that a company cannot
|
||||
effectively restrict the users of a free program by obtaining a
|
||||
restrictive license from a patent holder. Therefore, we insist that
|
||||
any patent license obtained for a version of the library must be
|
||||
consistent with the full freedom of use specified in this license.
|
||||
|
||||
Most GNU software, including some libraries, is covered by the
|
||||
ordinary GNU General Public License. This license, the GNU Lesser
|
||||
General Public License, applies to certain designated libraries, and
|
||||
is quite different from the ordinary General Public License. We use
|
||||
this license for certain libraries in order to permit linking those
|
||||
libraries into non-free programs.
|
||||
|
||||
When a program is linked with a library, whether statically or using
|
||||
a shared library, the combination of the two is legally speaking a
|
||||
combined work, a derivative of the original library. The ordinary
|
||||
General Public License therefore permits such linking only if the
|
||||
entire combination fits its criteria of freedom. The Lesser General
|
||||
Public License permits more lax criteria for linking other code with
|
||||
the library.
|
||||
|
||||
We call this license the "Lesser" General Public License because it
|
||||
does Less to protect the user's freedom than the ordinary General
|
||||
Public License. It also provides other free software developers Less
|
||||
of an advantage over competing non-free programs. These disadvantages
|
||||
are the reason we use the ordinary General Public License for many
|
||||
libraries. However, the Lesser license provides advantages in certain
|
||||
special circumstances.
|
||||
|
||||
For example, on rare occasions, there may be a special need to
|
||||
encourage the widest possible use of a certain library, so that it becomes
|
||||
a de-facto standard. To achieve this, non-free programs must be
|
||||
allowed to use the library. A more frequent case is that a free
|
||||
library does the same job as widely used non-free libraries. In this
|
||||
case, there is little to gain by limiting the free library to free
|
||||
software only, so we use the Lesser General Public License.
|
||||
|
||||
In other cases, permission to use a particular library in non-free
|
||||
programs enables a greater number of people to use a large body of
|
||||
free software. For example, permission to use the GNU C Library in
|
||||
non-free programs enables many more people to use the whole GNU
|
||||
operating system, as well as its variant, the GNU/Linux operating
|
||||
system.
|
||||
|
||||
Although the Lesser General Public License is Less protective of the
|
||||
users' freedom, it does ensure that the user of a program that is
|
||||
linked with the Library has the freedom and the wherewithal to run
|
||||
that program using a modified version of the Library.
|
||||
|
||||
The precise terms and conditions for copying, distribution and
|
||||
modification follow. Pay close attention to the difference between a
|
||||
"work based on the library" and a "work that uses the library". The
|
||||
former contains code derived from the library, whereas the latter must
|
||||
be combined with the library in order to run.
|
||||
|
||||
GNU LESSER GENERAL PUBLIC LICENSE
|
||||
TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
|
||||
|
||||
0. This License Agreement applies to any software library or other
|
||||
program which contains a notice placed by the copyright holder or
|
||||
other authorized party saying it may be distributed under the terms of
|
||||
this Lesser General Public License (also called "this License").
|
||||
Each licensee is addressed as "you".
|
||||
|
||||
A "library" means a collection of software functions and/or data
|
||||
prepared so as to be conveniently linked with application programs
|
||||
(which use some of those functions and data) to form executables.
|
||||
|
||||
The "Library", below, refers to any such software library or work
|
||||
which has been distributed under these terms. A "work based on the
|
||||
Library" means either the Library or any derivative work under
|
||||
copyright law: that is to say, a work containing the Library or a
|
||||
portion of it, either verbatim or with modifications and/or translated
|
||||
straightforwardly into another language. (Hereinafter, translation is
|
||||
included without limitation in the term "modification".)
|
||||
|
||||
"Source code" for a work means the preferred form of the work for
|
||||
making modifications to it. For a library, complete source code means
|
||||
all the source code for all modules it contains, plus any associated
|
||||
interface definition files, plus the scripts used to control compilation
|
||||
and installation of the library.
|
||||
|
||||
Activities other than copying, distribution and modification are not
|
||||
covered by this License; they are outside its scope. The act of
|
||||
running a program using the Library is not restricted, and output from
|
||||
such a program is covered only if its contents constitute a work based
|
||||
on the Library (independent of the use of the Library in a tool for
|
||||
writing it). Whether that is true depends on what the Library does
|
||||
and what the program that uses the Library does.
|
||||
|
||||
1. You may copy and distribute verbatim copies of the Library's
|
||||
complete source code as you receive it, in any medium, provided that
|
||||
you conspicuously and appropriately publish on each copy an
|
||||
appropriate copyright notice and disclaimer of warranty; keep intact
|
||||
all the notices that refer to this License and to the absence of any
|
||||
warranty; and distribute a copy of this License along with the
|
||||
Library.
|
||||
|
||||
You may charge a fee for the physical act of transferring a copy,
|
||||
and you may at your option offer warranty protection in exchange for a
|
||||
fee.
|
||||
|
||||
2. You may modify your copy or copies of the Library or any portion
|
||||
of it, thus forming a work based on the Library, and copy and
|
||||
distribute such modifications or work under the terms of Section 1
|
||||
above, provided that you also meet all of these conditions:
|
||||
|
||||
a) The modified work must itself be a software library.
|
||||
|
||||
b) You must cause the files modified to carry prominent notices
|
||||
stating that you changed the files and the date of any change.
|
||||
|
||||
c) You must cause the whole of the work to be licensed at no
|
||||
charge to all third parties under the terms of this License.
|
||||
|
||||
d) If a facility in the modified Library refers to a function or a
|
||||
table of data to be supplied by an application program that uses
|
||||
the facility, other than as an argument passed when the facility
|
||||
is invoked, then you must make a good faith effort to ensure that,
|
||||
in the event an application does not supply such function or
|
||||
table, the facility still operates, and performs whatever part of
|
||||
its purpose remains meaningful.
|
||||
|
||||
(For example, a function in a library to compute square roots has
|
||||
a purpose that is entirely well-defined independent of the
|
||||
application. Therefore, Subsection 2d requires that any
|
||||
application-supplied function or table used by this function must
|
||||
be optional: if the application does not supply it, the square
|
||||
root function must still compute square roots.)
|
||||
|
||||
These requirements apply to the modified work as a whole. If
|
||||
identifiable sections of that work are not derived from the Library,
|
||||
and can be reasonably considered independent and separate works in
|
||||
themselves, then this License, and its terms, do not apply to those
|
||||
sections when you distribute them as separate works. But when you
|
||||
distribute the same sections as part of a whole which is a work based
|
||||
on the Library, the distribution of the whole must be on the terms of
|
||||
this License, whose permissions for other licensees extend to the
|
||||
entire whole, and thus to each and every part regardless of who wrote
|
||||
it.
|
||||
|
||||
Thus, it is not the intent of this section to claim rights or contest
|
||||
your rights to work written entirely by you; rather, the intent is to
|
||||
exercise the right to control the distribution of derivative or
|
||||
collective works based on the Library.
|
||||
|
||||
In addition, mere aggregation of another work not based on the Library
|
||||
with the Library (or with a work based on the Library) on a volume of
|
||||
a storage or distribution medium does not bring the other work under
|
||||
the scope of this License.
|
||||
|
||||
3. You may opt to apply the terms of the ordinary GNU General Public
|
||||
License instead of this License to a given copy of the Library. To do
|
||||
this, you must alter all the notices that refer to this License, so
|
||||
that they refer to the ordinary GNU General Public License, version 2,
|
||||
instead of to this License. (If a newer version than version 2 of the
|
||||
ordinary GNU General Public License has appeared, then you can specify
|
||||
that version instead if you wish.) Do not make any other change in
|
||||
these notices.
|
||||
|
||||
Once this change is made in a given copy, it is irreversible for
|
||||
that copy, so the ordinary GNU General Public License applies to all
|
||||
subsequent copies and derivative works made from that copy.
|
||||
|
||||
This option is useful when you wish to copy part of the code of
|
||||
the Library into a program that is not a library.
|
||||
|
||||
4. You may copy and distribute the Library (or a portion or
|
||||
derivative of it, under Section 2) in object code or executable form
|
||||
under the terms of Sections 1 and 2 above provided that you accompany
|
||||
it with the complete corresponding machine-readable source code, which
|
||||
must be distributed under the terms of Sections 1 and 2 above on a
|
||||
medium customarily used for software interchange.
|
||||
|
||||
If distribution of object code is made by offering access to copy
|
||||
from a designated place, then offering equivalent access to copy the
|
||||
source code from the same place satisfies the requirement to
|
||||
distribute the source code, even though third parties are not
|
||||
compelled to copy the source along with the object code.
|
||||
|
||||
5. A program that contains no derivative of any portion of the
|
||||
Library, but is designed to work with the Library by being compiled or
|
||||
linked with it, is called a "work that uses the Library". Such a
|
||||
work, in isolation, is not a derivative work of the Library, and
|
||||
therefore falls outside the scope of this License.
|
||||
|
||||
However, linking a "work that uses the Library" with the Library
|
||||
creates an executable that is a derivative of the Library (because it
|
||||
contains portions of the Library), rather than a "work that uses the
|
||||
library". The executable is therefore covered by this License.
|
||||
Section 6 states terms for distribution of such executables.
|
||||
|
||||
When a "work that uses the Library" uses material from a header file
|
||||
that is part of the Library, the object code for the work may be a
|
||||
derivative work of the Library even though the source code is not.
|
||||
Whether this is true is especially significant if the work can be
|
||||
linked without the Library, or if the work is itself a library. The
|
||||
threshold for this to be true is not precisely defined by law.
|
||||
|
||||
If such an object file uses only numerical parameters, data
|
||||
structure layouts and accessors, and small macros and small inline
|
||||
functions (ten lines or less in length), then the use of the object
|
||||
file is unrestricted, regardless of whether it is legally a derivative
|
||||
work. (Executables containing this object code plus portions of the
|
||||
Library will still fall under Section 6.)
|
||||
|
||||
Otherwise, if the work is a derivative of the Library, you may
|
||||
distribute the object code for the work under the terms of Section 6.
|
||||
Any executables containing that work also fall under Section 6,
|
||||
whether or not they are linked directly with the Library itself.
|
||||
|
||||
6. As an exception to the Sections above, you may also combine or
|
||||
link a "work that uses the Library" with the Library to produce a
|
||||
work containing portions of the Library, and distribute that work
|
||||
under terms of your choice, provided that the terms permit
|
||||
modification of the work for the customer's own use and reverse
|
||||
engineering for debugging such modifications.
|
||||
|
||||
You must give prominent notice with each copy of the work that the
|
||||
Library is used in it and that the Library and its use are covered by
|
||||
this License. You must supply a copy of this License. If the work
|
||||
during execution displays copyright notices, you must include the
|
||||
copyright notice for the Library among them, as well as a reference
|
||||
directing the user to the copy of this License. Also, you must do one
|
||||
of these things:
|
||||
|
||||
a) Accompany the work with the complete corresponding
|
||||
machine-readable source code for the Library including whatever
|
||||
changes were used in the work (which must be distributed under
|
||||
Sections 1 and 2 above); and, if the work is an executable linked
|
||||
with the Library, with the complete machine-readable "work that
|
||||
uses the Library", as object code and/or source code, so that the
|
||||
user can modify the Library and then relink to produce a modified
|
||||
executable containing the modified Library. (It is understood
|
||||
that the user who changes the contents of definitions files in the
|
||||
Library will not necessarily be able to recompile the application
|
||||
to use the modified definitions.)
|
||||
|
||||
b) Use a suitable shared library mechanism for linking with the
|
||||
Library. A suitable mechanism is one that (1) uses at run time a
|
||||
copy of the library already present on the user's computer system,
|
||||
rather than copying library functions into the executable, and (2)
|
||||
will operate properly with a modified version of the library, if
|
||||
the user installs one, as long as the modified version is
|
||||
interface-compatible with the version that the work was made with.
|
||||
|
||||
c) Accompany the work with a written offer, valid for at
|
||||
least three years, to give the same user the materials
|
||||
specified in Subsection 6a, above, for a charge no more
|
||||
than the cost of performing this distribution.
|
||||
|
||||
d) If distribution of the work is made by offering access to copy
|
||||
from a designated place, offer equivalent access to copy the above
|
||||
specified materials from the same place.
|
||||
|
||||
e) Verify that the user has already received a copy of these
|
||||
materials or that you have already sent this user a copy.
|
||||
|
||||
For an executable, the required form of the "work that uses the
|
||||
Library" must include any data and utility programs needed for
|
||||
reproducing the executable from it. However, as a special exception,
|
||||
the materials to be distributed need not include anything that is
|
||||
normally distributed (in either source or binary form) with the major
|
||||
components (compiler, kernel, and so on) of the operating system on
|
||||
which the executable runs, unless that component itself accompanies
|
||||
the executable.
|
||||
|
||||
It may happen that this requirement contradicts the license
|
||||
restrictions of other proprietary libraries that do not normally
|
||||
accompany the operating system. Such a contradiction means you cannot
|
||||
use both them and the Library together in an executable that you
|
||||
distribute.
|
||||
|
||||
7. You may place library facilities that are a work based on the
|
||||
Library side-by-side in a single library together with other library
|
||||
facilities not covered by this License, and distribute such a combined
|
||||
library, provided that the separate distribution of the work based on
|
||||
the Library and of the other library facilities is otherwise
|
||||
permitted, and provided that you do these two things:
|
||||
|
||||
a) Accompany the combined library with a copy of the same work
|
||||
based on the Library, uncombined with any other library
|
||||
facilities. This must be distributed under the terms of the
|
||||
Sections above.
|
||||
|
||||
b) Give prominent notice with the combined library of the fact
|
||||
that part of it is a work based on the Library, and explaining
|
||||
where to find the accompanying uncombined form of the same work.
|
||||
|
||||
8. You may not copy, modify, sublicense, link with, or distribute
|
||||
the Library except as expressly provided under this License. Any
|
||||
attempt otherwise to copy, modify, sublicense, link with, or
|
||||
distribute the Library is void, and will automatically terminate your
|
||||
rights under this License. However, parties who have received copies,
|
||||
or rights, from you under this License will not have their licenses
|
||||
terminated so long as such parties remain in full compliance.
|
||||
|
||||
9. You are not required to accept this License, since you have not
|
||||
signed it. However, nothing else grants you permission to modify or
|
||||
distribute the Library or its derivative works. These actions are
|
||||
prohibited by law if you do not accept this License. Therefore, by
|
||||
modifying or distributing the Library (or any work based on the
|
||||
Library), you indicate your acceptance of this License to do so, and
|
||||
all its terms and conditions for copying, distributing or modifying
|
||||
the Library or works based on it.
|
||||
|
||||
10. Each time you redistribute the Library (or any work based on the
|
||||
Library), the recipient automatically receives a license from the
|
||||
original licensor to copy, distribute, link with or modify the Library
|
||||
subject to these terms and conditions. You may not impose any further
|
||||
restrictions on the recipients' exercise of the rights granted herein.
|
||||
You are not responsible for enforcing compliance by third parties with
|
||||
this License.
|
||||
|
||||
11. If, as a consequence of a court judgment or allegation of patent
|
||||
infringement or for any other reason (not limited to patent issues),
|
||||
conditions are imposed on you (whether by court order, agreement or
|
||||
otherwise) that contradict the conditions of this License, they do not
|
||||
excuse you from the conditions of this License. If you cannot
|
||||
distribute so as to satisfy simultaneously your obligations under this
|
||||
License and any other pertinent obligations, then as a consequence you
|
||||
may not distribute the Library at all. For example, if a patent
|
||||
license would not permit royalty-free redistribution of the Library by
|
||||
all those who receive copies directly or indirectly through you, then
|
||||
the only way you could satisfy both it and this License would be to
|
||||
refrain entirely from distribution of the Library.
|
||||
|
||||
If any portion of this section is held invalid or unenforceable under any
|
||||
particular circumstance, the balance of the section is intended to apply,
|
||||
and the section as a whole is intended to apply in other circumstances.
|
||||
|
||||
It is not the purpose of this section to induce you to infringe any
|
||||
patents or other property right claims or to contest validity of any
|
||||
such claims; this section has the sole purpose of protecting the
|
||||
integrity of the free software distribution system which is
|
||||
implemented by public license practices. Many people have made
|
||||
generous contributions to the wide range of software distributed
|
||||
through that system in reliance on consistent application of that
|
||||
system; it is up to the author/donor to decide if he or she is willing
|
||||
to distribute software through any other system and a licensee cannot
|
||||
impose that choice.
|
||||
|
||||
This section is intended to make thoroughly clear what is believed to
|
||||
be a consequence of the rest of this License.
|
||||
|
||||
12. If the distribution and/or use of the Library is restricted in
|
||||
certain countries either by patents or by copyrighted interfaces, the
|
||||
original copyright holder who places the Library under this License may add
|
||||
an explicit geographical distribution limitation excluding those countries,
|
||||
so that distribution is permitted only in or among countries not thus
|
||||
excluded. In such case, this License incorporates the limitation as if
|
||||
written in the body of this License.
|
||||
|
||||
13. The Free Software Foundation may publish revised and/or new
|
||||
versions of the Lesser General Public License from time to time.
|
||||
Such new versions will be similar in spirit to the present version,
|
||||
but may differ in detail to address new problems or concerns.
|
||||
|
||||
Each version is given a distinguishing version number. If the Library
|
||||
specifies a version number of this License which applies to it and
|
||||
"any later version", you have the option of following the terms and
|
||||
conditions either of that version or of any later version published by
|
||||
the Free Software Foundation. If the Library does not specify a
|
||||
license version number, you may choose any version ever published by
|
||||
the Free Software Foundation.
|
||||
|
||||
14. If you wish to incorporate parts of the Library into other free
|
||||
programs whose distribution conditions are incompatible with these,
|
||||
write to the author to ask for permission. For software which is
|
||||
copyrighted by the Free Software Foundation, write to the Free
|
||||
Software Foundation; we sometimes make exceptions for this. Our
|
||||
decision will be guided by the two goals of preserving the free status
|
||||
of all derivatives of our free software and of promoting the sharing
|
||||
and reuse of software generally.
|
||||
|
||||
NO WARRANTY
|
||||
|
||||
15. BECAUSE THE LIBRARY IS LICENSED FREE OF CHARGE, THERE IS NO
|
||||
WARRANTY FOR THE LIBRARY, TO THE EXTENT PERMITTED BY APPLICABLE LAW.
|
||||
EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR
|
||||
OTHER PARTIES PROVIDE THE LIBRARY "AS IS" WITHOUT WARRANTY OF ANY
|
||||
KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||
PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE
|
||||
LIBRARY IS WITH YOU. SHOULD THE LIBRARY PROVE DEFECTIVE, YOU ASSUME
|
||||
THE COST OF ALL NECESSARY SERVICING, REPAIR OR CORRECTION.
|
||||
|
||||
16. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN
|
||||
WRITING WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY
|
||||
AND/OR REDISTRIBUTE THE LIBRARY AS PERMITTED ABOVE, BE LIABLE TO YOU
|
||||
FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR
|
||||
CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE THE
|
||||
LIBRARY (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING
|
||||
RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A
|
||||
FAILURE OF THE LIBRARY TO OPERATE WITH ANY OTHER SOFTWARE), EVEN IF
|
||||
SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH
|
||||
DAMAGES.
|
||||
@@ -0,0 +1,40 @@
|
||||
# ESP8266Ping
|
||||
Let the ESP8266 ping a remote machine.
|
||||
|
||||
With this library an ESP8266 can ping a remote machine and know if it's reachable.
|
||||
It provide some basic measurements on ping messages (avg response time).
|
||||
|
||||
## Usage
|
||||
|
||||
First, include the library in your sketch along with WiFi library:
|
||||
|
||||
```Arduino
|
||||
#include <ESP8266WiFi.h>
|
||||
#include <ESP8266Ping.h>
|
||||
```
|
||||
|
||||
Next, simply call the `Ping.ping()` function
|
||||
|
||||
```Arduino
|
||||
IPAddress ip (192, 168, 0, 1); // The remote ip to ping
|
||||
bool ret = Ping.ping(ip);
|
||||
```
|
||||
|
||||
`ret` will be true if the remote responded to pings, false if not reachable.
|
||||
The library supports hostname too, just pass a string instead of the ip address:
|
||||
|
||||
```Arduino
|
||||
bool ret = Ping.ping("www.google.com");
|
||||
```
|
||||
|
||||
Additionally, the function accept a second integer parameter `count` that specify how many pings has to be sent:
|
||||
|
||||
```Arduino
|
||||
bool ret = Ping.ping(ip_or_host, 10);
|
||||
```
|
||||
|
||||
After `Ping.ping()` has been called, the average response time (in milliseconds) can be retrieved with
|
||||
|
||||
```Arduino
|
||||
int avg_time_ms = Ping.averageTime();
|
||||
```
|
||||
@@ -0,0 +1,43 @@
|
||||
/*
|
||||
* This example show how to ping a remote machine using it's hostname
|
||||
*/
|
||||
|
||||
#include <ESP8266WiFi.h>
|
||||
#include <ESP8266Ping.h>
|
||||
|
||||
const char* ssid = "ssid";
|
||||
const char* password = "passphrase";
|
||||
|
||||
const char* remote_host = "www.google.com";
|
||||
|
||||
void setup() {
|
||||
Serial.begin(115200);
|
||||
delay(10);
|
||||
|
||||
// We start by connecting to a WiFi network
|
||||
|
||||
Serial.println();
|
||||
Serial.println("Connecting to WiFi");
|
||||
|
||||
WiFi.begin(ssid, password);
|
||||
|
||||
while (WiFi.status() != WL_CONNECTED) {
|
||||
delay(100);
|
||||
Serial.print(".");
|
||||
}
|
||||
|
||||
Serial.println();
|
||||
Serial.print("WiFi connected with ip ");
|
||||
Serial.println(WiFi.localIP());
|
||||
|
||||
Serial.print("Pinging host ");
|
||||
Serial.println(remote_host);
|
||||
|
||||
if(Ping.ping(remote_host)) {
|
||||
Serial.println("Success!!");
|
||||
} else {
|
||||
Serial.println("Error :(");
|
||||
}
|
||||
}
|
||||
|
||||
void loop() { }
|
||||
@@ -0,0 +1,44 @@
|
||||
/*
|
||||
* With this library an ESP8266 can ping a remote machine and know if it's reachable.
|
||||
* It provides some basic measurements on ping messages (avg response time).
|
||||
*/
|
||||
|
||||
#include <ESP8266WiFi.h>
|
||||
#include <ESP8266Ping.h>
|
||||
|
||||
const char* ssid = "ssid";
|
||||
const char* password = "passphrase";
|
||||
|
||||
const IPAddress remote_ip(192, 168, 0, 1);
|
||||
|
||||
void setup() {
|
||||
Serial.begin(115200);
|
||||
delay(10);
|
||||
|
||||
// We start by connecting to a WiFi network
|
||||
|
||||
Serial.println();
|
||||
Serial.println("Connecting to WiFi");
|
||||
|
||||
WiFi.begin(ssid, password);
|
||||
|
||||
while (WiFi.status() != WL_CONNECTED) {
|
||||
delay(100);
|
||||
Serial.print(".");
|
||||
}
|
||||
|
||||
Serial.println();
|
||||
Serial.print("WiFi connected with ip ");
|
||||
Serial.println(WiFi.localIP());
|
||||
|
||||
Serial.print("Pinging ip ");
|
||||
Serial.println(remote_ip);
|
||||
|
||||
if(Ping.ping(remote_ip)) {
|
||||
Serial.println("Success!!");
|
||||
} else {
|
||||
Serial.println("Error :(");
|
||||
}
|
||||
}
|
||||
|
||||
void loop() { }
|
||||
@@ -0,0 +1,26 @@
|
||||
#######################################
|
||||
# Syntax Coloring Map For ESP8266Ping
|
||||
#######################################
|
||||
|
||||
#######################################
|
||||
# Library (KEYWORD3)
|
||||
#######################################
|
||||
|
||||
ESP8266Ping KEYWORD3
|
||||
|
||||
#######################################
|
||||
# Datatypes (KEYWORD1)
|
||||
#######################################
|
||||
|
||||
Ping KEYWORD1
|
||||
|
||||
#######################################
|
||||
# Methods and Functions (KEYWORD2)
|
||||
#######################################
|
||||
|
||||
ping KEYWORD2
|
||||
|
||||
#######################################
|
||||
# Constants (LITERAL1)
|
||||
#######################################
|
||||
|
||||
@@ -0,0 +1,9 @@
|
||||
name=ESPEasy_ESP8266Ping
|
||||
version=1.0
|
||||
author=Daniele Colanardi
|
||||
maintainer=Daniele Colanardi <dancol90@gmail.com>
|
||||
sentence=Let the ESP8266 ping a remote machine.
|
||||
paragraph=With this library an ESP8266 can ping a remote machine and know if it's reachable. It provide some basic measurements on ping messages (avg response time). Lib name renamed to avoid conflicts in Arduino IDE.
|
||||
category=Communication
|
||||
url=
|
||||
architectures=esp8266
|
||||
@@ -0,0 +1,61 @@
|
||||
/*
|
||||
ESP8266Ping - Ping library for ESP8266
|
||||
Copyright (c) 2015 Daniele Colanardi. All rights reserved.
|
||||
|
||||
This library is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU Lesser General Public
|
||||
License as published by the Free Software Foundation; either
|
||||
version 2.1 of the License, or (at your option) any later version.
|
||||
|
||||
This library is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
Lesser General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public
|
||||
License along with this library; if not, write to the Free Software
|
||||
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
*/
|
||||
|
||||
#ifndef ESP8266Ping_H
|
||||
#define ESP8266Ping_H
|
||||
|
||||
#if defined(ESP8266)
|
||||
#include <Arduino.h>
|
||||
#include <ESP8266WiFi.h>
|
||||
|
||||
extern "C" {
|
||||
#include <ping.h>
|
||||
}
|
||||
|
||||
#ifdef ENABLE_DEBUG_PING
|
||||
#define DEBUG_PING(...) Serial.printf(__VA_ARGS__)
|
||||
#else
|
||||
#define DEBUG_PING(...)
|
||||
#endif
|
||||
|
||||
class PingClass {
|
||||
public:
|
||||
PingClass();
|
||||
|
||||
bool ping(IPAddress dest, byte count = 5);
|
||||
bool ping(const char* host, byte count = 5);
|
||||
|
||||
int averageTime();
|
||||
|
||||
protected:
|
||||
static void _ping_sent_cb(void *opt, void *pdata);
|
||||
static void _ping_recv_cb(void *opt, void *pdata);
|
||||
|
||||
IPAddress _dest;
|
||||
ping_option _options;
|
||||
|
||||
static byte _expected_count, _errors, _success;
|
||||
static int _avg_time;
|
||||
};
|
||||
|
||||
#include "ESP8266Ping.impl.h"
|
||||
PingClass Ping;
|
||||
|
||||
#endif
|
||||
#endif
|
||||
@@ -0,0 +1,112 @@
|
||||
/*
|
||||
ESP8266Ping - Ping library for ESP8266
|
||||
Copyright (c) 2015 Daniele Colanardi. All rights reserved.
|
||||
|
||||
This library is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU Lesser General Public
|
||||
License as published by the Free Software Foundation; either
|
||||
version 2.1 of the License, or (at your option) any later version.
|
||||
|
||||
This library is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
Lesser General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public
|
||||
License along with this library; if not, write to the Free Software
|
||||
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
*/
|
||||
|
||||
|
||||
extern "C" void esp_schedule();
|
||||
extern "C" void esp_yield();
|
||||
|
||||
PingClass::PingClass() {}
|
||||
|
||||
bool PingClass::ping(IPAddress dest, byte count) {
|
||||
_expected_count = count;
|
||||
_errors = 0;
|
||||
_success = 0;
|
||||
|
||||
_avg_time = 0;
|
||||
|
||||
memset(&_options, 0, sizeof(struct ping_option));
|
||||
|
||||
// Repeat count (how many time send a ping message to destination)
|
||||
_options.count = count;
|
||||
// Time interval between two ping (seconds??)
|
||||
_options.coarse_time = 1;
|
||||
// Destination machine
|
||||
_options.ip = dest;
|
||||
|
||||
// Callbacks
|
||||
_options.recv_function = reinterpret_cast<ping_recv_function>(&PingClass::_ping_recv_cb);
|
||||
_options.sent_function = NULL; //reinterpret_cast<ping_sent_function>(&_ping_sent_cb);
|
||||
|
||||
// Let's go!
|
||||
if(ping_start(&_options)) {
|
||||
// Suspend till the process end
|
||||
esp_yield();
|
||||
}
|
||||
|
||||
return (_success > 0);
|
||||
}
|
||||
|
||||
bool PingClass::ping(const char* host, byte count) {
|
||||
IPAddress remote_addr;
|
||||
|
||||
if (WiFi.hostByName(host, remote_addr))
|
||||
return ping(remote_addr, count);
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
int PingClass::averageTime() {
|
||||
return _avg_time;
|
||||
}
|
||||
|
||||
void PingClass::_ping_recv_cb(void *opt, void *resp) {
|
||||
// Cast the parameters to get some usable info
|
||||
ping_resp* ping_resp = reinterpret_cast<struct ping_resp*>(resp);
|
||||
//ping_option* ping_opt = reinterpret_cast<struct ping_option*>(opt);
|
||||
|
||||
// Error or success?
|
||||
if (ping_resp->ping_err == -1)
|
||||
_errors++;
|
||||
else {
|
||||
_success++;
|
||||
_avg_time += ping_resp->resp_time;
|
||||
}
|
||||
|
||||
// Some debug info
|
||||
DEBUG_PING(
|
||||
"DEBUG: ping reply\n"
|
||||
"\ttotal_count = %d \n"
|
||||
"\tresp_time = %d \n"
|
||||
"\tseqno = %d \n"
|
||||
"\ttimeout_count = %d \n"
|
||||
"\tbytes = %d \n"
|
||||
"\ttotal_bytes = %d \n"
|
||||
"\ttotal_time = %d \n"
|
||||
"\tping_err = %d \n",
|
||||
ping_resp->total_count, ping_resp->resp_time, ping_resp->seqno,
|
||||
ping_resp->timeout_count, ping_resp->bytes, ping_resp->total_bytes,
|
||||
ping_resp->total_time, ping_resp->ping_err
|
||||
);
|
||||
|
||||
// Is it time to end?
|
||||
// Don't using seqno because it does not increase on error
|
||||
if (_success + _errors == _expected_count) {
|
||||
_avg_time = _avg_time / _expected_count;
|
||||
|
||||
DEBUG_PING("Avg resp time %d ms\n", _avg_time);
|
||||
|
||||
// Done, return to main functiom
|
||||
esp_schedule();
|
||||
}
|
||||
}
|
||||
|
||||
byte PingClass::_expected_count = 0;
|
||||
byte PingClass::_errors = 0;
|
||||
byte PingClass::_success = 0;
|
||||
int PingClass::_avg_time = 0;
|
||||
@@ -0,0 +1,8 @@
|
||||
# Precompiled Headers
|
||||
*.gch
|
||||
*.pch
|
||||
|
||||
# PlatformIO folders
|
||||
.pioenvs
|
||||
.piolibdeps
|
||||
pio
|
||||
@@ -0,0 +1,39 @@
|
||||
{
|
||||
"name": "HLW8012",
|
||||
"license": "GPL-3.0",
|
||||
"platforms": [
|
||||
"atmelavr",
|
||||
"espressif8266"
|
||||
],
|
||||
"repository": {
|
||||
"url": "https://bitbucket.org/xoseperez/hlw8012.git",
|
||||
"type": "git"
|
||||
},
|
||||
"frameworks": [
|
||||
"arduino"
|
||||
],
|
||||
"version": "1.0.0",
|
||||
"export": {
|
||||
"exclude": "tests"
|
||||
},
|
||||
"examples": [
|
||||
"examples/*/*.ino"
|
||||
],
|
||||
"dependencies": [],
|
||||
"authors": [
|
||||
{
|
||||
"maintainer": true,
|
||||
"name": "Xose Perez",
|
||||
"url": "http://tinkerman.cat",
|
||||
"email": "xose.perez@gmail.com"
|
||||
}
|
||||
],
|
||||
"keywords": [
|
||||
"current",
|
||||
"hlw8012",
|
||||
"power",
|
||||
"voltage"
|
||||
],
|
||||
"id": 1281,
|
||||
"description": "HLW8012 library for Arduino and ESP8266"
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
# HLW8012 change log
|
||||
|
||||
The format is based on [Keep a Changelog](http://keepachangelog.com/)
|
||||
and this project adheres to [Semantic Versioning](http://semver.org/).
|
||||
|
||||
## [1.0.0] 2017-01-13
|
||||
### Added
|
||||
- Added reactive power calculation
|
||||
- Added reset calibration values
|
||||
|
||||
### Fixed
|
||||
- Using volatile for variable inside callbacks
|
||||
|
||||
## [0.1.0] 2016-11-08
|
||||
- Initial working version
|
||||
@@ -0,0 +1,675 @@
|
||||
GNU GENERAL PUBLIC LICENSE
|
||||
Version 3, 29 June 2007
|
||||
|
||||
Copyright (C) 2007 Free Software Foundation, Inc. <http://fsf.org/>
|
||||
Everyone is permitted to copy and distribute verbatim copies
|
||||
of this license document, but changing it is not allowed.
|
||||
|
||||
Preamble
|
||||
|
||||
The GNU General Public License is a free, copyleft license for
|
||||
software and other kinds of works.
|
||||
|
||||
The licenses for most software and other practical works are designed
|
||||
to take away your freedom to share and change the works. By contrast,
|
||||
the GNU General Public License is intended to guarantee your freedom to
|
||||
share and change all versions of a program--to make sure it remains free
|
||||
software for all its users. We, the Free Software Foundation, use the
|
||||
GNU General Public License for most of our software; it applies also to
|
||||
any other work released this way by its authors. You can apply it to
|
||||
your programs, too.
|
||||
|
||||
When we speak of free software, we are referring to freedom, not
|
||||
price. Our General Public Licenses are designed to make sure that you
|
||||
have the freedom to distribute copies of free software (and charge for
|
||||
them if you wish), that you receive source code or can get it if you
|
||||
want it, that you can change the software or use pieces of it in new
|
||||
free programs, and that you know you can do these things.
|
||||
|
||||
To protect your rights, we need to prevent others from denying you
|
||||
these rights or asking you to surrender the rights. Therefore, you have
|
||||
certain responsibilities if you distribute copies of the software, or if
|
||||
you modify it: responsibilities to respect the freedom of others.
|
||||
|
||||
For example, if you distribute copies of such a program, whether
|
||||
gratis or for a fee, you must pass on to the recipients the same
|
||||
freedoms that you received. You must make sure that they, too, receive
|
||||
or can get the source code. And you must show them these terms so they
|
||||
know their rights.
|
||||
|
||||
Developers that use the GNU GPL protect your rights with two steps:
|
||||
(1) assert copyright on the software, and (2) offer you this License
|
||||
giving you legal permission to copy, distribute and/or modify it.
|
||||
|
||||
For the developers' and authors' protection, the GPL clearly explains
|
||||
that there is no warranty for this free software. For both users' and
|
||||
authors' sake, the GPL requires that modified versions be marked as
|
||||
changed, so that their problems will not be attributed erroneously to
|
||||
authors of previous versions.
|
||||
|
||||
Some devices are designed to deny users access to install or run
|
||||
modified versions of the software inside them, although the manufacturer
|
||||
can do so. This is fundamentally incompatible with the aim of
|
||||
protecting users' freedom to change the software. The systematic
|
||||
pattern of such abuse occurs in the area of products for individuals to
|
||||
use, which is precisely where it is most unacceptable. Therefore, we
|
||||
have designed this version of the GPL to prohibit the practice for those
|
||||
products. If such problems arise substantially in other domains, we
|
||||
stand ready to extend this provision to those domains in future versions
|
||||
of the GPL, as needed to protect the freedom of users.
|
||||
|
||||
Finally, every program is threatened constantly by software patents.
|
||||
States should not allow patents to restrict development and use of
|
||||
software on general-purpose computers, but in those that do, we wish to
|
||||
avoid the special danger that patents applied to a free program could
|
||||
make it effectively proprietary. To prevent this, the GPL assures that
|
||||
patents cannot be used to render the program non-free.
|
||||
|
||||
The precise terms and conditions for copying, distribution and
|
||||
modification follow.
|
||||
|
||||
TERMS AND CONDITIONS
|
||||
|
||||
0. Definitions.
|
||||
|
||||
"This License" refers to version 3 of the GNU General Public License.
|
||||
|
||||
"Copyright" also means copyright-like laws that apply to other kinds of
|
||||
works, such as semiconductor masks.
|
||||
|
||||
"The Program" refers to any copyrightable work licensed under this
|
||||
License. Each licensee is addressed as "you". "Licensees" and
|
||||
"recipients" may be individuals or organizations.
|
||||
|
||||
To "modify" a work means to copy from or adapt all or part of the work
|
||||
in a fashion requiring copyright permission, other than the making of an
|
||||
exact copy. The resulting work is called a "modified version" of the
|
||||
earlier work or a work "based on" the earlier work.
|
||||
|
||||
A "covered work" means either the unmodified Program or a work based
|
||||
on the Program.
|
||||
|
||||
To "propagate" a work means to do anything with it that, without
|
||||
permission, would make you directly or secondarily liable for
|
||||
infringement under applicable copyright law, except executing it on a
|
||||
computer or modifying a private copy. Propagation includes copying,
|
||||
distribution (with or without modification), making available to the
|
||||
public, and in some countries other activities as well.
|
||||
|
||||
To "convey" a work means any kind of propagation that enables other
|
||||
parties to make or receive copies. Mere interaction with a user through
|
||||
a computer network, with no transfer of a copy, is not conveying.
|
||||
|
||||
An interactive user interface displays "Appropriate Legal Notices"
|
||||
to the extent that it includes a convenient and prominently visible
|
||||
feature that (1) displays an appropriate copyright notice, and (2)
|
||||
tells the user that there is no warranty for the work (except to the
|
||||
extent that warranties are provided), that licensees may convey the
|
||||
work under this License, and how to view a copy of this License. If
|
||||
the interface presents a list of user commands or options, such as a
|
||||
menu, a prominent item in the list meets this criterion.
|
||||
|
||||
1. Source Code.
|
||||
|
||||
The "source code" for a work means the preferred form of the work
|
||||
for making modifications to it. "Object code" means any non-source
|
||||
form of a work.
|
||||
|
||||
A "Standard Interface" means an interface that either is an official
|
||||
standard defined by a recognized standards body, or, in the case of
|
||||
interfaces specified for a particular programming language, one that
|
||||
is widely used among developers working in that language.
|
||||
|
||||
The "System Libraries" of an executable work include anything, other
|
||||
than the work as a whole, that (a) is included in the normal form of
|
||||
packaging a Major Component, but which is not part of that Major
|
||||
Component, and (b) serves only to enable use of the work with that
|
||||
Major Component, or to implement a Standard Interface for which an
|
||||
implementation is available to the public in source code form. A
|
||||
"Major Component", in this context, means a major essential component
|
||||
(kernel, window system, and so on) of the specific operating system
|
||||
(if any) on which the executable work runs, or a compiler used to
|
||||
produce the work, or an object code interpreter used to run it.
|
||||
|
||||
The "Corresponding Source" for a work in object code form means all
|
||||
the source code needed to generate, install, and (for an executable
|
||||
work) run the object code and to modify the work, including scripts to
|
||||
control those activities. However, it does not include the work's
|
||||
System Libraries, or general-purpose tools or generally available free
|
||||
programs which are used unmodified in performing those activities but
|
||||
which are not part of the work. For example, Corresponding Source
|
||||
includes interface definition files associated with source files for
|
||||
the work, and the source code for shared libraries and dynamically
|
||||
linked subprograms that the work is specifically designed to require,
|
||||
such as by intimate data communication or control flow between those
|
||||
subprograms and other parts of the work.
|
||||
|
||||
The Corresponding Source need not include anything that users
|
||||
can regenerate automatically from other parts of the Corresponding
|
||||
Source.
|
||||
|
||||
The Corresponding Source for a work in source code form is that
|
||||
same work.
|
||||
|
||||
2. Basic Permissions.
|
||||
|
||||
All rights granted under this License are granted for the term of
|
||||
copyright on the Program, and are irrevocable provided the stated
|
||||
conditions are met. This License explicitly affirms your unlimited
|
||||
permission to run the unmodified Program. The output from running a
|
||||
covered work is covered by this License only if the output, given its
|
||||
content, constitutes a covered work. This License acknowledges your
|
||||
rights of fair use or other equivalent, as provided by copyright law.
|
||||
|
||||
You may make, run and propagate covered works that you do not
|
||||
convey, without conditions so long as your license otherwise remains
|
||||
in force. You may convey covered works to others for the sole purpose
|
||||
of having them make modifications exclusively for you, or provide you
|
||||
with facilities for running those works, provided that you comply with
|
||||
the terms of this License in conveying all material for which you do
|
||||
not control copyright. Those thus making or running the covered works
|
||||
for you must do so exclusively on your behalf, under your direction
|
||||
and control, on terms that prohibit them from making any copies of
|
||||
your copyrighted material outside their relationship with you.
|
||||
|
||||
Conveying under any other circumstances is permitted solely under
|
||||
the conditions stated below. Sublicensing is not allowed; section 10
|
||||
makes it unnecessary.
|
||||
|
||||
3. Protecting Users' Legal Rights From Anti-Circumvention Law.
|
||||
|
||||
No covered work shall be deemed part of an effective technological
|
||||
measure under any applicable law fulfilling obligations under article
|
||||
11 of the WIPO copyright treaty adopted on 20 December 1996, or
|
||||
similar laws prohibiting or restricting circumvention of such
|
||||
measures.
|
||||
|
||||
When you convey a covered work, you waive any legal power to forbid
|
||||
circumvention of technological measures to the extent such circumvention
|
||||
is effected by exercising rights under this License with respect to
|
||||
the covered work, and you disclaim any intention to limit operation or
|
||||
modification of the work as a means of enforcing, against the work's
|
||||
users, your or third parties' legal rights to forbid circumvention of
|
||||
technological measures.
|
||||
|
||||
4. Conveying Verbatim Copies.
|
||||
|
||||
You may convey verbatim copies of the Program's source code as you
|
||||
receive it, in any medium, provided that you conspicuously and
|
||||
appropriately publish on each copy an appropriate copyright notice;
|
||||
keep intact all notices stating that this License and any
|
||||
non-permissive terms added in accord with section 7 apply to the code;
|
||||
keep intact all notices of the absence of any warranty; and give all
|
||||
recipients a copy of this License along with the Program.
|
||||
|
||||
You may charge any price or no price for each copy that you convey,
|
||||
and you may offer support or warranty protection for a fee.
|
||||
|
||||
5. Conveying Modified Source Versions.
|
||||
|
||||
You may convey a work based on the Program, or the modifications to
|
||||
produce it from the Program, in the form of source code under the
|
||||
terms of section 4, provided that you also meet all of these conditions:
|
||||
|
||||
a) The work must carry prominent notices stating that you modified
|
||||
it, and giving a relevant date.
|
||||
|
||||
b) The work must carry prominent notices stating that it is
|
||||
released under this License and any conditions added under section
|
||||
7. This requirement modifies the requirement in section 4 to
|
||||
"keep intact all notices".
|
||||
|
||||
c) You must license the entire work, as a whole, under this
|
||||
License to anyone who comes into possession of a copy. This
|
||||
License will therefore apply, along with any applicable section 7
|
||||
additional terms, to the whole of the work, and all its parts,
|
||||
regardless of how they are packaged. This License gives no
|
||||
permission to license the work in any other way, but it does not
|
||||
invalidate such permission if you have separately received it.
|
||||
|
||||
d) If the work has interactive user interfaces, each must display
|
||||
Appropriate Legal Notices; however, if the Program has interactive
|
||||
interfaces that do not display Appropriate Legal Notices, your
|
||||
work need not make them do so.
|
||||
|
||||
A compilation of a covered work with other separate and independent
|
||||
works, which are not by their nature extensions of the covered work,
|
||||
and which are not combined with it such as to form a larger program,
|
||||
in or on a volume of a storage or distribution medium, is called an
|
||||
"aggregate" if the compilation and its resulting copyright are not
|
||||
used to limit the access or legal rights of the compilation's users
|
||||
beyond what the individual works permit. Inclusion of a covered work
|
||||
in an aggregate does not cause this License to apply to the other
|
||||
parts of the aggregate.
|
||||
|
||||
6. Conveying Non-Source Forms.
|
||||
|
||||
You may convey a covered work in object code form under the terms
|
||||
of sections 4 and 5, provided that you also convey the
|
||||
machine-readable Corresponding Source under the terms of this License,
|
||||
in one of these ways:
|
||||
|
||||
a) Convey the object code in, or embodied in, a physical product
|
||||
(including a physical distribution medium), accompanied by the
|
||||
Corresponding Source fixed on a durable physical medium
|
||||
customarily used for software interchange.
|
||||
|
||||
b) Convey the object code in, or embodied in, a physical product
|
||||
(including a physical distribution medium), accompanied by a
|
||||
written offer, valid for at least three years and valid for as
|
||||
long as you offer spare parts or customer support for that product
|
||||
model, to give anyone who possesses the object code either (1) a
|
||||
copy of the Corresponding Source for all the software in the
|
||||
product that is covered by this License, on a durable physical
|
||||
medium customarily used for software interchange, for a price no
|
||||
more than your reasonable cost of physically performing this
|
||||
conveying of source, or (2) access to copy the
|
||||
Corresponding Source from a network server at no charge.
|
||||
|
||||
c) Convey individual copies of the object code with a copy of the
|
||||
written offer to provide the Corresponding Source. This
|
||||
alternative is allowed only occasionally and noncommercially, and
|
||||
only if you received the object code with such an offer, in accord
|
||||
with subsection 6b.
|
||||
|
||||
d) Convey the object code by offering access from a designated
|
||||
place (gratis or for a charge), and offer equivalent access to the
|
||||
Corresponding Source in the same way through the same place at no
|
||||
further charge. You need not require recipients to copy the
|
||||
Corresponding Source along with the object code. If the place to
|
||||
copy the object code is a network server, the Corresponding Source
|
||||
may be on a different server (operated by you or a third party)
|
||||
that supports equivalent copying facilities, provided you maintain
|
||||
clear directions next to the object code saying where to find the
|
||||
Corresponding Source. Regardless of what server hosts the
|
||||
Corresponding Source, you remain obligated to ensure that it is
|
||||
available for as long as needed to satisfy these requirements.
|
||||
|
||||
e) Convey the object code using peer-to-peer transmission, provided
|
||||
you inform other peers where the object code and Corresponding
|
||||
Source of the work are being offered to the general public at no
|
||||
charge under subsection 6d.
|
||||
|
||||
A separable portion of the object code, whose source code is excluded
|
||||
from the Corresponding Source as a System Library, need not be
|
||||
included in conveying the object code work.
|
||||
|
||||
A "User Product" is either (1) a "consumer product", which means any
|
||||
tangible personal property which is normally used for personal, family,
|
||||
or household purposes, or (2) anything designed or sold for incorporation
|
||||
into a dwelling. In determining whether a product is a consumer product,
|
||||
doubtful cases shall be resolved in favor of coverage. For a particular
|
||||
product received by a particular user, "normally used" refers to a
|
||||
typical or common use of that class of product, regardless of the status
|
||||
of the particular user or of the way in which the particular user
|
||||
actually uses, or expects or is expected to use, the product. A product
|
||||
is a consumer product regardless of whether the product has substantial
|
||||
commercial, industrial or non-consumer uses, unless such uses represent
|
||||
the only significant mode of use of the product.
|
||||
|
||||
"Installation Information" for a User Product means any methods,
|
||||
procedures, authorization keys, or other information required to install
|
||||
and execute modified versions of a covered work in that User Product from
|
||||
a modified version of its Corresponding Source. The information must
|
||||
suffice to ensure that the continued functioning of the modified object
|
||||
code is in no case prevented or interfered with solely because
|
||||
modification has been made.
|
||||
|
||||
If you convey an object code work under this section in, or with, or
|
||||
specifically for use in, a User Product, and the conveying occurs as
|
||||
part of a transaction in which the right of possession and use of the
|
||||
User Product is transferred to the recipient in perpetuity or for a
|
||||
fixed term (regardless of how the transaction is characterized), the
|
||||
Corresponding Source conveyed under this section must be accompanied
|
||||
by the Installation Information. But this requirement does not apply
|
||||
if neither you nor any third party retains the ability to install
|
||||
modified object code on the User Product (for example, the work has
|
||||
been installed in ROM).
|
||||
|
||||
The requirement to provide Installation Information does not include a
|
||||
requirement to continue to provide support service, warranty, or updates
|
||||
for a work that has been modified or installed by the recipient, or for
|
||||
the User Product in which it has been modified or installed. Access to a
|
||||
network may be denied when the modification itself materially and
|
||||
adversely affects the operation of the network or violates the rules and
|
||||
protocols for communication across the network.
|
||||
|
||||
Corresponding Source conveyed, and Installation Information provided,
|
||||
in accord with this section must be in a format that is publicly
|
||||
documented (and with an implementation available to the public in
|
||||
source code form), and must require no special password or key for
|
||||
unpacking, reading or copying.
|
||||
|
||||
7. Additional Terms.
|
||||
|
||||
"Additional permissions" are terms that supplement the terms of this
|
||||
License by making exceptions from one or more of its conditions.
|
||||
Additional permissions that are applicable to the entire Program shall
|
||||
be treated as though they were included in this License, to the extent
|
||||
that they are valid under applicable law. If additional permissions
|
||||
apply only to part of the Program, that part may be used separately
|
||||
under those permissions, but the entire Program remains governed by
|
||||
this License without regard to the additional permissions.
|
||||
|
||||
When you convey a copy of a covered work, you may at your option
|
||||
remove any additional permissions from that copy, or from any part of
|
||||
it. (Additional permissions may be written to require their own
|
||||
removal in certain cases when you modify the work.) You may place
|
||||
additional permissions on material, added by you to a covered work,
|
||||
for which you have or can give appropriate copyright permission.
|
||||
|
||||
Notwithstanding any other provision of this License, for material you
|
||||
add to a covered work, you may (if authorized by the copyright holders of
|
||||
that material) supplement the terms of this License with terms:
|
||||
|
||||
a) Disclaiming warranty or limiting liability differently from the
|
||||
terms of sections 15 and 16 of this License; or
|
||||
|
||||
b) Requiring preservation of specified reasonable legal notices or
|
||||
author attributions in that material or in the Appropriate Legal
|
||||
Notices displayed by works containing it; or
|
||||
|
||||
c) Prohibiting misrepresentation of the origin of that material, or
|
||||
requiring that modified versions of such material be marked in
|
||||
reasonable ways as different from the original version; or
|
||||
|
||||
d) Limiting the use for publicity purposes of names of licensors or
|
||||
authors of the material; or
|
||||
|
||||
e) Declining to grant rights under trademark law for use of some
|
||||
trade names, trademarks, or service marks; or
|
||||
|
||||
f) Requiring indemnification of licensors and authors of that
|
||||
material by anyone who conveys the material (or modified versions of
|
||||
it) with contractual assumptions of liability to the recipient, for
|
||||
any liability that these contractual assumptions directly impose on
|
||||
those licensors and authors.
|
||||
|
||||
All other non-permissive additional terms are considered "further
|
||||
restrictions" within the meaning of section 10. If the Program as you
|
||||
received it, or any part of it, contains a notice stating that it is
|
||||
governed by this License along with a term that is a further
|
||||
restriction, you may remove that term. If a license document contains
|
||||
a further restriction but permits relicensing or conveying under this
|
||||
License, you may add to a covered work material governed by the terms
|
||||
of that license document, provided that the further restriction does
|
||||
not survive such relicensing or conveying.
|
||||
|
||||
If you add terms to a covered work in accord with this section, you
|
||||
must place, in the relevant source files, a statement of the
|
||||
additional terms that apply to those files, or a notice indicating
|
||||
where to find the applicable terms.
|
||||
|
||||
Additional terms, permissive or non-permissive, may be stated in the
|
||||
form of a separately written license, or stated as exceptions;
|
||||
the above requirements apply either way.
|
||||
|
||||
8. Termination.
|
||||
|
||||
You may not propagate or modify a covered work except as expressly
|
||||
provided under this License. Any attempt otherwise to propagate or
|
||||
modify it is void, and will automatically terminate your rights under
|
||||
this License (including any patent licenses granted under the third
|
||||
paragraph of section 11).
|
||||
|
||||
However, if you cease all violation of this License, then your
|
||||
license from a particular copyright holder is reinstated (a)
|
||||
provisionally, unless and until the copyright holder explicitly and
|
||||
finally terminates your license, and (b) permanently, if the copyright
|
||||
holder fails to notify you of the violation by some reasonable means
|
||||
prior to 60 days after the cessation.
|
||||
|
||||
Moreover, your license from a particular copyright holder is
|
||||
reinstated permanently if the copyright holder notifies you of the
|
||||
violation by some reasonable means, this is the first time you have
|
||||
received notice of violation of this License (for any work) from that
|
||||
copyright holder, and you cure the violation prior to 30 days after
|
||||
your receipt of the notice.
|
||||
|
||||
Termination of your rights under this section does not terminate the
|
||||
licenses of parties who have received copies or rights from you under
|
||||
this License. If your rights have been terminated and not permanently
|
||||
reinstated, you do not qualify to receive new licenses for the same
|
||||
material under section 10.
|
||||
|
||||
9. Acceptance Not Required for Having Copies.
|
||||
|
||||
You are not required to accept this License in order to receive or
|
||||
run a copy of the Program. Ancillary propagation of a covered work
|
||||
occurring solely as a consequence of using peer-to-peer transmission
|
||||
to receive a copy likewise does not require acceptance. However,
|
||||
nothing other than this License grants you permission to propagate or
|
||||
modify any covered work. These actions infringe copyright if you do
|
||||
not accept this License. Therefore, by modifying or propagating a
|
||||
covered work, you indicate your acceptance of this License to do so.
|
||||
|
||||
10. Automatic Licensing of Downstream Recipients.
|
||||
|
||||
Each time you convey a covered work, the recipient automatically
|
||||
receives a license from the original licensors, to run, modify and
|
||||
propagate that work, subject to this License. You are not responsible
|
||||
for enforcing compliance by third parties with this License.
|
||||
|
||||
An "entity transaction" is a transaction transferring control of an
|
||||
organization, or substantially all assets of one, or subdividing an
|
||||
organization, or merging organizations. If propagation of a covered
|
||||
work results from an entity transaction, each party to that
|
||||
transaction who receives a copy of the work also receives whatever
|
||||
licenses to the work the party's predecessor in interest had or could
|
||||
give under the previous paragraph, plus a right to possession of the
|
||||
Corresponding Source of the work from the predecessor in interest, if
|
||||
the predecessor has it or can get it with reasonable efforts.
|
||||
|
||||
You may not impose any further restrictions on the exercise of the
|
||||
rights granted or affirmed under this License. For example, you may
|
||||
not impose a license fee, royalty, or other charge for exercise of
|
||||
rights granted under this License, and you may not initiate litigation
|
||||
(including a cross-claim or counterclaim in a lawsuit) alleging that
|
||||
any patent claim is infringed by making, using, selling, offering for
|
||||
sale, or importing the Program or any portion of it.
|
||||
|
||||
11. Patents.
|
||||
|
||||
A "contributor" is a copyright holder who authorizes use under this
|
||||
License of the Program or a work on which the Program is based. The
|
||||
work thus licensed is called the contributor's "contributor version".
|
||||
|
||||
A contributor's "essential patent claims" are all patent claims
|
||||
owned or controlled by the contributor, whether already acquired or
|
||||
hereafter acquired, that would be infringed by some manner, permitted
|
||||
by this License, of making, using, or selling its contributor version,
|
||||
but do not include claims that would be infringed only as a
|
||||
consequence of further modification of the contributor version. For
|
||||
purposes of this definition, "control" includes the right to grant
|
||||
patent sublicenses in a manner consistent with the requirements of
|
||||
this License.
|
||||
|
||||
Each contributor grants you a non-exclusive, worldwide, royalty-free
|
||||
patent license under the contributor's essential patent claims, to
|
||||
make, use, sell, offer for sale, import and otherwise run, modify and
|
||||
propagate the contents of its contributor version.
|
||||
|
||||
In the following three paragraphs, a "patent license" is any express
|
||||
agreement or commitment, however denominated, not to enforce a patent
|
||||
(such as an express permission to practice a patent or covenant not to
|
||||
sue for patent infringement). To "grant" such a patent license to a
|
||||
party means to make such an agreement or commitment not to enforce a
|
||||
patent against the party.
|
||||
|
||||
If you convey a covered work, knowingly relying on a patent license,
|
||||
and the Corresponding Source of the work is not available for anyone
|
||||
to copy, free of charge and under the terms of this License, through a
|
||||
publicly available network server or other readily accessible means,
|
||||
then you must either (1) cause the Corresponding Source to be so
|
||||
available, or (2) arrange to deprive yourself of the benefit of the
|
||||
patent license for this particular work, or (3) arrange, in a manner
|
||||
consistent with the requirements of this License, to extend the patent
|
||||
license to downstream recipients. "Knowingly relying" means you have
|
||||
actual knowledge that, but for the patent license, your conveying the
|
||||
covered work in a country, or your recipient's use of the covered work
|
||||
in a country, would infringe one or more identifiable patents in that
|
||||
country that you have reason to believe are valid.
|
||||
|
||||
If, pursuant to or in connection with a single transaction or
|
||||
arrangement, you convey, or propagate by procuring conveyance of, a
|
||||
covered work, and grant a patent license to some of the parties
|
||||
receiving the covered work authorizing them to use, propagate, modify
|
||||
or convey a specific copy of the covered work, then the patent license
|
||||
you grant is automatically extended to all recipients of the covered
|
||||
work and works based on it.
|
||||
|
||||
A patent license is "discriminatory" if it does not include within
|
||||
the scope of its coverage, prohibits the exercise of, or is
|
||||
conditioned on the non-exercise of one or more of the rights that are
|
||||
specifically granted under this License. You may not convey a covered
|
||||
work if you are a party to an arrangement with a third party that is
|
||||
in the business of distributing software, under which you make payment
|
||||
to the third party based on the extent of your activity of conveying
|
||||
the work, and under which the third party grants, to any of the
|
||||
parties who would receive the covered work from you, a discriminatory
|
||||
patent license (a) in connection with copies of the covered work
|
||||
conveyed by you (or copies made from those copies), or (b) primarily
|
||||
for and in connection with specific products or compilations that
|
||||
contain the covered work, unless you entered into that arrangement,
|
||||
or that patent license was granted, prior to 28 March 2007.
|
||||
|
||||
Nothing in this License shall be construed as excluding or limiting
|
||||
any implied license or other defenses to infringement that may
|
||||
otherwise be available to you under applicable patent law.
|
||||
|
||||
12. No Surrender of Others' Freedom.
|
||||
|
||||
If conditions are imposed on you (whether by court order, agreement or
|
||||
otherwise) that contradict the conditions of this License, they do not
|
||||
excuse you from the conditions of this License. If you cannot convey a
|
||||
covered work so as to satisfy simultaneously your obligations under this
|
||||
License and any other pertinent obligations, then as a consequence you may
|
||||
not convey it at all. For example, if you agree to terms that obligate you
|
||||
to collect a royalty for further conveying from those to whom you convey
|
||||
the Program, the only way you could satisfy both those terms and this
|
||||
License would be to refrain entirely from conveying the Program.
|
||||
|
||||
13. Use with the GNU Affero General Public License.
|
||||
|
||||
Notwithstanding any other provision of this License, you have
|
||||
permission to link or combine any covered work with a work licensed
|
||||
under version 3 of the GNU Affero General Public License into a single
|
||||
combined work, and to convey the resulting work. The terms of this
|
||||
License will continue to apply to the part which is the covered work,
|
||||
but the special requirements of the GNU Affero General Public License,
|
||||
section 13, concerning interaction through a network will apply to the
|
||||
combination as such.
|
||||
|
||||
14. Revised Versions of this License.
|
||||
|
||||
The Free Software Foundation may publish revised and/or new versions of
|
||||
the GNU General Public License from time to time. Such new versions will
|
||||
be similar in spirit to the present version, but may differ in detail to
|
||||
address new problems or concerns.
|
||||
|
||||
Each version is given a distinguishing version number. If the
|
||||
Program specifies that a certain numbered version of the GNU General
|
||||
Public License "or any later version" applies to it, you have the
|
||||
option of following the terms and conditions either of that numbered
|
||||
version or of any later version published by the Free Software
|
||||
Foundation. If the Program does not specify a version number of the
|
||||
GNU General Public License, you may choose any version ever published
|
||||
by the Free Software Foundation.
|
||||
|
||||
If the Program specifies that a proxy can decide which future
|
||||
versions of the GNU General Public License can be used, that proxy's
|
||||
public statement of acceptance of a version permanently authorizes you
|
||||
to choose that version for the Program.
|
||||
|
||||
Later license versions may give you additional or different
|
||||
permissions. However, no additional obligations are imposed on any
|
||||
author or copyright holder as a result of your choosing to follow a
|
||||
later version.
|
||||
|
||||
15. Disclaimer of Warranty.
|
||||
|
||||
THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY
|
||||
APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT
|
||||
HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY
|
||||
OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO,
|
||||
THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||
PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM
|
||||
IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF
|
||||
ALL NECESSARY SERVICING, REPAIR OR CORRECTION.
|
||||
|
||||
16. Limitation of Liability.
|
||||
|
||||
IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
|
||||
WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS
|
||||
THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY
|
||||
GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE
|
||||
USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF
|
||||
DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD
|
||||
PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS),
|
||||
EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF
|
||||
SUCH DAMAGES.
|
||||
|
||||
17. Interpretation of Sections 15 and 16.
|
||||
|
||||
If the disclaimer of warranty and limitation of liability provided
|
||||
above cannot be given local legal effect according to their terms,
|
||||
reviewing courts shall apply local law that most closely approximates
|
||||
an absolute waiver of all civil liability in connection with the
|
||||
Program, unless a warranty or assumption of liability accompanies a
|
||||
copy of the Program in return for a fee.
|
||||
|
||||
END OF TERMS AND CONDITIONS
|
||||
|
||||
How to Apply These Terms to Your New Programs
|
||||
|
||||
If you develop a new program, and you want it to be of the greatest
|
||||
possible use to the public, the best way to achieve this is to make it
|
||||
free software which everyone can redistribute and change under these terms.
|
||||
|
||||
To do so, attach the following notices to the program. It is safest
|
||||
to attach them to the start of each source file to most effectively
|
||||
state the exclusion of warranty; and each file should have at least
|
||||
the "copyright" line and a pointer to where the full notice is found.
|
||||
|
||||
<one line to give the program's name and a brief idea of what it does.>
|
||||
Copyright (C) <year> <name of author>
|
||||
|
||||
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 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
Also add information on how to contact you by electronic and paper mail.
|
||||
|
||||
If the program does terminal interaction, make it output a short
|
||||
notice like this when it starts in an interactive mode:
|
||||
|
||||
<program> Copyright (C) <year> <name of author>
|
||||
This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
|
||||
This is free software, and you are welcome to redistribute it
|
||||
under certain conditions; type `show c' for details.
|
||||
|
||||
The hypothetical commands `show w' and `show c' should show the appropriate
|
||||
parts of the General Public License. Of course, your program's commands
|
||||
might be different; for a GUI interface, you would use an "about box".
|
||||
|
||||
You should also get your employer (if you work as a programmer) or school,
|
||||
if any, to sign a "copyright disclaimer" for the program, if necessary.
|
||||
For more information on this, and how to apply and follow the GNU GPL, see
|
||||
<http://www.gnu.org/licenses/>.
|
||||
|
||||
The GNU General Public License does not permit incorporating your program
|
||||
into proprietary programs. If your program is a subroutine library, you
|
||||
may consider it more useful to permit linking proprietary applications with
|
||||
the library. If this is what you want to do, use the GNU Lesser General
|
||||
Public License instead of this License. But first, please read
|
||||
<http://www.gnu.org/philosophy/why-not-lgpl.html>.
|
||||
|
||||
@@ -0,0 +1,62 @@
|
||||
# HLW8012
|
||||
|
||||
HLW8012 library for Arduino and ESP8266 using the [Arduino Core for ESP8266][1].
|
||||
|
||||

|
||||
|
||||
|
||||
This is the IC present in some chinese products like [Itead's Sonoff POW][2].
|
||||
The HLW8012 is a current, voltage and power monitor IC that outputs a pulse of a frequency inversely proportional to the value to be read.
|
||||
This IC provides two PWM outputs, the first one for power and the second one for current or voltage, depending on the SEL pin. The output values are always RMS. Power measurements are very consistent but current or voltage measurements require a minimum time lapse after changing the SEL pin value to become stable. This fact reduces sampling frequency.
|
||||
Higher values (of power, current or voltage) mean shorter pulses.
|
||||
|
||||
Typical values are:
|
||||
|
||||
* A 1Hz pulse on CF pin means around 12W RMS
|
||||
* A 1Hz pulse on CF1 pin means 15mA or 0.5V RMS depending on the value in SEL pin
|
||||
|
||||
These ratios are per datasheet typical application, but the actual circuitry might be different.
|
||||
Even if the circuit matches that on the datasheet the IC tolerances are quite loosy (+-15% for clock frequency, for instance).
|
||||
|
||||
## Features
|
||||
|
||||
The main features of the HLW8012 library are:
|
||||
|
||||
* Two available modes: interrupt-driven or non-interrupt-driven.
|
||||
* Default calibration based on product datasheet (3.1 Typical Applications).
|
||||
* You can specify the resistor values for your circuit.
|
||||
* Optional manual calibration based on expected values.
|
||||
|
||||
## Usage
|
||||
|
||||
Check the examples for indications on how to use the library.
|
||||
|
||||
### Interrupt driven mode
|
||||
|
||||
When using interrupts, values are monitored in the background. When calling the get***() methods the last sampled value is returned, this value might be up to a few seconds old if they are very low values. This is specially obvious when switching off the load. The new value of 0W or 0mA is ideally represented by infinite-length pulses. That means that the interrupt is not triggered, the value does not get updated and it will only timeout after 2 seconds (configurable through the pulse_timeout parameter in the begin() method). During that time lapse the library will still return the last non-zero value.
|
||||
|
||||
### Non interrupt mode
|
||||
|
||||
On the other hand, when not using interrupts, you have to let some time for the pulses in CF1 to stabilize before reading the value. So after calling setMode or toggleMode leave 2 seconds minimum before calling the get methods. The get method for the current mode will measure the pulse width and return the corresponding value, the other one will return the cached value (or 0 if none).
|
||||
|
||||
Use non-interrupt approach and a low pulse_timeout (200ms) only if you are deploying a battery powered device and you care more about your device power consumption than about precission. But then you should know the HLW8012 takes about 15mW...
|
||||
|
||||
### Notes
|
||||
|
||||
I've put together this library after doing a lot of tests with a Sonoff POW[2]. The HLW8012 datasheet (in the "docs" folder) gives some information but I couldn't find any about this issue in the CF1 line that requires some time for the pulse length to stabilize (apparently). Any help about that will be very welcome.
|
||||
|
||||
## Manual calibration
|
||||
|
||||
Use a pure resistive load with a well-known power consumption or use a multimeter to monitor it. A bulb is usually a good idea, although a toaster would be better since it's power consumption is higher.
|
||||
|
||||
Then use the expected*() methods and feed the values. For instance, for a 60W bulb in a 230 line that would be:
|
||||
|
||||
```
|
||||
hlw8012.expectedActivePower(60.0);
|
||||
hlw8012.expectedVoltage(230.0);
|
||||
hlw8012.expectedCurrent(60.0 / 230.0);
|
||||
```
|
||||
|
||||
|
||||
[1]:https://github.com/esp8266/Arduino
|
||||
[2]:https://www.itead.cc/sonoff-pow.html?acc=70efdf2ec9b086079795c442636b55fb
|
||||
Binary file not shown.
Binary file not shown.
|
After Width: | Height: | Size: 35 KiB |
@@ -0,0 +1,120 @@
|
||||
#include <Arduino.h>
|
||||
#include "HLW8012.h"
|
||||
|
||||
#define SERIAL_BAUDRATE 115200
|
||||
|
||||
// GPIOs
|
||||
#define RELAY_PIN 12
|
||||
#define SEL_PIN 5
|
||||
#define CF1_PIN 13
|
||||
#define CF_PIN 14
|
||||
|
||||
// Check values every 2 seconds
|
||||
#define UPDATE_TIME 2000
|
||||
|
||||
// Set SEL_PIN to HIGH to sample current
|
||||
// This is the case for Itead's Sonoff POW, where a
|
||||
// the SEL_PIN drives a transistor that pulls down
|
||||
// the SEL pin in the HLW8012 when closed
|
||||
#define CURRENT_MODE HIGH
|
||||
|
||||
// These are the nominal values for the resistors in the circuit
|
||||
#define CURRENT_RESISTOR 0.001
|
||||
#define VOLTAGE_RESISTOR_UPSTREAM ( 5 * 470000 ) // Real: 2280k
|
||||
#define VOLTAGE_RESISTOR_DOWNSTREAM ( 1000 ) // Real 1.009k
|
||||
|
||||
HLW8012 hlw8012;
|
||||
|
||||
void unblockingDelay(unsigned long mseconds) {
|
||||
unsigned long timeout = millis();
|
||||
while ((millis() - timeout) < mseconds) delay(1);
|
||||
}
|
||||
|
||||
void calibrate() {
|
||||
|
||||
// Let's first read power, current and voltage
|
||||
// with an interval in between to allow the signal to stabilise:
|
||||
|
||||
hlw8012.getActivePower();
|
||||
|
||||
hlw8012.setMode(MODE_CURRENT);
|
||||
unblockingDelay(2000);
|
||||
hlw8012.getCurrent();
|
||||
|
||||
hlw8012.setMode(MODE_VOLTAGE);
|
||||
unblockingDelay(2000);
|
||||
hlw8012.getVoltage();
|
||||
|
||||
// Calibrate using a 60W bulb (pure resistive) on a 230V line
|
||||
hlw8012.expectedActivePower(60.0);
|
||||
hlw8012.expectedVoltage(230.0);
|
||||
hlw8012.expectedCurrent(60.0 / 230.0);
|
||||
|
||||
// Show corrected factors
|
||||
Serial.print("[HLW] New current multiplier : "); Serial.println(hlw8012.getCurrentMultiplier());
|
||||
Serial.print("[HLW] New voltage multiplier : "); Serial.println(hlw8012.getVoltageMultiplier());
|
||||
Serial.print("[HLW] New power multiplier : "); Serial.println(hlw8012.getPowerMultiplier());
|
||||
Serial.println();
|
||||
|
||||
}
|
||||
|
||||
void setup() {
|
||||
|
||||
// Init serial port and clean garbage
|
||||
Serial.begin(SERIAL_BAUDRATE);
|
||||
Serial.println();
|
||||
Serial.println();
|
||||
|
||||
// Close the relay to switch on the load
|
||||
pinMode(RELAY_PIN, OUTPUT);
|
||||
digitalWrite(RELAY_PIN, HIGH);
|
||||
|
||||
// Initialize HLW8012
|
||||
// void begin(unsigned char cf_pin, unsigned char cf1_pin, unsigned char sel_pin, unsigned char currentWhen = HIGH, bool use_interrupts = false, unsigned long pulse_timeout = PULSE_TIMEOUT);
|
||||
// * cf_pin, cf1_pin and sel_pin are GPIOs to the HLW8012 IC
|
||||
// * currentWhen is the value in sel_pin to select current sampling
|
||||
// * set use_interrupts to false, we will have to call handle() in the main loop to do the sampling
|
||||
// * set pulse_timeout to 500ms for a fast response but losing precision (that's ~24W precision :( )
|
||||
hlw8012.begin(CF_PIN, CF1_PIN, SEL_PIN, CURRENT_MODE, false, 500000);
|
||||
|
||||
// These values are used to calculate current, voltage and power factors as per datasheet formula
|
||||
// These are the nominal values for the Sonoff POW resistors:
|
||||
// * The CURRENT_RESISTOR is the 1milliOhm copper-manganese resistor in series with the main line
|
||||
// * The VOLTAGE_RESISTOR_UPSTREAM are the 5 470kOhm resistors in the voltage divider that feeds the V2P pin in the HLW8012
|
||||
// * The VOLTAGE_RESISTOR_DOWNSTREAM is the 1kOhm resistor in the voltage divider that feeds the V2P pin in the HLW8012
|
||||
hlw8012.setResistors(CURRENT_RESISTOR, VOLTAGE_RESISTOR_UPSTREAM, VOLTAGE_RESISTOR_DOWNSTREAM);
|
||||
|
||||
// Show default (as per datasheet) multipliers
|
||||
Serial.print("[HLW] Default current multiplier : "); Serial.println(hlw8012.getCurrentMultiplier());
|
||||
Serial.print("[HLW] Default voltage multiplier : "); Serial.println(hlw8012.getVoltageMultiplier());
|
||||
Serial.print("[HLW] Default power multiplier : "); Serial.println(hlw8012.getPowerMultiplier());
|
||||
Serial.println();
|
||||
|
||||
calibrate();
|
||||
|
||||
}
|
||||
|
||||
void loop() {
|
||||
|
||||
static unsigned long last = millis();
|
||||
|
||||
// This UPDATE_TIME should be at least twice the minimum time for the current or voltage
|
||||
// signals to stabilize. Experimentally that's about 1 second.
|
||||
if ((millis() - last) > UPDATE_TIME) {
|
||||
|
||||
last = millis();
|
||||
Serial.print("[HLW] Active Power (W) : "); Serial.println(hlw8012.getActivePower());
|
||||
Serial.print("[HLW] Voltage (V) : "); Serial.println(hlw8012.getVoltage());
|
||||
Serial.print("[HLW] Current (A) : "); Serial.println(hlw8012.getCurrent());
|
||||
Serial.print("[HLW] Apparent Power (VA) : "); Serial.println(hlw8012.getApparentPower());
|
||||
Serial.print("[HLW] Power Factor (%) : "); Serial.println((int) (100 * hlw8012.getPowerFactor()));
|
||||
Serial.println();
|
||||
|
||||
// When not using interrupts we have to manually switch to current or voltage monitor
|
||||
// This means that every time we get into the conditional we only update one of them
|
||||
// while the other will return the cached value.
|
||||
hlw8012.toggleMode();
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,46 @@
|
||||
#include <Arduino.h>
|
||||
#include <LowPower.h>
|
||||
#include "HLW8012.h"
|
||||
|
||||
#define SERIAL_BAUDRATE 115200
|
||||
|
||||
// GPIOs
|
||||
#define SEL_PIN 5
|
||||
#define CF1_PIN 13
|
||||
#define CF_PIN 14
|
||||
|
||||
// Set SEL_PIN to HIGH to sample current
|
||||
// This is the case for Itead's Sonoff POW, where a
|
||||
// the SEL_PIN drives a transistor that pulls down
|
||||
// the SEL pin in the HLW8012 when closed
|
||||
#define CURRENT_MODE HIGH
|
||||
|
||||
// Maximum pulse width, a 2Hz pulse means a precission of ~24W
|
||||
#define MAX_PULSE_WIDTH 500000
|
||||
|
||||
HLW8012 hlw8012;
|
||||
|
||||
void setup() {
|
||||
|
||||
// Init serial port and clean garbage
|
||||
Serial.begin(SERIAL_BAUDRATE);
|
||||
Serial.println();
|
||||
Serial.println();
|
||||
|
||||
// Initialize HLW8012
|
||||
hlw8012.begin(CF_PIN, CF1_PIN, SEL_PIN, CURRENT_MODE, false, MAX_PULSE_WIDTH);
|
||||
|
||||
}
|
||||
|
||||
void loop() {
|
||||
|
||||
// Sleep for 20 seconds
|
||||
for (unsigned short i = 0; i < 5; i++ ) {
|
||||
LowPower.powerDown(SLEEP_4S, ADC_OFF, BOD_OFF);
|
||||
}
|
||||
|
||||
unsigned long start = millis();
|
||||
Serial.print("[HLW] Active Power (W) : "); Serial.println(hlw8012.getActivePower());
|
||||
Serial.print("[HLW] Awake for (ms) : "); Serial.println(millis() - start);
|
||||
|
||||
}
|
||||
@@ -0,0 +1,118 @@
|
||||
#include <Arduino.h>
|
||||
#include "HLW8012.h"
|
||||
|
||||
#define SERIAL_BAUDRATE 115200
|
||||
|
||||
// GPIOs
|
||||
#define RELAY_PIN 12
|
||||
#define SEL_PIN 5
|
||||
#define CF1_PIN 13
|
||||
#define CF_PIN 14
|
||||
|
||||
// Check values every 10 seconds
|
||||
#define UPDATE_TIME 10000
|
||||
|
||||
// Set SEL_PIN to HIGH to sample current
|
||||
// This is the case for Itead's Sonoff POW, where a
|
||||
// the SEL_PIN drives a transistor that pulls down
|
||||
// the SEL pin in the HLW8012 when closed
|
||||
#define CURRENT_MODE HIGH
|
||||
|
||||
// These are the nominal values for the resistors in the circuit
|
||||
#define CURRENT_RESISTOR 0.001
|
||||
#define VOLTAGE_RESISTOR_UPSTREAM ( 5 * 470000 ) // Real: 2280k
|
||||
#define VOLTAGE_RESISTOR_DOWNSTREAM ( 1000 ) // Real 1.009k
|
||||
|
||||
HLW8012 hlw8012;
|
||||
|
||||
// When using interrupts we have to call the library entry point
|
||||
// whenever an interrupt is triggered
|
||||
void hlw8012_cf1_interrupt() {
|
||||
hlw8012.cf1_interrupt();
|
||||
}
|
||||
void hlw8012_cf_interrupt() {
|
||||
hlw8012.cf_interrupt();
|
||||
}
|
||||
|
||||
// Library expects an interrupt on both edges
|
||||
void setInterrupts() {
|
||||
attachInterrupt(CF1_PIN, hlw8012_cf1_interrupt, CHANGE);
|
||||
attachInterrupt(CF_PIN, hlw8012_cf_interrupt, CHANGE);
|
||||
}
|
||||
|
||||
void calibrate() {
|
||||
|
||||
// Let some time to register values
|
||||
unsigned long timeout = millis();
|
||||
while ((millis() - timeout) < 10000) {
|
||||
delay(1);
|
||||
}
|
||||
|
||||
// Calibrate using a 60W bulb (pure resistive) on a 230V line
|
||||
hlw8012.expectedActivePower(60.0);
|
||||
hlw8012.expectedVoltage(230.0);
|
||||
hlw8012.expectedCurrent(60.0 / 230.0);
|
||||
|
||||
// Show corrected factors
|
||||
Serial.print("[HLW] New current multiplier : "); Serial.println(hlw8012.getCurrentMultiplier());
|
||||
Serial.print("[HLW] New voltage multiplier : "); Serial.println(hlw8012.getVoltageMultiplier());
|
||||
Serial.print("[HLW] New power multiplier : "); Serial.println(hlw8012.getPowerMultiplier());
|
||||
Serial.println();
|
||||
|
||||
}
|
||||
|
||||
void setup() {
|
||||
|
||||
// Init serial port and clean garbage
|
||||
Serial.begin(SERIAL_BAUDRATE);
|
||||
Serial.println();
|
||||
Serial.println();
|
||||
|
||||
// Close the relay to switch on the load
|
||||
pinMode(RELAY_PIN, OUTPUT);
|
||||
digitalWrite(RELAY_PIN, HIGH);
|
||||
|
||||
// Initialize HLW8012
|
||||
// void begin(unsigned char cf_pin, unsigned char cf1_pin, unsigned char sel_pin, unsigned char currentWhen = HIGH, bool use_interrupts = false, unsigned long pulse_timeout = PULSE_TIMEOUT);
|
||||
// * cf_pin, cf1_pin and sel_pin are GPIOs to the HLW8012 IC
|
||||
// * currentWhen is the value in sel_pin to select current sampling
|
||||
// * set use_interrupts to true to use interrupts to monitor pulse widths
|
||||
// * leave pulse_timeout to the default value, recommended when using interrupts
|
||||
hlw8012.begin(CF_PIN, CF1_PIN, SEL_PIN, CURRENT_MODE, true);
|
||||
|
||||
// These values are used to calculate current, voltage and power factors as per datasheet formula
|
||||
// These are the nominal values for the Sonoff POW resistors:
|
||||
// * The CURRENT_RESISTOR is the 1milliOhm copper-manganese resistor in series with the main line
|
||||
// * The VOLTAGE_RESISTOR_UPSTREAM are the 5 470kOhm resistors in the voltage divider that feeds the V2P pin in the HLW8012
|
||||
// * The VOLTAGE_RESISTOR_DOWNSTREAM is the 1kOhm resistor in the voltage divider that feeds the V2P pin in the HLW8012
|
||||
hlw8012.setResistors(CURRENT_RESISTOR, VOLTAGE_RESISTOR_UPSTREAM, VOLTAGE_RESISTOR_DOWNSTREAM);
|
||||
|
||||
// Show default (as per datasheet) multipliers
|
||||
Serial.print("[HLW] Default current multiplier : "); Serial.println(hlw8012.getCurrentMultiplier());
|
||||
Serial.print("[HLW] Default voltage multiplier : "); Serial.println(hlw8012.getVoltageMultiplier());
|
||||
Serial.print("[HLW] Default power multiplier : "); Serial.println(hlw8012.getPowerMultiplier());
|
||||
Serial.println();
|
||||
|
||||
setInterrupts();
|
||||
calibrate();
|
||||
|
||||
}
|
||||
|
||||
void loop() {
|
||||
|
||||
static unsigned long last = millis();
|
||||
|
||||
// This UPDATE_TIME should be at least twice the interrupt timeout (2 second by default)
|
||||
if ((millis() - last) > UPDATE_TIME) {
|
||||
|
||||
last = millis();
|
||||
Serial.print("[HLW] Active Power (W) : "); Serial.println(hlw8012.getActivePower());
|
||||
Serial.print("[HLW] Voltage (V) : "); Serial.println(hlw8012.getVoltage());
|
||||
Serial.print("[HLW] Current (A) : "); Serial.println(hlw8012.getCurrent());
|
||||
Serial.print("[HLW] Apparent Power (VA) : "); Serial.println(hlw8012.getApparentPower());
|
||||
Serial.print("[HLW] Power Factor (%) : "); Serial.println((int) (100 * hlw8012.getPowerFactor()));
|
||||
Serial.println();
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,25 @@
|
||||
{
|
||||
"name": "HLW8012",
|
||||
"keywords": "hlw8012,power,current,voltage",
|
||||
"description": "HLW8012 library for Arduino and ESP8266",
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "https://bitbucket.org/xoseperez/hlw8012.git"
|
||||
},
|
||||
"version": "1.0.0",
|
||||
"license": "GPL-3.0",
|
||||
"exclude": "tests",
|
||||
"frameworks": "arduino",
|
||||
"platforms": ["atmelavr", "espressif8266"],
|
||||
"dependencies": [
|
||||
],
|
||||
"authors": {
|
||||
"name": "Xose Perez",
|
||||
"email": "xose.perez@gmail.com",
|
||||
"url": "http://tinkerman.cat",
|
||||
"maintainer": true
|
||||
},
|
||||
"examples": [
|
||||
"examples/*/*.ino"
|
||||
]
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
name=HLW8012
|
||||
version=1.0.0
|
||||
author=Xose Pérez <xose.perez@gmail.com>
|
||||
maintainer=Xose Perez <xose.perez@gmail.com>
|
||||
sentence=HLW8012 for Arduino / ESP8216
|
||||
paragraph=HLW8012 power/current/voltage monitor IC library for Arduino and ESP8266. Use 2.x.x for ESP and 1.3 for AVR.
|
||||
category=Sensors
|
||||
url=https://bitbucket.org/xoseperez/hlw8012
|
||||
architectures=*
|
||||
@@ -0,0 +1,220 @@
|
||||
/*
|
||||
|
||||
HLW8012 1.0.0
|
||||
|
||||
Copyright (C) 2016 by Xose Pérez <xose dot perez at gmail dot com>
|
||||
|
||||
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 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
*/
|
||||
|
||||
#include <Arduino.h>
|
||||
#include "HLW8012.h"
|
||||
|
||||
void HLW8012::begin(
|
||||
unsigned char cf_pin,
|
||||
unsigned char cf1_pin,
|
||||
unsigned char sel_pin,
|
||||
unsigned char currentWhen,
|
||||
bool use_interrupts,
|
||||
unsigned long pulse_timeout
|
||||
) {
|
||||
|
||||
_cf_pin = cf_pin;
|
||||
_cf1_pin = cf1_pin;
|
||||
_sel_pin = sel_pin;
|
||||
_current_mode = currentWhen;
|
||||
_use_interrupts = use_interrupts;
|
||||
_pulse_timeout = pulse_timeout;
|
||||
|
||||
pinMode(_cf_pin, INPUT_PULLUP);
|
||||
pinMode(_cf1_pin, INPUT_PULLUP);
|
||||
pinMode(_sel_pin, OUTPUT);
|
||||
|
||||
_calculateDefaultMultipliers();
|
||||
|
||||
_mode = _current_mode;
|
||||
digitalWrite(_sel_pin, _mode);
|
||||
|
||||
|
||||
}
|
||||
|
||||
void HLW8012::setMode(hlw8012_mode_t mode) {
|
||||
_mode = (mode == MODE_CURRENT) ? _current_mode : 1 - _current_mode;
|
||||
digitalWrite(_sel_pin, _mode);
|
||||
if (_use_interrupts) {
|
||||
_last_cf1_interrupt = _first_cf1_interrupt = micros();
|
||||
}
|
||||
}
|
||||
|
||||
hlw8012_mode_t HLW8012::getMode() {
|
||||
return (_mode == _current_mode) ? MODE_CURRENT : MODE_VOLTAGE;
|
||||
}
|
||||
|
||||
hlw8012_mode_t HLW8012::toggleMode() {
|
||||
hlw8012_mode_t new_mode = getMode() == MODE_CURRENT ? MODE_VOLTAGE : MODE_CURRENT;
|
||||
setMode(new_mode);
|
||||
return new_mode;
|
||||
}
|
||||
|
||||
double HLW8012::getCurrent() {
|
||||
|
||||
// Power measurements are more sensitive to switch offs,
|
||||
// so we first check if power is 0 to set _current to 0 too
|
||||
if (_power == 0) {
|
||||
_current_pulse_width = 0;
|
||||
|
||||
} else if (_use_interrupts) {
|
||||
_checkCF1Signal();
|
||||
|
||||
} else if (_mode == _current_mode) {
|
||||
_current_pulse_width = pulseIn(_cf1_pin, HIGH, _pulse_timeout);
|
||||
}
|
||||
|
||||
_current = (_current_pulse_width > 0) ? _current_multiplier / _current_pulse_width / 2 : 0;
|
||||
return _current;
|
||||
|
||||
}
|
||||
|
||||
unsigned int HLW8012::getVoltage() {
|
||||
if (_use_interrupts) {
|
||||
_checkCF1Signal();
|
||||
} else if (_mode != _current_mode) {
|
||||
_voltage_pulse_width = pulseIn(_cf1_pin, HIGH, _pulse_timeout);
|
||||
}
|
||||
_voltage = (_voltage_pulse_width > 0) ? _voltage_multiplier / _voltage_pulse_width / 2 : 0;
|
||||
return _voltage;
|
||||
}
|
||||
|
||||
unsigned int HLW8012::getActivePower() {
|
||||
if (_use_interrupts) {
|
||||
_checkCFSignal();
|
||||
} else {
|
||||
_power_pulse_width = pulseIn(_cf_pin, HIGH, _pulse_timeout);
|
||||
}
|
||||
_power = (_power_pulse_width > 0) ? _power_multiplier / _power_pulse_width / 2 : 0;
|
||||
return _power;
|
||||
}
|
||||
|
||||
unsigned int HLW8012::getApparentPower() {
|
||||
double current = getCurrent();
|
||||
unsigned int voltage = getVoltage();
|
||||
return voltage * current;
|
||||
}
|
||||
|
||||
unsigned int HLW8012::getReactivePower() {
|
||||
unsigned int active = getActivePower();
|
||||
unsigned int apparent = getApparentPower();
|
||||
if (apparent > active) {
|
||||
return sqrt(apparent * apparent - active * active);
|
||||
} else {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
double HLW8012::getPowerFactor() {
|
||||
unsigned int active = getActivePower();
|
||||
unsigned int apparent = getApparentPower();
|
||||
if (active > apparent) return 1;
|
||||
if (apparent == 0) return 0;
|
||||
return (double) active / apparent;
|
||||
}
|
||||
|
||||
void HLW8012::expectedCurrent(double value) {
|
||||
if (_current == 0) getCurrent();
|
||||
if (_current > 0) _current_multiplier *= (value / _current);
|
||||
}
|
||||
|
||||
void HLW8012::expectedVoltage(unsigned int value) {
|
||||
if (_voltage == 0) getVoltage();
|
||||
if (_voltage > 0) _voltage_multiplier *= ((double) value / _voltage);
|
||||
}
|
||||
|
||||
void HLW8012::expectedActivePower(unsigned int value) {
|
||||
if (_power == 0) getActivePower();
|
||||
if (_power > 0) _power_multiplier *= ((double) value / _power);
|
||||
}
|
||||
|
||||
void HLW8012::resetMultipliers() {
|
||||
_calculateDefaultMultipliers();
|
||||
}
|
||||
|
||||
void HLW8012::setResistors(double current, double voltage_upstream, double voltage_downstream) {
|
||||
if (voltage_downstream > 0) {
|
||||
_current_resistor = current;
|
||||
_voltage_resistor = (voltage_upstream + voltage_downstream) / voltage_downstream;
|
||||
_calculateDefaultMultipliers();
|
||||
}
|
||||
}
|
||||
|
||||
void HLW8012::cf_interrupt() {
|
||||
unsigned long now = micros();
|
||||
_power_pulse_width = now - _last_cf_interrupt;
|
||||
_last_cf_interrupt = now;
|
||||
}
|
||||
|
||||
void HLW8012::cf1_interrupt() {
|
||||
|
||||
unsigned long now = micros();
|
||||
unsigned long pulse_width;
|
||||
|
||||
if ((now - _first_cf1_interrupt) > _pulse_timeout) {
|
||||
|
||||
if (_last_cf1_interrupt == _first_cf1_interrupt) {
|
||||
pulse_width = 0;
|
||||
} else {
|
||||
pulse_width = now - _last_cf1_interrupt;
|
||||
}
|
||||
|
||||
if (_mode == _current_mode) {
|
||||
_current_pulse_width = pulse_width;
|
||||
} else {
|
||||
_voltage_pulse_width = pulse_width;
|
||||
}
|
||||
|
||||
_mode = 1 - _mode;
|
||||
digitalWrite(_sel_pin, _mode);
|
||||
_first_cf1_interrupt = now;
|
||||
|
||||
}
|
||||
|
||||
_last_cf1_interrupt = now;
|
||||
|
||||
}
|
||||
|
||||
void HLW8012::_checkCFSignal() {
|
||||
if ((micros() - _last_cf_interrupt) > _pulse_timeout) _power_pulse_width = 0;
|
||||
}
|
||||
|
||||
void HLW8012::_checkCF1Signal() {
|
||||
if ((micros() - _last_cf1_interrupt) > _pulse_timeout) {
|
||||
if (_mode == _current_mode) {
|
||||
_current_pulse_width = 0;
|
||||
} else {
|
||||
_voltage_pulse_width = 0;
|
||||
}
|
||||
toggleMode();
|
||||
}
|
||||
}
|
||||
|
||||
// These are the multipliers for current, voltage and power as per datasheet
|
||||
// These values divided by output period (in useconds) give the actual value
|
||||
// For power a frequency of 1Hz means around 12W
|
||||
// For current a frequency of 1Hz means around 15mA
|
||||
// For voltage a frequency of 1Hz means around 0.5V
|
||||
void HLW8012::_calculateDefaultMultipliers() {
|
||||
_current_multiplier = ( 1000000.0 * 512 * V_REF / _current_resistor / 24.0 / F_OSC );
|
||||
_voltage_multiplier = ( 1000000.0 * 512 * V_REF * _voltage_resistor / 2.0 / F_OSC );
|
||||
_power_multiplier = ( 1000000.0 * 128 * V_REF * V_REF * _voltage_resistor / _current_resistor / 48.0 / F_OSC );
|
||||
}
|
||||
@@ -0,0 +1,138 @@
|
||||
/*
|
||||
|
||||
HLW8012 1.0.0
|
||||
|
||||
Copyright (C) 2016 by Xose Pérez <xose dot perez at gmail dot com>
|
||||
|
||||
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 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
*/
|
||||
|
||||
#ifndef HLW8012_h
|
||||
#define HLW8012_h
|
||||
|
||||
#include <Arduino.h>
|
||||
|
||||
// Internal voltage reference value
|
||||
#define V_REF 2.43
|
||||
|
||||
// The factor of a 1mOhm resistor
|
||||
// as per recomended circuit in datasheet
|
||||
// A 1mOhm resistor allows a ~30A max measurement
|
||||
#define R_CURRENT 0.001
|
||||
|
||||
// This is the factor of a voltage divider of 6x 470K upstream and 1k downstream
|
||||
// as per recomended circuit in datasheet
|
||||
#define R_VOLTAGE 2821
|
||||
|
||||
// Frequency of the HLW8012 internal clock
|
||||
#define F_OSC 3579000
|
||||
|
||||
// Minimum delay between selecting a mode and reading a sample
|
||||
#define READING_INTERVAL 3000
|
||||
|
||||
// Maximum pulse with in microseconds
|
||||
// If longer than this pulse width is reset to 0
|
||||
// This value is purely experimental.
|
||||
// Higher values allow for a better precission but reduce sampling rate
|
||||
// and response speed to change
|
||||
// Lower values increase sampling rate but reduce precission
|
||||
// Values below 0.5s are not recommended since current and voltage output
|
||||
// will have no time to stabilise
|
||||
#define PULSE_TIMEOUT 2000000
|
||||
|
||||
// CF1 mode
|
||||
typedef enum {
|
||||
MODE_CURRENT,
|
||||
MODE_VOLTAGE
|
||||
} hlw8012_mode_t;
|
||||
|
||||
class HLW8012 {
|
||||
|
||||
public:
|
||||
|
||||
void cf_interrupt();
|
||||
void cf1_interrupt();
|
||||
|
||||
void begin(
|
||||
unsigned char cf_pin,
|
||||
unsigned char cf1_pin,
|
||||
unsigned char sel_pin,
|
||||
unsigned char currentWhen = HIGH,
|
||||
bool use_interrupts = true,
|
||||
unsigned long pulse_timeout = PULSE_TIMEOUT);
|
||||
|
||||
void setMode(hlw8012_mode_t mode);
|
||||
hlw8012_mode_t getMode();
|
||||
hlw8012_mode_t toggleMode();
|
||||
|
||||
double getCurrent();
|
||||
unsigned int getVoltage();
|
||||
unsigned int getActivePower();
|
||||
unsigned int getApparentPower();
|
||||
double getPowerFactor();
|
||||
unsigned int getReactivePower();
|
||||
|
||||
void setResistors(double current, double voltage_upstream, double voltage_downstream);
|
||||
|
||||
void expectedCurrent(double current);
|
||||
void expectedVoltage(unsigned int current);
|
||||
void expectedActivePower(unsigned int power);
|
||||
|
||||
double getCurrentMultiplier() { return _current_multiplier; };
|
||||
double getVoltageMultiplier() { return _voltage_multiplier; };
|
||||
double getPowerMultiplier() { return _power_multiplier; };
|
||||
|
||||
void setCurrentMultiplier(double current_multiplier) { _current_multiplier = current_multiplier; };
|
||||
void setVoltageMultiplier(double voltage_multiplier) { _voltage_multiplier = voltage_multiplier; };
|
||||
void setPowerMultiplier(double power_multiplier) { _power_multiplier = power_multiplier; };
|
||||
void resetMultipliers();
|
||||
|
||||
private:
|
||||
|
||||
unsigned char _cf_pin;
|
||||
unsigned char _cf1_pin;
|
||||
unsigned char _sel_pin;
|
||||
|
||||
double _current_resistor = R_CURRENT;
|
||||
double _voltage_resistor = R_VOLTAGE;
|
||||
|
||||
double _current_multiplier;
|
||||
double _voltage_multiplier;
|
||||
double _power_multiplier;
|
||||
|
||||
unsigned long _pulse_timeout = PULSE_TIMEOUT;
|
||||
volatile unsigned long _voltage_pulse_width = 0;
|
||||
volatile unsigned long _current_pulse_width = 0;
|
||||
volatile unsigned long _power_pulse_width = 0;
|
||||
|
||||
double _current = 0;
|
||||
unsigned int _voltage = 0;
|
||||
unsigned int _power = 0;
|
||||
|
||||
unsigned char _current_mode = HIGH;
|
||||
volatile unsigned char _mode;
|
||||
|
||||
bool _use_interrupts = true;
|
||||
volatile unsigned long _last_cf_interrupt = 0;
|
||||
volatile unsigned long _last_cf1_interrupt = 0;
|
||||
volatile unsigned long _first_cf1_interrupt = 0;
|
||||
|
||||
void _checkCFSignal();
|
||||
void _checkCF1Signal();
|
||||
void _calculateDefaultMultipliers();
|
||||
|
||||
};
|
||||
|
||||
#endif
|
||||
@@ -93,8 +93,8 @@ bool ICACHE_FLASH_ATTR IRKelvinatorAC::getPower() {
|
||||
|
||||
// Set the temp. in deg C
|
||||
void ICACHE_FLASH_ATTR IRKelvinatorAC::setTemp(uint8_t temp) {
|
||||
temp = max(KELVINATOR_MIN_TEMP, temp);
|
||||
temp = min(KELVINATOR_MAX_TEMP, temp);
|
||||
temp = max(static_cast<uint8_t>(KELVINATOR_MIN_TEMP), temp);
|
||||
temp = min(static_cast<uint8_t>(KELVINATOR_MAX_TEMP), temp);
|
||||
remote_state[1] = (remote_state[1] & 0xF0U) | (temp - KELVINATOR_MIN_TEMP);
|
||||
remote_state[9] = remote_state[1]; // Duplicate to the 2nd command chunk.
|
||||
}
|
||||
@@ -106,12 +106,12 @@ uint8_t ICACHE_FLASH_ATTR IRKelvinatorAC::getTemp() {
|
||||
|
||||
// Set the speed of the fan, 0-5, 0 is auto, 1-5 is the speed
|
||||
void ICACHE_FLASH_ATTR IRKelvinatorAC::setFan(uint8_t fan) {
|
||||
fan = min(KELVINATOR_FAN_MAX, fan); // Bounds check
|
||||
fan = min(static_cast<uint8_t>(KELVINATOR_FAN_MAX), fan); // Bounds check
|
||||
|
||||
// Only change things if we need to.
|
||||
if (fan != getFan()) {
|
||||
// Set the basic fan values.
|
||||
uint8_t fan_basic = min(KELVINATOR_BASIC_FAN_MAX, fan);
|
||||
uint8_t fan_basic = min(static_cast<uint8_t>(KELVINATOR_BASIC_FAN_MAX), fan);
|
||||
remote_state[0] = (remote_state[0] & KELVINATOR_BASIC_FAN_MASK) |
|
||||
(fan_basic << KELVINATOR_FAN_OFFSET);
|
||||
remote_state[8] = remote_state[0]; // Duplicate to the 2nd command chunk.
|
||||
|
||||
@@ -77,8 +77,8 @@ bool ICACHE_FLASH_ATTR IRMitsubishiAC::getPower() {
|
||||
|
||||
// Set the temp. in deg C
|
||||
void ICACHE_FLASH_ATTR IRMitsubishiAC::setTemp(uint8_t temp) {
|
||||
temp = max(MITSUBISHI_AC_MIN_TEMP, temp);
|
||||
temp = min(MITSUBISHI_AC_MAX_TEMP, temp);
|
||||
temp = max(static_cast<uint8_t>(MITSUBISHI_AC_MIN_TEMP), temp);
|
||||
temp = min(static_cast<uint8_t>(MITSUBISHI_AC_MAX_TEMP), temp);
|
||||
remote_state[7] = temp - MITSUBISHI_AC_MIN_TEMP;
|
||||
}
|
||||
|
||||
@@ -136,7 +136,7 @@ void ICACHE_FLASH_ATTR IRMitsubishiAC::setMode(uint8_t mode) {
|
||||
|
||||
// Set the requested vane operation mode of the a/c unit.
|
||||
void ICACHE_FLASH_ATTR IRMitsubishiAC::setVane(uint8_t mode) {
|
||||
mode = max(mode, B111); // bounds check
|
||||
mode = max(mode, static_cast<uint8_t>(B111)); // bounds check
|
||||
mode |= B1000;
|
||||
mode <<= 3;
|
||||
remote_state[9] |= mode;
|
||||
|
||||
@@ -155,7 +155,7 @@ void ICACHE_FLASH_ATTR IRsend::sendNEC (unsigned long data, int nbits,
|
||||
// Footer
|
||||
mark(NEC_BIT_MARK);
|
||||
// Gap to next command.
|
||||
space(max(0, NEC_MIN_COMMAND_LENGTH - usecs.elapsed()));
|
||||
space(max(0ul, NEC_MIN_COMMAND_LENGTH - usecs.elapsed()));
|
||||
|
||||
// Optional command repeat sequence.
|
||||
for (unsigned int i = 0; i < repeat; i++) {
|
||||
@@ -164,7 +164,52 @@ void ICACHE_FLASH_ATTR IRsend::sendNEC (unsigned long data, int nbits,
|
||||
space(NEC_RPT_SPACE);
|
||||
mark(NEC_BIT_MARK);
|
||||
// Gap till next command.
|
||||
space(max(0, NEC_MIN_COMMAND_LENGTH - usecs.elapsed()));
|
||||
space(max(0ul, NEC_MIN_COMMAND_LENGTH - usecs.elapsed()));
|
||||
}
|
||||
}
|
||||
|
||||
void ICACHE_FLASH_ATTR IRsend::sendPioneer (unsigned long data, int nbits,
|
||||
unsigned int repeat, unsigned long secondData) {
|
||||
// Details about timings can be found at:
|
||||
// http://www.sbprojects.com/knowledge/ir/nec.php
|
||||
// More about the pioneer format:
|
||||
// http://www.adrian-kingston.com/IRFormatPioneer.htm
|
||||
|
||||
// Set IR carrier frequency
|
||||
enableIROut(40);
|
||||
IRtimer usecs = IRtimer();
|
||||
|
||||
for (unsigned int i = 0; i <= repeat; i++) {
|
||||
usecs.reset();
|
||||
// Header
|
||||
mark(PIONEER_HDR_MARK);
|
||||
space(PIONEER_HDR_SPACE);
|
||||
|
||||
sendData(PIONEER_BIT_MARK, PIONEER_ONE_SPACE, PIONEER_BIT_MARK, PIONEER_ZERO_SPACE,
|
||||
data, nbits, true);
|
||||
|
||||
// Footer
|
||||
mark(PIONEER_BIT_MARK);
|
||||
space(PIONEER_ONE_SPACE);
|
||||
// Gap till next command.
|
||||
space(max(0ul, PIONEER_MIN_COMMAND_LENGTH - usecs.elapsed()));
|
||||
|
||||
// Some Pioneer signals have two 32 bit commands
|
||||
if (secondData) {
|
||||
usecs.reset();
|
||||
// Header
|
||||
mark(PIONEER_HDR_MARK);
|
||||
space(PIONEER_HDR_SPACE);
|
||||
|
||||
sendData(PIONEER_BIT_MARK, PIONEER_ONE_SPACE, PIONEER_BIT_MARK, PIONEER_ZERO_SPACE,
|
||||
secondData, nbits, true);
|
||||
|
||||
// Footer
|
||||
mark(PIONEER_BIT_MARK);
|
||||
space(PIONEER_ONE_SPACE);
|
||||
// Gap till next command.
|
||||
space(max(0ul, PIONEER_MIN_COMMAND_LENGTH - usecs.elapsed()));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -236,7 +281,7 @@ void ICACHE_FLASH_ATTR IRsend::sendSony(unsigned long data, int nbits,
|
||||
// Footer
|
||||
// The Sony protocol requires us to wait 45ms from start of a code to the
|
||||
// start of the next one. A 10ms minimum gap is also required.
|
||||
space(max(10000, 45000 - usecs.elapsed()));
|
||||
space(max(10000u, 45000 - usecs.elapsed()));
|
||||
}
|
||||
// A space() is always performed last, so no need to turn off the LED.
|
||||
}
|
||||
@@ -367,7 +412,7 @@ void ICACHE_FLASH_ATTR IRsend::sendRCMM(uint32_t data, uint8_t nbits) {
|
||||
mark(RCMM_BIT_MARK);
|
||||
// Protocol requires us to wait at least RCMM_RPT_LENGTH usecs from the start
|
||||
// or RCMM_MIN_GAP usecs.
|
||||
space(max(RCMM_RPT_LENGTH - usecs.elapsed(), RCMM_MIN_GAP));
|
||||
space(max(RCMM_RPT_LENGTH - usecs.elapsed(), static_cast<uint32_t>(RCMM_MIN_GAP)));
|
||||
}
|
||||
|
||||
void ICACHE_FLASH_ATTR IRsend::sendPanasonic(unsigned int address,
|
||||
@@ -415,7 +460,7 @@ void ICACHE_FLASH_ATTR IRsend::sendJVC(unsigned long data, int nbits,
|
||||
// Footer
|
||||
mark(JVC_BIT_MARK);
|
||||
// Wait till the end of the repeat time window before we send another code.
|
||||
space(max(0, JVC_RPT_LENGTH - usecs.elapsed()));
|
||||
space(max(0u, JVC_RPT_LENGTH - usecs.elapsed()));
|
||||
usecs.reset();
|
||||
}
|
||||
// No need to turn off the LED as we will always end with a space().
|
||||
@@ -647,7 +692,7 @@ void ICACHE_FLASH_ATTR IRsend::sendSherwood(unsigned long data, int nbits,
|
||||
unsigned int repeat) {
|
||||
// Sherwood remote codes appear to be NEC codes with a manditory repeat code.
|
||||
// i.e. repeat should be >= 1.
|
||||
sendNEC(data, nbits, max(1, repeat));
|
||||
sendNEC(data, nbits, max(1u, repeat));
|
||||
}
|
||||
|
||||
void ICACHE_FLASH_ATTR IRsend::sendMitsubishiAC(unsigned char data[]) {
|
||||
@@ -911,7 +956,7 @@ bool ICACHE_FLASH_ATTR IRrecv::decode(decode_results *results,
|
||||
// Nr. of ticks.
|
||||
uint32_t IRrecv::ticksLow(uint32_t usecs, uint8_t tolerance) {
|
||||
// max() used to ensure the result can't drop below 0 before the cast.
|
||||
return((uint32_t) max(usecs * (1.0 - tolerance/100.)/USECPERTICK, 0));
|
||||
return((uint32_t) max(usecs * (1.0 - tolerance/100.)/USECPERTICK, 0.0));
|
||||
}
|
||||
|
||||
// Calculate the upper bound of the nr. of ticks.
|
||||
|
||||
@@ -53,6 +53,7 @@ enum decode_type_t {
|
||||
RC5,
|
||||
RC6,
|
||||
NEC,
|
||||
PIONEER,
|
||||
SONY,
|
||||
PANASONIC,
|
||||
JVC,
|
||||
@@ -92,6 +93,7 @@ public:
|
||||
#define REPEAT 0xffffffff
|
||||
|
||||
#define SEND_PROTOCOL_NEC case NEC: sendNEC(data, nbits); break;
|
||||
#define SEND_PROTOCOL_PIONEER case PIONEER: sendPioneer(data, nbits, 1, 0ul); break;
|
||||
#define SEND_PROTOCOL_SONY case SONY: sendSony(data, nbits); break;
|
||||
#define SEND_PROTOCOL_RC5 case RC5: sendRC5(data, nbits); break;
|
||||
#define SEND_PROTOCOL_RC6 case RC6: sendRC6(data, nbits); break;
|
||||
@@ -162,6 +164,7 @@ public:
|
||||
void send(int type, unsigned long data, int nbits) {
|
||||
switch (type) {
|
||||
SEND_PROTOCOL_NEC
|
||||
SEND_PROTOCOL_PIONEER
|
||||
SEND_PROTOCOL_SONY
|
||||
SEND_PROTOCOL_RC5
|
||||
SEND_PROTOCOL_RC6
|
||||
@@ -179,6 +182,7 @@ public:
|
||||
void sendCOOLIX(unsigned long data, int nbits);
|
||||
void sendWhynter(unsigned long data, int nbits);
|
||||
void sendNEC(unsigned long data, int nbits=32, unsigned int repeat=0);
|
||||
void sendPioneer(unsigned long data, int nbits=32, unsigned int repeat=0, unsigned long secondData=0ul);
|
||||
void sendLG(unsigned long data, int nbits=28, unsigned int repeat=0);
|
||||
// sendSony() should typically be called with repeat=2 as Sony devices
|
||||
// expect the code to be sent at least 3 times. (code + 2 repeats = 3 codes)
|
||||
|
||||
@@ -60,6 +60,14 @@
|
||||
#define NEC_RPT_SPACE 2250
|
||||
#define NEC_MIN_COMMAND_LENGTH 108000UL
|
||||
|
||||
#define PIONEER_HDR_MARK 8000
|
||||
#define PIONEER_HDR_SPACE 4000
|
||||
#define PIONEER_BIT_MARK 500
|
||||
#define PIONEER_ONE_SPACE 1500
|
||||
#define PIONEER_ZERO_SPACE 500
|
||||
#define PIONEER_RPT_SPACE 2250
|
||||
#define PIONEER_MIN_COMMAND_LENGTH 90000UL
|
||||
|
||||
// Timings based on http://www.sbprojects.com/knowledge/ir/sirc.php
|
||||
#define SONY_HDR_MARK 2400
|
||||
#define SONY_HDR_SPACE 600
|
||||
|
||||
Regular → Executable
+21
-11
@@ -1,11 +1,4 @@
|
||||
//www.DFRobot.com
|
||||
//last updated on 21/12/2011
|
||||
//Tim Starling Fix the reset bug (Thanks Tim)
|
||||
//wiki doc http://www.dfrobot.com/wiki/index.php?title=I2C/TWI_LCD1602_Module_(SKU:_DFR0063)
|
||||
//Support Forum: http://www.dfrobot.com/forum/
|
||||
//Compatible with the Arduino IDE 1.0
|
||||
//Library version:1.1
|
||||
|
||||
// Based on the work by DFRobot
|
||||
|
||||
#include "LiquidCrystal_I2C.h"
|
||||
#include <inttypes.h>
|
||||
@@ -16,7 +9,7 @@
|
||||
#define printIIC(args) Wire.write(args)
|
||||
inline size_t LiquidCrystal_I2C::write(uint8_t value) {
|
||||
send(value, Rs);
|
||||
return 0;
|
||||
return 1;
|
||||
}
|
||||
|
||||
#else
|
||||
@@ -59,6 +52,11 @@ LiquidCrystal_I2C::LiquidCrystal_I2C(uint8_t lcd_Addr,uint8_t lcd_cols,uint8_t l
|
||||
_backlightval = LCD_NOBACKLIGHT;
|
||||
}
|
||||
|
||||
void LiquidCrystal_I2C::oled_init(){
|
||||
_oled = true;
|
||||
init_priv();
|
||||
}
|
||||
|
||||
void LiquidCrystal_I2C::init(){
|
||||
init_priv();
|
||||
}
|
||||
@@ -134,6 +132,7 @@ void LiquidCrystal_I2C::begin(uint8_t cols, uint8_t lines, uint8_t dotsize) {
|
||||
void LiquidCrystal_I2C::clear(){
|
||||
command(LCD_CLEARDISPLAY);// clear display, set cursor position to zero
|
||||
delayMicroseconds(2000); // this command takes a long time!
|
||||
if (_oled) setCursor(0,0);
|
||||
}
|
||||
|
||||
void LiquidCrystal_I2C::home(){
|
||||
@@ -221,6 +220,15 @@ void LiquidCrystal_I2C::createChar(uint8_t location, uint8_t charmap[]) {
|
||||
}
|
||||
}
|
||||
|
||||
//createChar with PROGMEM input
|
||||
void LiquidCrystal_I2C::createChar(uint8_t location, const char *charmap) {
|
||||
location &= 0x7; // we only have 8 locations 0-7
|
||||
command(LCD_SETCGRAMADDR | (location << 3));
|
||||
for (int i=0; i<8; i++) {
|
||||
write(pgm_read_byte_near(charmap++));
|
||||
}
|
||||
}
|
||||
|
||||
// Turn the (optional) backlight off/on
|
||||
void LiquidCrystal_I2C::noBacklight(void) {
|
||||
_backlightval=LCD_NOBACKLIGHT;
|
||||
@@ -309,6 +317,8 @@ void LiquidCrystal_I2C::printstr(const char c[]){
|
||||
|
||||
|
||||
// unsupported API functions
|
||||
#pragma GCC diagnostic push
|
||||
#pragma GCC diagnostic ignored "-Wunused-parameter"
|
||||
void LiquidCrystal_I2C::off(){}
|
||||
void LiquidCrystal_I2C::on(){}
|
||||
void LiquidCrystal_I2C::setDelay (int cmdDelay,int charDelay) {}
|
||||
@@ -318,5 +328,5 @@ uint8_t LiquidCrystal_I2C::init_bargraph(uint8_t graphtype){return 0;}
|
||||
void LiquidCrystal_I2C::draw_horizontal_graph(uint8_t row, uint8_t column, uint8_t len, uint8_t pixel_col_end){}
|
||||
void LiquidCrystal_I2C::draw_vertical_graph(uint8_t row, uint8_t column, uint8_t len, uint8_t pixel_row_end){}
|
||||
void LiquidCrystal_I2C::setContrast(uint8_t new_val){}
|
||||
|
||||
|
||||
#pragma GCC diagnostic pop
|
||||
|
||||
|
||||
Regular → Executable
+7
-2
@@ -1,4 +1,4 @@
|
||||
//DFRobot.com
|
||||
//YWROBOT
|
||||
#ifndef LiquidCrystal_I2C_h
|
||||
#define LiquidCrystal_I2C_h
|
||||
|
||||
@@ -77,14 +77,18 @@ public:
|
||||
void autoscroll();
|
||||
void noAutoscroll();
|
||||
void createChar(uint8_t, uint8_t[]);
|
||||
void createChar(uint8_t location, const char *charmap);
|
||||
// Example: const char bell[8] PROGMEM = {B00100,B01110,B01110,B01110,B11111,B00000,B00100,B00000};
|
||||
|
||||
void setCursor(uint8_t, uint8_t);
|
||||
#if defined(ARDUINO) && ARDUINO >= 100
|
||||
#if defined(ARDUINO) && ARDUINO >= 100
|
||||
virtual size_t write(uint8_t);
|
||||
#else
|
||||
virtual void write(uint8_t);
|
||||
#endif
|
||||
void command(uint8_t);
|
||||
void init();
|
||||
void oled_init();
|
||||
|
||||
////compatibility API function aliases
|
||||
void blink_on(); // alias for blink()
|
||||
@@ -118,6 +122,7 @@ private:
|
||||
uint8_t _displaycontrol;
|
||||
uint8_t _displaymode;
|
||||
uint8_t _numlines;
|
||||
bool _oled = false;
|
||||
uint8_t _cols;
|
||||
uint8_t _rows;
|
||||
uint8_t _backlightval;
|
||||
|
||||
Executable
+2
@@ -0,0 +1,2 @@
|
||||
# LiquidCrystal_I2C
|
||||
LiquidCrystal Arduino library for the DFRobot I2C LCD displays
|
||||
@@ -1,69 +0,0 @@
|
||||
1,6c1
|
||||
< //www.DFRobot.com
|
||||
< //last updated on 26/11/2010
|
||||
< //Tim Starling Fix the reset bug (Thanks Tim)
|
||||
< //wiki doc http://www.dfrobot.com/wiki/index.php?title=I2C/TWI_LCD1602_Module_(SKU:_DFR0063)
|
||||
< //Support Forum: http://www.dfrobot.com/forum/
|
||||
<
|
||||
---
|
||||
> // LiquidCrystal_I2C V2.0
|
||||
10d4
|
||||
< #include "WProgram.h"
|
||||
12c6
|
||||
<
|
||||
---
|
||||
> #include "Arduino.h"
|
||||
67c61
|
||||
< delay(50);
|
||||
---
|
||||
> delayMicroseconds(50000);
|
||||
77,90c71,84
|
||||
< // we start in 8bit mode, try to set 4 bit mode
|
||||
< write4bits(0x03 << 4);
|
||||
< delayMicroseconds(4500); // wait min 4.1ms
|
||||
<
|
||||
< // second try
|
||||
< write4bits(0x03 << 4);
|
||||
< delayMicroseconds(4500); // wait min 4.1ms
|
||||
<
|
||||
< // third go!
|
||||
< write4bits(0x03 << 4);
|
||||
< delayMicroseconds(150);
|
||||
<
|
||||
< // finally, set to 4-bit interface
|
||||
< write4bits(0x02 << 4);
|
||||
---
|
||||
> // we start in 8bit mode, try to set 4 bit mode
|
||||
> write4bits(0x03);
|
||||
> delayMicroseconds(4500); // wait min 4.1ms
|
||||
>
|
||||
> // second try
|
||||
> write4bits(0x03);
|
||||
> delayMicroseconds(4500); // wait min 4.1ms
|
||||
>
|
||||
> // third go!
|
||||
> write4bits(0x03);
|
||||
> delayMicroseconds(150);
|
||||
>
|
||||
> // finally, set to 4-bit interface
|
||||
> write4bits(0x02);
|
||||
225c219
|
||||
< inline void LiquidCrystal_I2C::write(uint8_t value) {
|
||||
---
|
||||
> inline size_t LiquidCrystal_I2C::write(uint8_t value) {
|
||||
226a221
|
||||
> return 0;
|
||||
235,238c230,233
|
||||
< uint8_t highnib=value&0xf0;
|
||||
< uint8_t lownib=(value<<4)&0xf0;
|
||||
< write4bits((highnib)|mode);
|
||||
< write4bits((lownib)|mode);
|
||||
---
|
||||
> uint8_t highnib=value>>4;
|
||||
> uint8_t lownib=value & 0x0F;
|
||||
> write4bits((highnib)|mode);
|
||||
> write4bits((lownib)|mode);
|
||||
248c243
|
||||
< Wire.send((int)(_data) | _backlightval);
|
||||
---
|
||||
> Wire.write((int)(_data) | _backlightval);
|
||||
Regular → Executable
+4
-4
@@ -1,4 +1,4 @@
|
||||
//DFRobot.com
|
||||
//YWROBOT
|
||||
//Compatible with the Arduino IDE 1.0
|
||||
//Library version:1.1
|
||||
#include <Wire.h>
|
||||
@@ -19,7 +19,7 @@ uint8_t check[8] = {0x0,0x1,0x3,0x16,0x1c,0x8,0x0};
|
||||
uint8_t cross[8] = {0x0,0x1b,0xe,0x4,0xe,0x1b,0x0};
|
||||
uint8_t retarrow[8] = { 0x1,0x1,0x5,0x9,0x1f,0x8,0x4};
|
||||
|
||||
LiquidCrystal_I2C lcd(0x27,16,2); // set the LCD address to 0x27 for a 16 chars and 2 line display
|
||||
LiquidCrystal_I2C lcd(0x27,20,4); // set the LCD address to 0x27 for a 16 chars and 2 line display
|
||||
|
||||
void setup()
|
||||
{
|
||||
@@ -52,7 +52,7 @@ void displayKeyCodes(void) {
|
||||
while (1) {
|
||||
lcd.clear();
|
||||
lcd.print("Codes 0x"); lcd.print(i, HEX);
|
||||
lcd.print("-0x"); lcd.print(i+16, HEX);
|
||||
lcd.print("-0x"); lcd.print(i+15, HEX);
|
||||
lcd.setCursor(0, 1);
|
||||
for (int j=0; j<16; j++) {
|
||||
lcd.printByte(i+j);
|
||||
@@ -67,4 +67,4 @@ void loop()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
Regular → Executable
+11
-3
@@ -1,20 +1,28 @@
|
||||
//DFRobot.com
|
||||
//YWROBOT
|
||||
//Compatible with the Arduino IDE 1.0
|
||||
//Library version:1.1
|
||||
#include <Wire.h>
|
||||
#include <LiquidCrystal_I2C.h>
|
||||
|
||||
LiquidCrystal_I2C lcd(0x27,16,2); // set the LCD address to 0x27 for a 16 chars and 2 line display
|
||||
LiquidCrystal_I2C lcd(0x27,20,4); // set the LCD address to 0x27 for a 16 chars and 2 line display
|
||||
|
||||
void setup()
|
||||
{
|
||||
lcd.init(); // initialize the lcd
|
||||
|
||||
lcd.init();
|
||||
// Print a message to the LCD.
|
||||
lcd.backlight();
|
||||
lcd.setCursor(3,0);
|
||||
lcd.print("Hello, world!");
|
||||
lcd.setCursor(2,1);
|
||||
lcd.print("Ywrobot Arduino!");
|
||||
lcd.setCursor(0,2);
|
||||
lcd.print("Arduino LCM IIC 2004");
|
||||
lcd.setCursor(2,3);
|
||||
lcd.print("Power By Ec-yuan!");
|
||||
}
|
||||
|
||||
|
||||
void loop()
|
||||
{
|
||||
}
|
||||
|
||||
Regular → Executable
+2
-2
@@ -1,14 +1,14 @@
|
||||
/*
|
||||
* Displays text sent over the serial port (e.g. from the Serial Monitor) on
|
||||
* an attached LCD.
|
||||
* DFRobot.com
|
||||
* YWROBOT
|
||||
*Compatible with the Arduino IDE 1.0
|
||||
*Library version:1.1
|
||||
*/
|
||||
#include <Wire.h>
|
||||
#include <LiquidCrystal_I2C.h>
|
||||
|
||||
LiquidCrystal_I2C lcd(0x27,16,2); // set the LCD address to 0x27 for a 16 chars and 2 line display
|
||||
LiquidCrystal_I2C lcd(0x27,20,4); // set the LCD address to 0x27 for a 16 chars and 2 line display
|
||||
|
||||
void setup()
|
||||
{
|
||||
|
||||
Regular → Executable
Executable
+16
@@ -0,0 +1,16 @@
|
||||
{
|
||||
"name": "LiquidCrystal_I2C",
|
||||
"keywords": "LCD, liquidcrystal, I2C",
|
||||
"description": "A library for DFRobot I2C LCD displays",
|
||||
"repository":
|
||||
{
|
||||
"type": "git",
|
||||
"url": "https://github.com/marcoschwartz/LiquidCrystal_I2C.git"
|
||||
},
|
||||
"frameworks": "arduino",
|
||||
"platforms":
|
||||
[
|
||||
"atmelavr",
|
||||
"espressif8266"
|
||||
]
|
||||
}
|
||||
Executable
+9
@@ -0,0 +1,9 @@
|
||||
name=LiquidCrystal_I2C
|
||||
version=1.1.4
|
||||
author=Frank de Brabander
|
||||
maintainer=Marco Schwartz <marcolivier.schwartz@gmail.com>
|
||||
sentence=A library for I2C LCD displays.
|
||||
paragraph= The library allows to control I2C displays with functions extremely similar to LiquidCrystal library. THIS LIBRARY MIGHT NOT BE COMPATIBLE WITH EXISTING SKETCHES.
|
||||
category=Display
|
||||
url=https://github.com/marcoschwartz/LiquidCrystal_I2C
|
||||
architectures=avr
|
||||
Executable
+362
@@ -0,0 +1,362 @@
|
||||
// ---------------------------------------------------------------------------
|
||||
// Created by Tim Eckel - teckel@leethost.com
|
||||
// Copyright 2016 License: GNU GPL v3 http://www.gnu.org/licenses/gpl.html
|
||||
//
|
||||
// See "NewPing.h" for purpose, syntax, version history, links, and more.
|
||||
// ---------------------------------------------------------------------------
|
||||
|
||||
#include "NewPing.h"
|
||||
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// NewPing constructor
|
||||
// ---------------------------------------------------------------------------
|
||||
|
||||
NewPing::NewPing(uint8_t trigger_pin, uint8_t echo_pin, unsigned int max_cm_distance) {
|
||||
#if DO_BITWISE == true
|
||||
_triggerBit = digitalPinToBitMask(trigger_pin); // Get the port register bitmask for the trigger pin.
|
||||
_echoBit = digitalPinToBitMask(echo_pin); // Get the port register bitmask for the echo pin.
|
||||
|
||||
_triggerOutput = portOutputRegister(digitalPinToPort(trigger_pin)); // Get the output port register for the trigger pin.
|
||||
_echoInput = portInputRegister(digitalPinToPort(echo_pin)); // Get the input port register for the echo pin.
|
||||
|
||||
_triggerMode = (uint8_t *) portModeRegister(digitalPinToPort(trigger_pin)); // Get the port mode register for the trigger pin.
|
||||
#else
|
||||
_triggerPin = trigger_pin;
|
||||
_echoPin = echo_pin;
|
||||
#endif
|
||||
|
||||
set_max_distance(max_cm_distance); // Call function to set the max sensor distance.
|
||||
|
||||
#if (defined (__arm__) && defined (TEENSYDUINO)) || DO_BITWISE != true
|
||||
pinMode(echo_pin, INPUT); // Set echo pin to input (on Teensy 3.x (ARM), pins default to disabled, at least one pinMode() is needed for GPIO mode).
|
||||
pinMode(trigger_pin, OUTPUT); // Set trigger pin to output (on Teensy 3.x (ARM), pins default to disabled, at least one pinMode() is needed for GPIO mode).
|
||||
#endif
|
||||
|
||||
#if defined (ARDUINO_AVR_YUN)
|
||||
pinMode(echo_pin, INPUT); // Set echo pin to input for the Arduino Yun, not sure why it doesn't default this way.
|
||||
#endif
|
||||
|
||||
#if ONE_PIN_ENABLED != true && DO_BITWISE == true
|
||||
*_triggerMode |= _triggerBit; // Set trigger pin to output.
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// Standard ping methods
|
||||
// ---------------------------------------------------------------------------
|
||||
|
||||
unsigned int NewPing::ping(unsigned int max_cm_distance) {
|
||||
if (max_cm_distance > 0) set_max_distance(max_cm_distance); // Call function to set a new max sensor distance.
|
||||
|
||||
if (!ping_trigger()) return NO_ECHO; // Trigger a ping, if it returns false, return NO_ECHO to the calling function.
|
||||
|
||||
#if URM37_ENABLED == true
|
||||
#if DO_BITWISE == true
|
||||
while (!(*_echoInput & _echoBit)) // Wait for the ping echo.
|
||||
#else
|
||||
while (!digitalRead(_echoPin)) // Wait for the ping echo.
|
||||
#endif
|
||||
if (micros() > _max_time) return NO_ECHO; // Stop the loop and return NO_ECHO (false) if we're beyond the set maximum distance.
|
||||
#else
|
||||
#if DO_BITWISE == true
|
||||
while (*_echoInput & _echoBit) // Wait for the ping echo.
|
||||
#else
|
||||
while (digitalRead(_echoPin)) // Wait for the ping echo.
|
||||
#endif
|
||||
if (micros() > _max_time) return NO_ECHO; // Stop the loop and return NO_ECHO (false) if we're beyond the set maximum distance.
|
||||
#endif
|
||||
|
||||
return (micros() - (_max_time - _maxEchoTime) - PING_OVERHEAD); // Calculate ping time, include overhead.
|
||||
}
|
||||
|
||||
|
||||
unsigned long NewPing::ping_cm(unsigned int max_cm_distance) {
|
||||
unsigned long echoTime = NewPing::ping(max_cm_distance); // Calls the ping method and returns with the ping echo distance in uS.
|
||||
#if ROUNDING_ENABLED == false
|
||||
return (echoTime / US_ROUNDTRIP_CM); // Call the ping method and returns the distance in centimeters (no rounding).
|
||||
#else
|
||||
return NewPingConvert(echoTime, US_ROUNDTRIP_CM); // Convert uS to centimeters.
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
unsigned long NewPing::ping_in(unsigned int max_cm_distance) {
|
||||
unsigned long echoTime = NewPing::ping(max_cm_distance); // Calls the ping method and returns with the ping echo distance in uS.
|
||||
#if ROUNDING_ENABLED == false
|
||||
return (echoTime / US_ROUNDTRIP_IN); // Call the ping method and returns the distance in inches (no rounding).
|
||||
#else
|
||||
return NewPingConvert(echoTime, US_ROUNDTRIP_IN); // Convert uS to inches.
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
unsigned long NewPing::ping_median(uint8_t it, unsigned int max_cm_distance) {
|
||||
unsigned int uS[it], last;
|
||||
uint8_t j, i = 0;
|
||||
unsigned long t;
|
||||
uS[0] = NO_ECHO;
|
||||
|
||||
while (i < it) {
|
||||
t = micros(); // Start ping timestamp.
|
||||
last = ping(max_cm_distance); // Send ping.
|
||||
|
||||
if (last != NO_ECHO) { // Ping in range, include as part of median.
|
||||
if (i > 0) { // Don't start sort till second ping.
|
||||
for (j = i; j > 0 && uS[j - 1] < last; j--) // Insertion sort loop.
|
||||
uS[j] = uS[j - 1]; // Shift ping array to correct position for sort insertion.
|
||||
} else j = 0; // First ping is sort starting point.
|
||||
uS[j] = last; // Add last ping to array in sorted position.
|
||||
i++; // Move to next ping.
|
||||
} else it--; // Ping out of range, skip and don't include as part of median.
|
||||
|
||||
if (i < it && micros() - t < PING_MEDIAN_DELAY)
|
||||
delay((PING_MEDIAN_DELAY + t - micros()) / 1000); // Millisecond delay between pings.
|
||||
|
||||
}
|
||||
return (uS[it >> 1]); // Return the ping distance median.
|
||||
}
|
||||
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// Standard and timer interrupt ping method support functions (not called directly)
|
||||
// ---------------------------------------------------------------------------
|
||||
|
||||
boolean NewPing::ping_trigger() {
|
||||
#if DO_BITWISE == true
|
||||
#if ONE_PIN_ENABLED == true
|
||||
*_triggerMode |= _triggerBit; // Set trigger pin to output.
|
||||
#endif
|
||||
|
||||
*_triggerOutput &= ~_triggerBit; // Set the trigger pin low, should already be low, but this will make sure it is.
|
||||
delayMicroseconds(4); // Wait for pin to go low.
|
||||
*_triggerOutput |= _triggerBit; // Set trigger pin high, this tells the sensor to send out a ping.
|
||||
delayMicroseconds(10); // Wait long enough for the sensor to realize the trigger pin is high. Sensor specs say to wait 10uS.
|
||||
*_triggerOutput &= ~_triggerBit; // Set trigger pin back to low.
|
||||
|
||||
#if ONE_PIN_ENABLED == true
|
||||
*_triggerMode &= ~_triggerBit; // Set trigger pin to input (when using one Arduino pin, this is technically setting the echo pin to input as both are tied to the same Arduino pin).
|
||||
#endif
|
||||
|
||||
#if URM37_ENABLED == true
|
||||
if (!(*_echoInput & _echoBit)) return false; // Previous ping hasn't finished, abort.
|
||||
_max_time = micros() + _maxEchoTime + MAX_SENSOR_DELAY; // Maximum time we'll wait for ping to start (most sensors are <450uS, the SRF06 can take up to 34,300uS!)
|
||||
while (*_echoInput & _echoBit) // Wait for ping to start.
|
||||
if (micros() > _max_time) return false; // Took too long to start, abort.
|
||||
#else
|
||||
if (*_echoInput & _echoBit) return false; // Previous ping hasn't finished, abort.
|
||||
_max_time = micros() + _maxEchoTime + MAX_SENSOR_DELAY; // Maximum time we'll wait for ping to start (most sensors are <450uS, the SRF06 can take up to 34,300uS!)
|
||||
while (!(*_echoInput & _echoBit)) // Wait for ping to start.
|
||||
if (micros() > _max_time) return false; // Took too long to start, abort.
|
||||
#endif
|
||||
#else
|
||||
#if ONE_PIN_ENABLED == true
|
||||
pinMode(_triggerPin, OUTPUT); // Set trigger pin to output.
|
||||
#endif
|
||||
|
||||
digitalWrite(_triggerPin, LOW); // Set the trigger pin low, should already be low, but this will make sure it is.
|
||||
delayMicroseconds(4); // Wait for pin to go low.
|
||||
digitalWrite(_triggerPin, HIGH); // Set trigger pin high, this tells the sensor to send out a ping.
|
||||
delayMicroseconds(10); // Wait long enough for the sensor to realize the trigger pin is high. Sensor specs say to wait 10uS.
|
||||
digitalWrite(_triggerPin, LOW); // Set trigger pin back to low.
|
||||
|
||||
#if ONE_PIN_ENABLED == true
|
||||
pinMode(_triggerPin, INPUT); // Set trigger pin to input (when using one Arduino pin, this is technically setting the echo pin to input as both are tied to the same Arduino pin).
|
||||
#endif
|
||||
|
||||
#if URM37_ENABLED == true
|
||||
if (!digitalRead(_echoPin)) return false; // Previous ping hasn't finished, abort.
|
||||
_max_time = micros() + _maxEchoTime + MAX_SENSOR_DELAY; // Maximum time we'll wait for ping to start (most sensors are <450uS, the SRF06 can take up to 34,300uS!)
|
||||
while (digitalRead(_echoPin)) // Wait for ping to start.
|
||||
if (micros() > _max_time) return false; // Took too long to start, abort.
|
||||
#else
|
||||
if (digitalRead(_echoPin)) return false; // Previous ping hasn't finished, abort.
|
||||
_max_time = micros() + _maxEchoTime + MAX_SENSOR_DELAY; // Maximum time we'll wait for ping to start (most sensors are <450uS, the SRF06 can take up to 34,300uS!)
|
||||
while (!digitalRead(_echoPin)) // Wait for ping to start.
|
||||
if (micros() > _max_time) return false; // Took too long to start, abort.
|
||||
#endif
|
||||
#endif
|
||||
|
||||
_max_time = micros() + _maxEchoTime; // Ping started, set the time-out.
|
||||
return true; // Ping started successfully.
|
||||
}
|
||||
|
||||
|
||||
void NewPing::set_max_distance(unsigned int max_cm_distance) {
|
||||
#if ROUNDING_ENABLED == false
|
||||
_maxEchoTime = min(max_cm_distance + 1, (unsigned int) MAX_SENSOR_DISTANCE + 1) * US_ROUNDTRIP_CM; // Calculate the maximum distance in uS (no rounding).
|
||||
#else
|
||||
_maxEchoTime = min(max_cm_distance, (unsigned int) MAX_SENSOR_DISTANCE) * US_ROUNDTRIP_CM + (US_ROUNDTRIP_CM / 2); // Calculate the maximum distance in uS.
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
#if TIMER_ENABLED == true && DO_BITWISE == true
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// Timer interrupt ping methods (won't work with non-AVR, ATmega128 and all ATtiny microcontrollers)
|
||||
// ---------------------------------------------------------------------------
|
||||
|
||||
void NewPing::ping_timer(void (*userFunc)(void), unsigned int max_cm_distance) {
|
||||
if (max_cm_distance > 0) set_max_distance(max_cm_distance); // Call function to set a new max sensor distance.
|
||||
|
||||
if (!ping_trigger()) return; // Trigger a ping, if it returns false, return without starting the echo timer.
|
||||
timer_us(ECHO_TIMER_FREQ, userFunc); // Set ping echo timer check every ECHO_TIMER_FREQ uS.
|
||||
}
|
||||
|
||||
|
||||
boolean NewPing::check_timer() {
|
||||
if (micros() > _max_time) { // Outside the time-out limit.
|
||||
timer_stop(); // Disable timer interrupt
|
||||
return false; // Cancel ping timer.
|
||||
}
|
||||
|
||||
#if URM37_ENABLED == false
|
||||
if (!(*_echoInput & _echoBit)) { // Ping echo received.
|
||||
#else
|
||||
if (*_echoInput & _echoBit) { // Ping echo received.
|
||||
#endif
|
||||
timer_stop(); // Disable timer interrupt
|
||||
ping_result = (micros() - (_max_time - _maxEchoTime) - PING_TIMER_OVERHEAD); // Calculate ping time including overhead.
|
||||
return true; // Return ping echo true.
|
||||
}
|
||||
|
||||
return false; // Return false because there's no ping echo yet.
|
||||
}
|
||||
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// Timer2/Timer4 interrupt methods (can be used for non-ultrasonic needs)
|
||||
// ---------------------------------------------------------------------------
|
||||
|
||||
// Variables used for timer functions
|
||||
void (*intFunc)();
|
||||
void (*intFunc2)();
|
||||
unsigned long _ms_cnt_reset;
|
||||
volatile unsigned long _ms_cnt;
|
||||
#if defined(__arm__) && defined(TEENSYDUINO)
|
||||
IntervalTimer itimer;
|
||||
#endif
|
||||
|
||||
|
||||
void NewPing::timer_us(unsigned int frequency, void (*userFunc)(void)) {
|
||||
intFunc = userFunc; // User's function to call when there's a timer event.
|
||||
timer_setup(); // Configure the timer interrupt.
|
||||
|
||||
#if defined (__AVR_ATmega32U4__) // Use Timer4 for ATmega32U4 (Teensy/Leonardo).
|
||||
OCR4C = min((frequency>>2) - 1, 255); // Every count is 4uS, so divide by 4 (bitwise shift right 2) subtract one, then make sure we don't go over 255 limit.
|
||||
TIMSK4 = (1<<TOIE4); // Enable Timer4 interrupt.
|
||||
#elif defined (__arm__) && defined (TEENSYDUINO) // Timer for Teensy 3.x
|
||||
itimer.begin(userFunc, frequency); // Really simple on the Teensy 3.x, calls userFunc every 'frequency' uS.
|
||||
#else
|
||||
OCR2A = min((frequency>>2) - 1, 255); // Every count is 4uS, so divide by 4 (bitwise shift right 2) subtract one, then make sure we don't go over 255 limit.
|
||||
TIMSK2 |= (1<<OCIE2A); // Enable Timer2 interrupt.
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
void NewPing::timer_ms(unsigned long frequency, void (*userFunc)(void)) {
|
||||
intFunc = NewPing::timer_ms_cntdwn; // Timer events are sent here once every ms till user's frequency is reached.
|
||||
intFunc2 = userFunc; // User's function to call when user's frequency is reached.
|
||||
_ms_cnt = _ms_cnt_reset = frequency; // Current ms counter and reset value.
|
||||
timer_setup(); // Configure the timer interrupt.
|
||||
|
||||
#if defined (__AVR_ATmega32U4__) // Use Timer4 for ATmega32U4 (Teensy/Leonardo).
|
||||
OCR4C = 249; // Every count is 4uS, so 1ms = 250 counts - 1.
|
||||
TIMSK4 = (1<<TOIE4); // Enable Timer4 interrupt.
|
||||
#elif defined (__arm__) && defined (TEENSYDUINO) // Timer for Teensy 3.x
|
||||
itimer.begin(NewPing::timer_ms_cntdwn, 1000); // Set timer to 1ms (1000 uS).
|
||||
#else
|
||||
OCR2A = 249; // Every count is 4uS, so 1ms = 250 counts - 1.
|
||||
TIMSK2 |= (1<<OCIE2A); // Enable Timer2 interrupt.
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
void NewPing::timer_stop() { // Disable timer interrupt.
|
||||
#if defined (__AVR_ATmega32U4__) // Use Timer4 for ATmega32U4 (Teensy/Leonardo).
|
||||
TIMSK4 = 0;
|
||||
#elif defined (__arm__) && defined (TEENSYDUINO) // Timer for Teensy 3.x
|
||||
itimer.end();
|
||||
#else
|
||||
TIMSK2 &= ~(1<<OCIE2A);
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// Timer2/Timer4 interrupt method support functions (not called directly)
|
||||
// ---------------------------------------------------------------------------
|
||||
|
||||
void NewPing::timer_setup() {
|
||||
#if defined (__AVR_ATmega32U4__) // Use Timer4 for ATmega32U4 (Teensy/Leonardo).
|
||||
timer_stop(); // Disable Timer4 interrupt.
|
||||
TCCR4A = TCCR4C = TCCR4D = TCCR4E = 0;
|
||||
TCCR4B = (1<<CS42) | (1<<CS41) | (1<<CS40) | (1<<PSR4); // Set Timer4 prescaler to 64 (4uS/count, 4uS-1020uS range).
|
||||
TIFR4 = (1<<TOV4);
|
||||
TCNT4 = 0; // Reset Timer4 counter.
|
||||
#elif defined (__AVR_ATmega8__) || defined (__AVR_ATmega16__) || defined (__AVR_ATmega32__) || defined (__AVR_ATmega8535__) // Alternate timer commands for certain microcontrollers.
|
||||
timer_stop(); // Disable Timer2 interrupt.
|
||||
ASSR &= ~(1<<AS2); // Set clock, not pin.
|
||||
TCCR2 = (1<<WGM21 | 1<<CS22); // Set Timer2 to CTC mode, prescaler to 64 (4uS/count, 4uS-1020uS range).
|
||||
TCNT2 = 0; // Reset Timer2 counter.
|
||||
#elif defined (__arm__) && defined (TEENSYDUINO)
|
||||
timer_stop(); // Stop the timer.
|
||||
#else
|
||||
timer_stop(); // Disable Timer2 interrupt.
|
||||
ASSR &= ~(1<<AS2); // Set clock, not pin.
|
||||
TCCR2A = (1<<WGM21); // Set Timer2 to CTC mode.
|
||||
TCCR2B = (1<<CS22); // Set Timer2 prescaler to 64 (4uS/count, 4uS-1020uS range).
|
||||
TCNT2 = 0; // Reset Timer2 counter.
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
void NewPing::timer_ms_cntdwn() {
|
||||
if (!_ms_cnt--) { // Count down till we reach zero.
|
||||
intFunc2(); // Scheduled time reached, run the main timer event function.
|
||||
_ms_cnt = _ms_cnt_reset; // Reset the ms timer.
|
||||
}
|
||||
}
|
||||
|
||||
#if defined (__AVR_ATmega32U4__) // Use Timer4 for ATmega32U4 (Teensy/Leonardo).
|
||||
ISR(TIMER4_OVF_vect) {
|
||||
intFunc(); // Call wrapped function.
|
||||
}
|
||||
#elif defined (__AVR_ATmega8__) || defined (__AVR_ATmega16__) || defined (__AVR_ATmega32__) || defined (__AVR_ATmega8535__) // Alternate timer commands for certain microcontrollers.
|
||||
ISR(TIMER2_COMP_vect) {
|
||||
intFunc(); // Call wrapped function.
|
||||
}
|
||||
#elif defined (__arm__)
|
||||
// Do nothing...
|
||||
#else
|
||||
ISR(TIMER2_COMPA_vect) {
|
||||
intFunc(); // Call wrapped function.
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// Conversion methods (rounds result to nearest cm or inch).
|
||||
// ---------------------------------------------------------------------------
|
||||
|
||||
unsigned int NewPing::convert_cm(unsigned int echoTime) {
|
||||
#if ROUNDING_ENABLED == false
|
||||
return (echoTime / US_ROUNDTRIP_CM); // Convert uS to centimeters (no rounding).
|
||||
#else
|
||||
return NewPingConvert(echoTime, US_ROUNDTRIP_CM); // Convert uS to centimeters.
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
unsigned int NewPing::convert_in(unsigned int echoTime) {
|
||||
#if ROUNDING_ENABLED == false
|
||||
return (echoTime / US_ROUNDTRIP_IN); // Convert uS to inches (no rounding).
|
||||
#else
|
||||
return NewPingConvert(echoTime, US_ROUNDTRIP_IN); // Convert uS to inches.
|
||||
#endif
|
||||
}
|
||||
Executable
+245
@@ -0,0 +1,245 @@
|
||||
// ---------------------------------------------------------------------------
|
||||
// NewPing Library - v1.8 - 07/30/2016
|
||||
//
|
||||
// AUTHOR/LICENSE:
|
||||
// Created by Tim Eckel - teckel@leethost.com
|
||||
// Copyright 2016 License: GNU GPL v3 http://www.gnu.org/licenses/gpl.html
|
||||
//
|
||||
// LINKS:
|
||||
// Project home: https://bitbucket.org/teckel12/arduino-new-ping/wiki/Home
|
||||
// Blog: http://arduino.cc/forum/index.php/topic,106043.0.html
|
||||
//
|
||||
// DISCLAIMER:
|
||||
// This software is furnished "as is", without technical support, and with no
|
||||
// warranty, express or implied, as to its usefulness for any purpose.
|
||||
//
|
||||
// BACKGROUND:
|
||||
// When I first received an ultrasonic sensor I was not happy with how poorly
|
||||
// it worked. Quickly I realized the problem wasn't the sensor, it was the
|
||||
// available ping and ultrasonic libraries causing the problem. The NewPing
|
||||
// library totally fixes these problems, adds many new features, and breaths
|
||||
// new life into these very affordable distance sensors.
|
||||
//
|
||||
// FEATURES:
|
||||
// * Works with many different ultrasonic sensors: SR04, SRF05, SRF06, DYP-ME007, URM37 & Parallax PING))).
|
||||
// * Compatible with the entire Arduino line-up (and clones), Teensy family (including $19 96Mhz 32 bit Teensy 3.2) and non-AVR microcontrollers.
|
||||
// * Interface with all but the SRF06 sensor using only one Arduino pin.
|
||||
// * Doesn't lag for a full second if no ping/echo is received.
|
||||
// * Ping sensors consistently and reliably at up to 30 times per second.
|
||||
// * Timer interrupt method for event-driven sketches.
|
||||
// * Built-in digital filter method ping_median() for easy error correction.
|
||||
// * Uses port registers for a faster pin interface and smaller code size.
|
||||
// * Allows you to set a maximum distance where pings beyond that distance are read as no ping "clear".
|
||||
// * Ease of using multiple sensors (example sketch with 15 sensors).
|
||||
// * More accurate distance calculation (cm, inches & uS).
|
||||
// * Doesn't use pulseIn, which is slow and gives incorrect results with some ultrasonic sensor models.
|
||||
// * Actively developed with features being added and bugs/issues addressed.
|
||||
//
|
||||
// CONSTRUCTOR:
|
||||
// NewPing sonar(trigger_pin, echo_pin [, max_cm_distance])
|
||||
// trigger_pin & echo_pin - Arduino pins connected to sensor trigger and echo.
|
||||
// NOTE: To use the same Arduino pin for trigger and echo, specify the same pin for both values.
|
||||
// max_cm_distance - [Optional] Maximum distance you wish to sense. Default=500cm.
|
||||
//
|
||||
// METHODS:
|
||||
// sonar.ping([max_cm_distance]) - Send a ping and get the echo time (in microseconds) as a result. [max_cm_distance] allows you to optionally set a new max distance.
|
||||
// sonar.ping_in([max_cm_distance]) - Send a ping and get the distance in whole inches. [max_cm_distance] allows you to optionally set a new max distance.
|
||||
// sonar.ping_cm([max_cm_distance]) - Send a ping and get the distance in whole centimeters. [max_cm_distance] allows you to optionally set a new max distance.
|
||||
// sonar.ping_median(iterations [, max_cm_distance]) - Do multiple pings (default=5), discard out of range pings and return median in microseconds. [max_cm_distance] allows you to optionally set a new max distance.
|
||||
// NewPing::convert_in(echoTime) - Convert echoTime from microseconds to inches (rounds to nearest inch).
|
||||
// NewPing::convert_cm(echoTime) - Convert echoTime from microseconds to centimeters (rounds to nearest cm).
|
||||
// sonar.ping_timer(function [, max_cm_distance]) - Send a ping and call function to test if ping is complete. [max_cm_distance] allows you to optionally set a new max distance.
|
||||
// sonar.check_timer() - Check if ping has returned within the set distance limit.
|
||||
// NewPing::timer_us(frequency, function) - Call function every frequency microseconds.
|
||||
// NewPing::timer_ms(frequency, function) - Call function every frequency milliseconds.
|
||||
// NewPing::timer_stop() - Stop the timer.
|
||||
//
|
||||
// HISTORY:
|
||||
// 07/30/2016 v1.8 - Added support for non-AVR microcontrollers. For non-AVR
|
||||
// microcontrollers, advanced ping_timer() timer methods are disabled due to
|
||||
// inconsistencies or no support at all between platforms. However, standard
|
||||
// ping methods are all supported. Added new optional variable to ping(),
|
||||
// ping_in(), ping_cm(), ping_median(), and ping_timer() methods which allows
|
||||
// you to set a new maximum distance for each ping. Added support for the
|
||||
// ATmega16, ATmega32 and ATmega8535 microcontrollers. Changed convert_cm()
|
||||
// and convert_in() methods to static members. You can now call them without
|
||||
// an object. For example: cm = NewPing::convert_cm(distance);
|
||||
//
|
||||
// 09/29/2015 v1.7 - Removed support for the Arduino Due and Zero because
|
||||
// they're both 3.3 volt boards and are not 5 volt tolerant while the HC-SR04
|
||||
// is a 5 volt sensor. Also, the Due and Zero don't support pin manipulation
|
||||
// compatibility via port registers which can be done (see the Teensy 3.2).
|
||||
//
|
||||
// 06/17/2014 v1.6 - Corrected delay between pings when using ping_median()
|
||||
// method. Added support for the URM37 sensor (must change URM37_ENABLED from
|
||||
// false to true). Added support for Arduino microcontrollers like the $20
|
||||
// 32 bit ARM Cortex-M4 based Teensy 3.2. Added automatic support for the
|
||||
// Atmel ATtiny family of microcontrollers. Added timer support for the
|
||||
// ATmega8 microcontroller. Rounding disabled by default, reduces compiled
|
||||
// code size (can be turned on with ROUNDING_ENABLED switch). Added
|
||||
// TIMER_ENABLED switch to get around compile-time "__vector_7" errors when
|
||||
// using the Tone library, or you can use the toneAC, NewTone or
|
||||
// TimerFreeTone libraries: https://bitbucket.org/teckel12/arduino-toneac/
|
||||
// Other speed and compiled size optimizations.
|
||||
//
|
||||
// 08/15/2012 v1.5 - Added ping_median() method which does a user specified
|
||||
// number of pings (default=5) and returns the median ping in microseconds
|
||||
// (out of range pings ignored). This is a very effective digital filter.
|
||||
// Optimized for smaller compiled size (even smaller than sketches that
|
||||
// don't use a library).
|
||||
//
|
||||
// 07/14/2012 v1.4 - Added support for the Parallax PING)))� sensor. Interface
|
||||
// with all but the SRF06 sensor using only one Arduino pin. You can also
|
||||
// interface with the SRF06 using one pin if you install a 0.1uf capacitor
|
||||
// on the trigger and echo pins of the sensor then tie the trigger pin to
|
||||
// the Arduino pin (doesn't work with Teensy). To use the same Arduino pin
|
||||
// for trigger and echo, specify the same pin for both values. Various bug
|
||||
// fixes.
|
||||
//
|
||||
// 06/08/2012 v1.3 - Big feature addition, event-driven ping! Uses Timer2
|
||||
// interrupt, so be mindful of PWM or timing conflicts messing with Timer2
|
||||
// may cause (namely PWM on pins 3 & 11 on Arduino, PWM on pins 9 and 10 on
|
||||
// Mega, and Tone library). Simple to use timer interrupt functions you can
|
||||
// use in your sketches totally unrelated to ultrasonic sensors (don't use if
|
||||
// you're also using NewPing's ping_timer because both use Timer2 interrupts).
|
||||
// Loop counting ping method deleted in favor of timing ping method after
|
||||
// inconsistent results kept surfacing with the loop timing ping method.
|
||||
// Conversion to cm and inches now rounds to the nearest cm or inch. Code
|
||||
// optimized to save program space and fixed a couple minor bugs here and
|
||||
// there. Many new comments added as well as line spacing to group code
|
||||
// sections for better source readability.
|
||||
//
|
||||
// 05/25/2012 v1.2 - Lots of code clean-up thanks to Arduino Forum members.
|
||||
// Rebuilt the ping timing code from scratch, ditched the pulseIn code as it
|
||||
// doesn't give correct results (at least with ping sensors). The NewPing
|
||||
// library is now VERY accurate and the code was simplified as a bonus.
|
||||
// Smaller and faster code as well. Fixed some issues with very close ping
|
||||
// results when converting to inches. All functions now return 0 only when
|
||||
// there's no ping echo (out of range) and a positive value for a successful
|
||||
// ping. This can effectively be used to detect if something is out of range
|
||||
// or in-range and at what distance. Now compatible with Arduino 0023.
|
||||
//
|
||||
// 05/16/2012 v1.1 - Changed all I/O functions to use low-level port registers
|
||||
// for ultra-fast and lean code (saves from 174 to 394 bytes). Tested on both
|
||||
// the Arduino Uno and Teensy 2.0 but should work on all Arduino-based
|
||||
// platforms because it calls standard functions to retrieve port registers
|
||||
// and bit masks. Also made a couple minor fixes to defines.
|
||||
//
|
||||
// 05/15/2012 v1.0 - Initial release.
|
||||
// ---------------------------------------------------------------------------
|
||||
|
||||
#ifndef NewPing_h
|
||||
#define NewPing_h
|
||||
|
||||
#if defined (ARDUINO) && ARDUINO >= 100
|
||||
#include <Arduino.h>
|
||||
#else
|
||||
#include <WProgram.h>
|
||||
#include <pins_arduino.h>
|
||||
#endif
|
||||
|
||||
#if defined (__AVR__)
|
||||
#include <avr/io.h>
|
||||
#include <avr/interrupt.h>
|
||||
#endif
|
||||
|
||||
// Shouldn't need to change these values unless you have a specific need to do so.
|
||||
#define MAX_SENSOR_DISTANCE 500 // Maximum sensor distance can be as high as 500cm, no reason to wait for ping longer than sound takes to travel this distance and back. Default=500
|
||||
#define US_ROUNDTRIP_CM 57 // Microseconds (uS) it takes sound to travel round-trip 1cm (2cm total), uses integer to save compiled code space. Default=57
|
||||
#define US_ROUNDTRIP_IN 146 // Microseconds (uS) it takes sound to travel round-trip 1 inch (2 inches total), uses integer to save compiled code space. Defalult=146
|
||||
#define ONE_PIN_ENABLED true // Set to "false" to disable one pin mode which saves around 14-26 bytes of binary size. Default=true
|
||||
#define ROUNDING_ENABLED false // Set to "true" to enable distance rounding which also adds 64 bytes to binary size. Default=false
|
||||
#define URM37_ENABLED false // Set to "true" to enable support for the URM37 sensor in PWM mode. Default=false
|
||||
#define TIMER_ENABLED true // Set to "false" to disable the timer ISR (if getting "__vector_7" compile errors set this to false). Default=true
|
||||
|
||||
// Probably shouldn't change these values unless you really know what you're doing.
|
||||
#define NO_ECHO 0 // Value returned if there's no ping echo within the specified MAX_SENSOR_DISTANCE or max_cm_distance. Default=0
|
||||
#define MAX_SENSOR_DELAY 5800 // Maximum uS it takes for sensor to start the ping. Default=5800
|
||||
#define ECHO_TIMER_FREQ 24 // Frequency to check for a ping echo (every 24uS is about 0.4cm accuracy). Default=24
|
||||
#define PING_MEDIAN_DELAY 29000 // Microsecond delay between pings in the ping_median method. Default=29000
|
||||
#define PING_OVERHEAD 5 // Ping overhead in microseconds (uS). Default=5
|
||||
#define PING_TIMER_OVERHEAD 13 // Ping timer overhead in microseconds (uS). Default=13
|
||||
#if URM37_ENABLED == true
|
||||
#undef US_ROUNDTRIP_CM
|
||||
#undef US_ROUNDTRIP_IN
|
||||
#define US_ROUNDTRIP_CM 50 // Every 50uS PWM signal is low indicates 1cm distance. Default=50
|
||||
#define US_ROUNDTRIP_IN 127 // If 50uS is 1cm, 1 inch would be 127uS (50 x 2.54 = 127). Default=127
|
||||
#endif
|
||||
|
||||
// Conversion from uS to distance (round result to nearest cm or inch).
|
||||
#define NewPingConvert(echoTime, conversionFactor) (max(((unsigned int)echoTime + conversionFactor / 2) / conversionFactor, (echoTime ? 1 : 0)))
|
||||
|
||||
// Detect non-AVR microcontrollers (Teensy 3.x, Arduino DUE, etc.) and don't use port registers or timer interrupts as required.
|
||||
#if (defined (__arm__) && defined (TEENSYDUINO))
|
||||
#undef PING_OVERHEAD
|
||||
#define PING_OVERHEAD 1
|
||||
#undef PING_TIMER_OVERHEAD
|
||||
#define PING_TIMER_OVERHEAD 1
|
||||
#define DO_BITWISE true
|
||||
#elif !defined (__AVR__)
|
||||
#undef PING_OVERHEAD
|
||||
#define PING_OVERHEAD 1
|
||||
#undef PING_TIMER_OVERHEAD
|
||||
#define PING_TIMER_OVERHEAD 1
|
||||
#undef TIMER_ENABLED
|
||||
#define TIMER_ENABLED false
|
||||
#define DO_BITWISE false
|
||||
#else
|
||||
#define DO_BITWISE true
|
||||
#endif
|
||||
|
||||
// Disable the timer interrupts when using ATmega128 and all ATtiny microcontrollers.
|
||||
#if defined (__AVR_ATmega128__) || defined (__AVR_ATtiny24__) || defined (__AVR_ATtiny44__) || defined (__AVR_ATtiny84__) || defined (__AVR_ATtiny25__) || defined (__AVR_ATtiny45__) || defined (__AVR_ATtiny85__) || defined (__AVR_ATtiny261__) || defined (__AVR_ATtiny461__) || defined (__AVR_ATtiny861__) || defined (__AVR_ATtiny43U__)
|
||||
#undef TIMER_ENABLED
|
||||
#define TIMER_ENABLED false
|
||||
#endif
|
||||
|
||||
// Define timers when using ATmega8, ATmega16, ATmega32 and ATmega8535 microcontrollers.
|
||||
#if defined (__AVR_ATmega8__) || defined (__AVR_ATmega16__) || defined (__AVR_ATmega32__) || defined (__AVR_ATmega8535__)
|
||||
#define OCR2A OCR2
|
||||
#define TIMSK2 TIMSK
|
||||
#define OCIE2A OCIE2
|
||||
#endif
|
||||
|
||||
class NewPing {
|
||||
public:
|
||||
NewPing(uint8_t trigger_pin, uint8_t echo_pin, unsigned int max_cm_distance = MAX_SENSOR_DISTANCE);
|
||||
unsigned int ping(unsigned int max_cm_distance = 0);
|
||||
unsigned long ping_cm(unsigned int max_cm_distance = 0);
|
||||
unsigned long ping_in(unsigned int max_cm_distance = 0);
|
||||
unsigned long ping_median(uint8_t it = 5, unsigned int max_cm_distance = 0);
|
||||
static unsigned int convert_cm(unsigned int echoTime);
|
||||
static unsigned int convert_in(unsigned int echoTime);
|
||||
#if TIMER_ENABLED == true
|
||||
void ping_timer(void (*userFunc)(void), unsigned int max_cm_distance = 0);
|
||||
boolean check_timer();
|
||||
unsigned long ping_result;
|
||||
static void timer_us(unsigned int frequency, void (*userFunc)(void));
|
||||
static void timer_ms(unsigned long frequency, void (*userFunc)(void));
|
||||
static void timer_stop();
|
||||
#endif
|
||||
private:
|
||||
boolean ping_trigger();
|
||||
void set_max_distance(unsigned int max_cm_distance);
|
||||
#if TIMER_ENABLED == true
|
||||
boolean ping_trigger_timer(unsigned int trigger_delay);
|
||||
boolean ping_wait_timer();
|
||||
static void timer_setup();
|
||||
static void timer_ms_cntdwn();
|
||||
#endif
|
||||
#if DO_BITWISE == true
|
||||
uint8_t _triggerBit;
|
||||
uint8_t _echoBit;
|
||||
volatile uint8_t *_triggerOutput;
|
||||
volatile uint8_t *_echoInput;
|
||||
volatile uint8_t *_triggerMode;
|
||||
#else
|
||||
uint8_t _triggerPin;
|
||||
uint8_t _echoPin;
|
||||
#endif
|
||||
unsigned int _maxEchoTime;
|
||||
unsigned long _max_time;
|
||||
};
|
||||
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,75 @@
|
||||
// ---------------------------------------------------------------------------
|
||||
// This example code was used to successfully communicate with 15 ultrasonic sensors. You can adjust
|
||||
// the number of sensors in your project by changing SONAR_NUM and the number of NewPing objects in the
|
||||
// "sonar" array. You also need to change the pins for each sensor for the NewPing objects. Each sensor
|
||||
// is pinged at 33ms intervals. So, one cycle of all sensors takes 495ms (33 * 15 = 495ms). The results
|
||||
// are sent to the "oneSensorCycle" function which currently just displays the distance data. Your project
|
||||
// would normally process the sensor results in this function (for example, decide if a robot needs to
|
||||
// turn and call the turn function). Keep in mind this example is event-driven. Your complete sketch needs
|
||||
// to be written so there's no "delay" commands and the loop() cycles at faster than a 33ms rate. If other
|
||||
// processes take longer than 33ms, you'll need to increase PING_INTERVAL so it doesn't get behind.
|
||||
// ---------------------------------------------------------------------------
|
||||
#include <NewPing.h>
|
||||
|
||||
#define SONAR_NUM 15 // Number of sensors.
|
||||
#define MAX_DISTANCE 200 // Maximum distance (in cm) to ping.
|
||||
#define PING_INTERVAL 33 // Milliseconds between sensor pings (29ms is about the min to avoid cross-sensor echo).
|
||||
|
||||
unsigned long pingTimer[SONAR_NUM]; // Holds the times when the next ping should happen for each sensor.
|
||||
unsigned int cm[SONAR_NUM]; // Where the ping distances are stored.
|
||||
uint8_t currentSensor = 0; // Keeps track of which sensor is active.
|
||||
|
||||
NewPing sonar[SONAR_NUM] = { // Sensor object array.
|
||||
NewPing(41, 42, MAX_DISTANCE), // Each sensor's trigger pin, echo pin, and max distance to ping.
|
||||
NewPing(43, 44, MAX_DISTANCE),
|
||||
NewPing(45, 20, MAX_DISTANCE),
|
||||
NewPing(21, 22, MAX_DISTANCE),
|
||||
NewPing(23, 24, MAX_DISTANCE),
|
||||
NewPing(25, 26, MAX_DISTANCE),
|
||||
NewPing(27, 28, MAX_DISTANCE),
|
||||
NewPing(29, 30, MAX_DISTANCE),
|
||||
NewPing(31, 32, MAX_DISTANCE),
|
||||
NewPing(34, 33, MAX_DISTANCE),
|
||||
NewPing(35, 36, MAX_DISTANCE),
|
||||
NewPing(37, 38, MAX_DISTANCE),
|
||||
NewPing(39, 40, MAX_DISTANCE),
|
||||
NewPing(50, 51, MAX_DISTANCE),
|
||||
NewPing(52, 53, MAX_DISTANCE)
|
||||
};
|
||||
|
||||
void setup() {
|
||||
Serial.begin(115200);
|
||||
pingTimer[0] = millis() + 75; // First ping starts at 75ms, gives time for the Arduino to chill before starting.
|
||||
for (uint8_t i = 1; i < SONAR_NUM; i++) // Set the starting time for each sensor.
|
||||
pingTimer[i] = pingTimer[i - 1] + PING_INTERVAL;
|
||||
}
|
||||
|
||||
void loop() {
|
||||
for (uint8_t i = 0; i < SONAR_NUM; i++) { // Loop through all the sensors.
|
||||
if (millis() >= pingTimer[i]) { // Is it this sensor's time to ping?
|
||||
pingTimer[i] += PING_INTERVAL * SONAR_NUM; // Set next time this sensor will be pinged.
|
||||
if (i == 0 && currentSensor == SONAR_NUM - 1) oneSensorCycle(); // Sensor ping cycle complete, do something with the results.
|
||||
sonar[currentSensor].timer_stop(); // Make sure previous timer is canceled before starting a new ping (insurance).
|
||||
currentSensor = i; // Sensor being accessed.
|
||||
cm[currentSensor] = 0; // Make distance zero in case there's no ping echo for this sensor.
|
||||
sonar[currentSensor].ping_timer(echoCheck); // Do the ping (processing continues, interrupt will call echoCheck to look for echo).
|
||||
}
|
||||
}
|
||||
// Other code that *DOESN'T* analyze ping results can go here.
|
||||
}
|
||||
|
||||
void echoCheck() { // If ping received, set the sensor distance to array.
|
||||
if (sonar[currentSensor].check_timer())
|
||||
cm[currentSensor] = sonar[currentSensor].ping_result / US_ROUNDTRIP_CM;
|
||||
}
|
||||
|
||||
void oneSensorCycle() { // Sensor ping cycle complete, do something with the results.
|
||||
// The following code would be replaced with your code that does something with the ping results.
|
||||
for (uint8_t i = 0; i < SONAR_NUM; i++) {
|
||||
Serial.print(i);
|
||||
Serial.print("=");
|
||||
Serial.print(cm[i]);
|
||||
Serial.print("cm ");
|
||||
}
|
||||
Serial.println();
|
||||
}
|
||||
@@ -0,0 +1,46 @@
|
||||
// ---------------------------------------------------------------------------
|
||||
// This example shows how to use NewPing's ping_timer method which uses the Timer2 interrupt to get the
|
||||
// ping time. The advantage of using this method over the standard ping method is that it permits a more
|
||||
// event-driven sketch which allows you to appear to do two things at once. An example would be to ping
|
||||
// an ultrasonic sensor for a possible collision while at the same time navigating. This allows a
|
||||
// properly developed sketch to multitask. Be aware that because the ping_timer method uses Timer2,
|
||||
// other features or libraries that also use Timer2 would be effected. For example, the PWM function on
|
||||
// pins 3 & 11 on Arduino Uno (pins 9 and 11 on Arduino Mega) and the Tone library. Note, only the PWM
|
||||
// functionality of the pins is lost (as they use Timer2 to do PWM), the pins are still available to use.
|
||||
// NOTE: For Teensy/Leonardo (ATmega32U4) the library uses Timer4 instead of Timer2.
|
||||
// ---------------------------------------------------------------------------
|
||||
#include <NewPing.h>
|
||||
|
||||
#define TRIGGER_PIN 12 // Arduino pin tied to trigger pin on ping sensor.
|
||||
#define ECHO_PIN 11 // Arduino pin tied to echo pin on ping sensor.
|
||||
#define MAX_DISTANCE 200 // Maximum distance we want to ping for (in centimeters). Maximum sensor distance is rated at 400-500cm.
|
||||
|
||||
NewPing sonar(TRIGGER_PIN, ECHO_PIN, MAX_DISTANCE); // NewPing setup of pins and maximum distance.
|
||||
|
||||
unsigned int pingSpeed = 50; // How frequently are we going to send out a ping (in milliseconds). 50ms would be 20 times a second.
|
||||
unsigned long pingTimer; // Holds the next ping time.
|
||||
|
||||
void setup() {
|
||||
Serial.begin(115200); // Open serial monitor at 115200 baud to see ping results.
|
||||
pingTimer = millis(); // Start now.
|
||||
}
|
||||
|
||||
void loop() {
|
||||
// Notice how there's no delays in this sketch to allow you to do other processing in-line while doing distance pings.
|
||||
if (millis() >= pingTimer) { // pingSpeed milliseconds since last ping, do another ping.
|
||||
pingTimer += pingSpeed; // Set the next ping time.
|
||||
sonar.ping_timer(echoCheck); // Send out the ping, calls "echoCheck" function every 24uS where you can check the ping status.
|
||||
}
|
||||
// Do other stuff here, really. Think of it as multi-tasking.
|
||||
}
|
||||
|
||||
void echoCheck() { // Timer2 interrupt calls this function every 24uS where you can check the ping status.
|
||||
// Don't do anything here!
|
||||
if (sonar.check_timer()) { // This is how you check to see if the ping was received.
|
||||
// Here's where you can add code.
|
||||
Serial.print("Ping: ");
|
||||
Serial.print(sonar.ping_result / US_ROUNDTRIP_CM); // Ping returned, uS result in ping_result, convert to cm with US_ROUNDTRIP_CM.
|
||||
Serial.println("cm");
|
||||
}
|
||||
// Don't do anything here!
|
||||
}
|
||||
+22
@@ -0,0 +1,22 @@
|
||||
// ---------------------------------------------------------------------------
|
||||
// Example NewPing library sketch that does a ping about 20 times per second.
|
||||
// ---------------------------------------------------------------------------
|
||||
|
||||
#include <NewPing.h>
|
||||
|
||||
#define TRIGGER_PIN 12 // Arduino pin tied to trigger pin on the ultrasonic sensor.
|
||||
#define ECHO_PIN 11 // Arduino pin tied to echo pin on the ultrasonic sensor.
|
||||
#define MAX_DISTANCE 200 // Maximum distance we want to ping for (in centimeters). Maximum sensor distance is rated at 400-500cm.
|
||||
|
||||
NewPing sonar(TRIGGER_PIN, ECHO_PIN, MAX_DISTANCE); // NewPing setup of pins and maximum distance.
|
||||
|
||||
void setup() {
|
||||
Serial.begin(115200); // Open serial monitor at 115200 baud to see ping results.
|
||||
}
|
||||
|
||||
void loop() {
|
||||
delay(50); // Wait 50ms between pings (about 20 pings/sec). 29ms should be the shortest delay between pings.
|
||||
Serial.print("Ping: ");
|
||||
Serial.print(sonar.ping_cm()); // Send ping, get distance in cm and print result (0 = outside set distance range)
|
||||
Serial.println("cm");
|
||||
}
|
||||
+25
@@ -0,0 +1,25 @@
|
||||
// ---------------------------------------------------------------------------
|
||||
// While the NewPing library's primary goal is to interface with ultrasonic sensors, interfacing with
|
||||
// the Timer2 interrupt was a result of creating an interrupt-based ping method. Since these Timer2
|
||||
// interrupt methods were built, the library may as well provide the functionality to use these methods
|
||||
// in your sketches. This shows how simple it is (no ultrasonic sensor required). Keep in mind that
|
||||
// these methods use Timer2, as does NewPing's ping_timer method for using ultrasonic sensors. You
|
||||
// can't use ping_timer at the same time you're using timer_ms or timer_us as all use the same timer.
|
||||
// ---------------------------------------------------------------------------
|
||||
|
||||
#include <NewPing.h>
|
||||
|
||||
#define LED_PIN 13 // Pin with LED attached.
|
||||
|
||||
void setup() {
|
||||
pinMode(LED_PIN, OUTPUT);
|
||||
NewPing::timer_ms(500, toggleLED); // Create a Timer2 interrupt that calls toggleLED in your sketch once every 500 milliseconds.
|
||||
}
|
||||
|
||||
void loop() {
|
||||
// Do anything here, the Timer2 interrupt will take care of the flashing LED without your intervention.
|
||||
}
|
||||
|
||||
void toggleLED() {
|
||||
digitalWrite(LED_PIN, !digitalRead(LED_PIN)); // Toggle the LED.
|
||||
}
|
||||
Executable
+29
@@ -0,0 +1,29 @@
|
||||
###################################
|
||||
# Syntax Coloring Map For NewPing
|
||||
###################################
|
||||
|
||||
###################################
|
||||
# Datatypes (KEYWORD1)
|
||||
###################################
|
||||
|
||||
NewPing KEYWORD1
|
||||
|
||||
###################################
|
||||
# Methods and Functions (KEYWORD2)
|
||||
###################################
|
||||
|
||||
ping KEYWORD2
|
||||
ping_in KEYWORD2
|
||||
ping_cm KEYWORD2
|
||||
ping_median KEYWORD2
|
||||
ping_timer KEYWORD2
|
||||
check_timer KEYWORD2
|
||||
timer_us KEYWORD2
|
||||
timer_ms KEYWORD2
|
||||
timer_stop KEYWORD2
|
||||
convert_in KEYWORD2
|
||||
convert_cm KEYWORD2
|
||||
|
||||
###################################
|
||||
# Constants (LITERAL1)
|
||||
###################################
|
||||
@@ -26,7 +26,7 @@
|
||||
#include <SensorSerial.h>
|
||||
|
||||
|
||||
SensorSerial::SensorSerial(int receivePin, int transmitPin, bool inverse_logic, unsigned int buffSize) : SoftwareSerial(receivePin, transmitPin, inverse_logic, buffSize)
|
||||
SensorSerial::SensorSerial(int receivePin, int transmitPin, bool inverse_logic, unsigned int buffSize) : ESPeasySoftwareSerial(receivePin, transmitPin, inverse_logic, buffSize)
|
||||
{
|
||||
//boolean sws = isValidGPIOpin(receivePin);
|
||||
_hw = receivePin < 0;
|
||||
@@ -37,7 +37,7 @@ void SensorSerial::begin(long speed)
|
||||
if (_hw)
|
||||
Serial.begin(speed);
|
||||
else
|
||||
SoftwareSerial::begin(speed);
|
||||
ESPeasySoftwareSerial::begin(speed);
|
||||
}
|
||||
|
||||
int SensorSerial::peek()
|
||||
@@ -45,7 +45,7 @@ int SensorSerial::peek()
|
||||
if (_hw)
|
||||
return Serial.peek();
|
||||
else
|
||||
return SoftwareSerial::peek();
|
||||
return ESPeasySoftwareSerial::peek();
|
||||
}
|
||||
|
||||
size_t SensorSerial::write(uint8_t byte)
|
||||
@@ -53,7 +53,7 @@ size_t SensorSerial::write(uint8_t byte)
|
||||
if (_hw)
|
||||
return Serial.write(byte);
|
||||
else
|
||||
return SoftwareSerial::write(byte);
|
||||
return ESPeasySoftwareSerial::write(byte);
|
||||
}
|
||||
|
||||
int SensorSerial::read()
|
||||
@@ -61,7 +61,7 @@ int SensorSerial::read()
|
||||
if (_hw)
|
||||
return Serial.read();
|
||||
else
|
||||
return SoftwareSerial::read();
|
||||
return ESPeasySoftwareSerial::read();
|
||||
}
|
||||
|
||||
int SensorSerial::available()
|
||||
@@ -69,7 +69,7 @@ int SensorSerial::available()
|
||||
if (_hw)
|
||||
return Serial.available();
|
||||
else
|
||||
return SoftwareSerial::available();
|
||||
return ESPeasySoftwareSerial::available();
|
||||
}
|
||||
|
||||
void SensorSerial::flush()
|
||||
@@ -77,5 +77,5 @@ void SensorSerial::flush()
|
||||
if (_hw)
|
||||
Serial.flush();
|
||||
else
|
||||
SoftwareSerial::flush();
|
||||
ESPeasySoftwareSerial::flush();
|
||||
}
|
||||
|
||||
@@ -27,9 +27,9 @@
|
||||
#define _SENSORSERIAL_H_
|
||||
|
||||
#include "Arduino.h"
|
||||
#include <SoftwareSerial.h>
|
||||
#include <ESPeasySoftwareSerial.h>
|
||||
|
||||
class SensorSerial : public SoftwareSerial
|
||||
class SensorSerial : public ESPeasySoftwareSerial
|
||||
{
|
||||
public:
|
||||
SensorSerial(int receivePin, int transmitPin = -1, bool inverse_logic = false, unsigned int buffSize = 64);
|
||||
|
||||
+116
-29
@@ -25,7 +25,7 @@
|
||||
|
||||
#include "jkSDS011.h"
|
||||
|
||||
CjkSDS011::CjkSDS011(int16_t pinRX, int16_t pinTX) : _serial(pinRX, pinTX)
|
||||
CjkSDS011::CjkSDS011(int16_t pinRX, int16_t pinTX)
|
||||
{
|
||||
_sws = ! ( pinRX < 0 || pinRX == 3 );
|
||||
_pm2_5 = NAN;
|
||||
@@ -35,43 +35,131 @@ CjkSDS011::CjkSDS011(int16_t pinRX, int16_t pinTX) : _serial(pinRX, pinTX)
|
||||
_pm10_avr = 0;
|
||||
_avr = 0;
|
||||
_data.SetPacketLength(10);
|
||||
_command.SetPacketLength(19);
|
||||
_working_period = -1;
|
||||
_sleepmode_active = false;
|
||||
_serial = new ESPeasySoftwareSerial(pinRX, pinTX);
|
||||
_serial->begin(9600);
|
||||
}
|
||||
|
||||
_serial.begin(9600);
|
||||
CjkSDS011::~CjkSDS011() {
|
||||
delete _serial;
|
||||
}
|
||||
|
||||
void CjkSDS011::SendCommand(byte byte1, byte byte2, byte byte3) {
|
||||
_command[0] = 0xAA; // Head
|
||||
_command[1] = 0xB4; // Command ID
|
||||
_command[2] = byte1; // Data Byte 1
|
||||
_command[3] = byte2; // Data Byte 2
|
||||
_command[4] = byte3; // Data Byte 3
|
||||
_command[5] = 0; // Data Byte 4
|
||||
_command[6] = 0; // Data Byte 5
|
||||
_command[7] = 0; // Data Byte 6
|
||||
_command[8] = 0; // Data Byte 7
|
||||
_command[9] = 0; // Data Byte 8
|
||||
_command[10] = 0; // Data Byte 9
|
||||
_command[11] = 0; // Data Byte 10
|
||||
_command[12] = 0; // Data Byte 11
|
||||
_command[13] = 0; // Data Byte 12
|
||||
_command[14] = 0; // Data Byte 13
|
||||
_command[15] = 0xFF; // Device ID byte 1, FF: All sensor response
|
||||
_command[16] = 0xFF; // Device ID byte 2, FF: All sensor response
|
||||
|
||||
byte checksum = 0;
|
||||
for (byte i=2; i< 17; ++i) {
|
||||
checksum += _command[i];
|
||||
}
|
||||
_command[17] = checksum; // Checksum
|
||||
_command[18] = 0xAB; // Tail
|
||||
|
||||
for (int i = 0; i < 19; ++i) {
|
||||
_serial->write(_command[i]);
|
||||
}
|
||||
}
|
||||
|
||||
void CjkSDS011::SetSleepMode(bool enabled) {
|
||||
byte databyte3 = enabled ? 0 : 1;
|
||||
SendCommand(6, 1, databyte3);
|
||||
}
|
||||
|
||||
void CjkSDS011::SetWorkingPeriod(int minutes) {
|
||||
// Data byte 1: 8
|
||||
// Data byte 2: 0: query the current mode
|
||||
// 1: set mode
|
||||
// Data byte 3: 0:continuous(default)
|
||||
// 1-30minute:work 30 seconds and sleep n*60-30 seconds
|
||||
if (minutes < 0 || minutes > 30) return;
|
||||
// Working period is stored in the flash of the sensor. Only write to change.
|
||||
const int currentWorkingPeriod = GetWorkingPeriod();
|
||||
if (minutes != currentWorkingPeriod)
|
||||
SendCommand(8, 1, minutes);
|
||||
}
|
||||
|
||||
int CjkSDS011::GetWorkingPeriod() {
|
||||
// Data byte 1: 8
|
||||
// Data byte 2: 0: query the current mode
|
||||
// 1: set mode
|
||||
// Data byte 3: 0:continuous(default)
|
||||
// 1-30minute:work 30 seconds and sleep n*60-30 seconds
|
||||
SendCommand(8, 0, 0);
|
||||
Process();
|
||||
return _working_period;
|
||||
}
|
||||
|
||||
void CjkSDS011::ParseCommandReply() {
|
||||
switch(_data[2]) {
|
||||
case 6: // Enable/Disable sleep mode.
|
||||
if (_data[3] == 0)
|
||||
_sleepmode_active = _data[4];
|
||||
break;
|
||||
case 8: // Set/Get working period
|
||||
if (_data[3] == 0)
|
||||
_working_period = _data[4];
|
||||
break;
|
||||
default:
|
||||
// Not implemented.
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
void CjkSDS011::Process()
|
||||
{
|
||||
while (_serial.available())
|
||||
while (_serial->available())
|
||||
{
|
||||
_data.AddData(_serial.read());
|
||||
_data.AddData(_serial->read());
|
||||
|
||||
if (_data[0] == 0xAA && _data[9] == 0xAB && (_data[1] == 0xC0 || _data[1] == 0xCF)) // correct packet frame?
|
||||
if (_data[0] == 0xAA && _data[9] == 0xAB) // correct packet frame?
|
||||
{
|
||||
byte checksum = 0;
|
||||
for (byte i=2; i<= 7; i++)
|
||||
checksum += _data[i];
|
||||
checksum += _data[i];
|
||||
if (checksum != _data[8])
|
||||
continue;
|
||||
|
||||
if (_data[1] == 0xC0) // SDS011 or SDS018?
|
||||
{
|
||||
_pm2_5 = (float)((_data[3] << 8) | _data[2]) * 0.1;
|
||||
_pm10_ = (float)((_data[5] << 8) | _data[4]) * 0.1;
|
||||
_available = true;
|
||||
switch(_data[1]) {
|
||||
case 0xC0: // SDS011 or SDS018?
|
||||
_pm2_5 = (float)((_data[3] << 8) | _data[2]) * 0.1;
|
||||
_pm10_ = (float)((_data[5] << 8) | _data[4]) * 0.1;
|
||||
_available = true;
|
||||
break;
|
||||
case 0xCF: // SDS198?
|
||||
_pm2_5 = (float)((_data[5] << 8) | _data[4]);
|
||||
_pm10_ = (float)((_data[3] << 8) | _data[2]);
|
||||
_available = true;
|
||||
break;
|
||||
case 0xC5: // Reply on command ID 0xB4
|
||||
ParseCommandReply();
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
else if (_data[1] == 0xCF) // SDS198?
|
||||
{
|
||||
_pm2_5 = (float)((_data[5] << 8) | _data[4]);
|
||||
_pm10_ = (float)((_data[3] << 8) | _data[2]);
|
||||
_available = true;
|
||||
if (_available) {
|
||||
_pm2_5avr += _pm2_5;
|
||||
_pm10_avr += _pm10_;
|
||||
_avr++;
|
||||
_data.Clear();
|
||||
return;
|
||||
}
|
||||
else
|
||||
continue;
|
||||
|
||||
_pm2_5avr += _pm2_5;
|
||||
_pm10_avr += _pm10_;
|
||||
_avr++;
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -83,7 +171,7 @@ boolean CjkSDS011::available()
|
||||
return ret;
|
||||
}
|
||||
|
||||
void CjkSDS011::ReadAverage(float &pm25, float &pm10)
|
||||
boolean CjkSDS011::ReadAverage(float &pm25, float &pm10)
|
||||
{
|
||||
if (_avr)
|
||||
{
|
||||
@@ -92,10 +180,9 @@ void CjkSDS011::ReadAverage(float &pm25, float &pm10)
|
||||
_pm2_5avr = 0;
|
||||
_pm10_avr = 0;
|
||||
_avr = 0;
|
||||
return true;
|
||||
}
|
||||
else
|
||||
{
|
||||
pm25 = NAN;
|
||||
pm10 = NAN;
|
||||
}
|
||||
pm25 = NAN;
|
||||
pm10 = NAN;
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -27,13 +27,16 @@
|
||||
#define _jkSDS011_H_
|
||||
|
||||
#include "Arduino.h"
|
||||
#include "SensorSerial.h"
|
||||
//#include "SensorSerial.h"
|
||||
#include "SensorSerialBuffer.h"
|
||||
#include "ESPeasySoftwareSerial.h"
|
||||
|
||||
|
||||
class CjkSDS011
|
||||
{
|
||||
public:
|
||||
CjkSDS011(int16_t pinRX, int16_t pinTX);
|
||||
virtual ~CjkSDS011();
|
||||
|
||||
void Process();
|
||||
|
||||
@@ -42,11 +45,28 @@ public:
|
||||
float GetPM2_5() { return _pm2_5; };
|
||||
float GetPM10_() { return _pm10_; };
|
||||
|
||||
void ReadAverage(float &pm25, float &pm10);
|
||||
// Return true when there are valid samples.
|
||||
boolean ReadAverage(float &pm25, float &pm10);
|
||||
|
||||
void SetSleepMode(bool enabled);
|
||||
|
||||
// Set interval to get new data, 0 .. 30 minutes.
|
||||
// Minutes = 0 => continous mode.
|
||||
// The setting is still effective after power off(factory default is continuous measurement)
|
||||
void SetWorkingPeriod(int minutes);
|
||||
|
||||
// Get the working period in minutes (0 = continuous reading)
|
||||
// Negative return value indicates error during communication.
|
||||
int GetWorkingPeriod();
|
||||
|
||||
private:
|
||||
SensorSerial _serial;
|
||||
void SendCommand(byte byte1, byte byte2, byte byte3);
|
||||
void ParseCommandReply();
|
||||
|
||||
// SensorSerial _serial;
|
||||
ESPeasySoftwareSerial *_serial;
|
||||
CSensorSerialBuffer _data;
|
||||
CSensorSerialBuffer _command;
|
||||
float _pm2_5;
|
||||
float _pm10_;
|
||||
float _pm2_5avr;
|
||||
@@ -54,6 +74,8 @@ private:
|
||||
uint16_t _avr;
|
||||
boolean _available;
|
||||
boolean _sws;
|
||||
int _working_period;
|
||||
boolean _sleepmode_active;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
@@ -0,0 +1,490 @@
|
||||
/**The MIT License (MIT)
|
||||
|
||||
Copyright (c) 2015 by Daniel Eichhorn
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
||||
|
||||
See more at http://blog.squix.ch
|
||||
*/
|
||||
|
||||
#ifndef DIALOG_PLAIN_FONT_H
|
||||
#define DIALOG_PLAIN_FONT_H
|
||||
|
||||
// OLED library version >= 3.0.0
|
||||
// Created by http://oleddisplay.squix.ch/ Consider a donation
|
||||
// In case of problems make sure that you are using the font file with the correct version!
|
||||
const char Dialog_plain_12[] PROGMEM = {
|
||||
0x0D, // Width: 13
|
||||
0x0F, // Height: 15
|
||||
0x20, // First Char: 32
|
||||
0xE0, // Numbers of Chars: 224
|
||||
|
||||
// Jump Table:
|
||||
0xFF, 0xFF, 0x00, 0x04, // 32:65535
|
||||
0x00, 0x00, 0x06, 0x05, // 33:0
|
||||
0x00, 0x06, 0x07, 0x05, // 34:6
|
||||
0x00, 0x0D, 0x11, 0x0A, // 35:13
|
||||
0x00, 0x1E, 0x0E, 0x08, // 36:30
|
||||
0x00, 0x2C, 0x16, 0x0C, // 37:44
|
||||
0x00, 0x42, 0x12, 0x09, // 38:66
|
||||
0x00, 0x54, 0x03, 0x03, // 39:84
|
||||
0x00, 0x57, 0x06, 0x05, // 40:87
|
||||
0x00, 0x5D, 0x08, 0x05, // 41:93
|
||||
0x00, 0x65, 0x0B, 0x07, // 42:101
|
||||
0x00, 0x70, 0x12, 0x0A, // 43:112
|
||||
0x00, 0x82, 0x04, 0x03, // 44:130
|
||||
0x00, 0x86, 0x08, 0x05, // 45:134
|
||||
0x00, 0x8E, 0x04, 0x03, // 46:142
|
||||
0x00, 0x92, 0x07, 0x04, // 47:146
|
||||
0x00, 0x99, 0x0E, 0x08, // 48:153
|
||||
0x00, 0xA7, 0x0C, 0x07, // 49:167
|
||||
0x00, 0xB3, 0x0C, 0x07, // 50:179
|
||||
0x00, 0xBF, 0x0C, 0x07, // 51:191
|
||||
0x00, 0xCB, 0x0E, 0x08, // 52:203
|
||||
0x00, 0xD9, 0x0C, 0x07, // 53:217
|
||||
0x00, 0xE5, 0x0E, 0x08, // 54:229
|
||||
0x00, 0xF3, 0x0D, 0x08, // 55:243
|
||||
0x01, 0x00, 0x0E, 0x08, // 56:256
|
||||
0x01, 0x0E, 0x0E, 0x08, // 57:270
|
||||
0x01, 0x1C, 0x04, 0x03, // 58:284
|
||||
0x01, 0x20, 0x04, 0x03, // 59:288
|
||||
0x01, 0x24, 0x12, 0x0A, // 60:292
|
||||
0x01, 0x36, 0x12, 0x0A, // 61:310
|
||||
0x01, 0x48, 0x12, 0x0A, // 62:328
|
||||
0x01, 0x5A, 0x09, 0x06, // 63:346
|
||||
0x01, 0x63, 0x16, 0x0C, // 64:355
|
||||
0x01, 0x79, 0x10, 0x08, // 65:377
|
||||
0x01, 0x89, 0x0E, 0x08, // 66:393
|
||||
0x01, 0x97, 0x10, 0x09, // 67:407
|
||||
0x01, 0xA7, 0x10, 0x09, // 68:423
|
||||
0x01, 0xB7, 0x0C, 0x07, // 69:439
|
||||
0x01, 0xC3, 0x0B, 0x07, // 70:451
|
||||
0x01, 0xCE, 0x12, 0x0A, // 71:462
|
||||
0x01, 0xE0, 0x10, 0x09, // 72:480
|
||||
0x01, 0xF0, 0x04, 0x03, // 73:496
|
||||
0x01, 0xF4, 0x04, 0x03, // 74:500
|
||||
0x01, 0xF8, 0x0E, 0x08, // 75:504
|
||||
0x02, 0x06, 0x0C, 0x06, // 76:518
|
||||
0x02, 0x12, 0x12, 0x0A, // 77:530
|
||||
0x02, 0x24, 0x10, 0x09, // 78:548
|
||||
0x02, 0x34, 0x12, 0x0A, // 79:564
|
||||
0x02, 0x46, 0x0D, 0x08, // 80:582
|
||||
0x02, 0x53, 0x12, 0x0A, // 81:595
|
||||
0x02, 0x65, 0x10, 0x09, // 82:613
|
||||
0x02, 0x75, 0x0E, 0x08, // 83:629
|
||||
0x02, 0x83, 0x0D, 0x07, // 84:643
|
||||
0x02, 0x90, 0x10, 0x09, // 85:656
|
||||
0x02, 0xA0, 0x0F, 0x08, // 86:672
|
||||
0x02, 0xAF, 0x15, 0x0C, // 87:687
|
||||
0x02, 0xC4, 0x10, 0x08, // 88:708
|
||||
0x02, 0xD4, 0x0D, 0x07, // 89:724
|
||||
0x02, 0xE1, 0x10, 0x09, // 90:737
|
||||
0x02, 0xF1, 0x06, 0x05, // 91:753
|
||||
0x02, 0xF7, 0x08, 0x04, // 92:759
|
||||
0x02, 0xFF, 0x08, 0x05, // 93:767
|
||||
0x03, 0x07, 0x11, 0x0A, // 94:775
|
||||
0x03, 0x18, 0x0C, 0x06, // 95:792
|
||||
0x03, 0x24, 0x05, 0x06, // 96:804
|
||||
0x03, 0x29, 0x0E, 0x08, // 97:809
|
||||
0x03, 0x37, 0x0E, 0x08, // 98:823
|
||||
0x03, 0x45, 0x0C, 0x07, // 99:837
|
||||
0x03, 0x51, 0x0E, 0x08, // 100:849
|
||||
0x03, 0x5F, 0x0E, 0x08, // 101:863
|
||||
0x03, 0x6D, 0x07, 0x04, // 102:877
|
||||
0x03, 0x74, 0x0E, 0x08, // 103:884
|
||||
0x03, 0x82, 0x0C, 0x07, // 104:898
|
||||
0x03, 0x8E, 0x04, 0x03, // 105:910
|
||||
0x03, 0x92, 0x04, 0x03, // 106:914
|
||||
0x03, 0x96, 0x0C, 0x07, // 107:918
|
||||
0x03, 0xA2, 0x04, 0x03, // 108:930
|
||||
0x03, 0xA6, 0x14, 0x0B, // 109:934
|
||||
0x03, 0xBA, 0x0C, 0x07, // 110:954
|
||||
0x03, 0xC6, 0x0E, 0x08, // 111:966
|
||||
0x03, 0xD4, 0x0E, 0x08, // 112:980
|
||||
0x03, 0xE2, 0x0E, 0x08, // 113:994
|
||||
0x03, 0xF0, 0x09, 0x05, // 114:1008
|
||||
0x03, 0xF9, 0x0C, 0x07, // 115:1017
|
||||
0x04, 0x05, 0x08, 0x05, // 116:1029
|
||||
0x04, 0x0D, 0x0C, 0x07, // 117:1037
|
||||
0x04, 0x19, 0x0D, 0x07, // 118:1049
|
||||
0x04, 0x26, 0x11, 0x0A, // 119:1062
|
||||
0x04, 0x37, 0x0C, 0x07, // 120:1079
|
||||
0x04, 0x43, 0x0D, 0x07, // 121:1091
|
||||
0x04, 0x50, 0x0E, 0x07, // 122:1104
|
||||
0x04, 0x5E, 0x0C, 0x07, // 123:1118
|
||||
0x04, 0x6A, 0x06, 0x05, // 124:1130
|
||||
0x04, 0x70, 0x0B, 0x07, // 125:1136
|
||||
0x04, 0x7B, 0x11, 0x0A, // 126:1147
|
||||
0x04, 0x8C, 0x0C, 0x07, // 127:1164
|
||||
0x04, 0x98, 0x0C, 0x07, // 128:1176
|
||||
0x04, 0xA4, 0x0C, 0x07, // 129:1188
|
||||
0x04, 0xB0, 0x0C, 0x07, // 130:1200
|
||||
0x04, 0xBC, 0x0C, 0x07, // 131:1212
|
||||
0x04, 0xC8, 0x0C, 0x07, // 132:1224
|
||||
0x04, 0xD4, 0x0C, 0x07, // 133:1236
|
||||
0x04, 0xE0, 0x0C, 0x07, // 134:1248
|
||||
0x04, 0xEC, 0x0C, 0x07, // 135:1260
|
||||
0x04, 0xF8, 0x0C, 0x07, // 136:1272
|
||||
0x05, 0x04, 0x0C, 0x07, // 137:1284
|
||||
0x05, 0x10, 0x0C, 0x07, // 138:1296
|
||||
0x05, 0x1C, 0x0C, 0x07, // 139:1308
|
||||
0x05, 0x28, 0x0C, 0x07, // 140:1320
|
||||
0x05, 0x34, 0x0C, 0x07, // 141:1332
|
||||
0x05, 0x40, 0x0C, 0x07, // 142:1344
|
||||
0x05, 0x4C, 0x0C, 0x07, // 143:1356
|
||||
0x05, 0x58, 0x0C, 0x07, // 144:1368
|
||||
0x05, 0x64, 0x0C, 0x07, // 145:1380
|
||||
0x05, 0x70, 0x0C, 0x07, // 146:1392
|
||||
0x05, 0x7C, 0x0C, 0x07, // 147:1404
|
||||
0x05, 0x88, 0x0C, 0x07, // 148:1416
|
||||
0x05, 0x94, 0x0C, 0x07, // 149:1428
|
||||
0x05, 0xA0, 0x0C, 0x07, // 150:1440
|
||||
0x05, 0xAC, 0x0C, 0x07, // 151:1452
|
||||
0x05, 0xB8, 0x0C, 0x07, // 152:1464
|
||||
0x05, 0xC4, 0x0C, 0x07, // 153:1476
|
||||
0x05, 0xD0, 0x0C, 0x07, // 154:1488
|
||||
0x05, 0xDC, 0x0C, 0x07, // 155:1500
|
||||
0x05, 0xE8, 0x0C, 0x07, // 156:1512
|
||||
0x05, 0xF4, 0x0C, 0x07, // 157:1524
|
||||
0x06, 0x00, 0x0C, 0x07, // 158:1536
|
||||
0x06, 0x0C, 0x0C, 0x07, // 159:1548
|
||||
0xFF, 0xFF, 0x00, 0x04, // 160:65535
|
||||
0x06, 0x18, 0x06, 0x05, // 161:1560
|
||||
0x06, 0x1E, 0x0E, 0x08, // 162:1566
|
||||
0x06, 0x2C, 0x0E, 0x08, // 163:1580
|
||||
0x06, 0x3A, 0x0C, 0x07, // 164:1594
|
||||
0x06, 0x46, 0x0C, 0x07, // 165:1606
|
||||
0x06, 0x52, 0x06, 0x05, // 166:1618
|
||||
0x06, 0x58, 0x0C, 0x07, // 167:1624
|
||||
0x06, 0x64, 0x07, 0x05, // 168:1636
|
||||
0x06, 0x6B, 0x16, 0x0D, // 169:1643
|
||||
0x06, 0x81, 0x0A, 0x06, // 170:1665
|
||||
0x06, 0x8B, 0x0E, 0x08, // 171:1675
|
||||
0x06, 0x99, 0x12, 0x0A, // 172:1689
|
||||
0x06, 0xAB, 0x08, 0x05, // 173:1707
|
||||
0x06, 0xB3, 0x16, 0x0D, // 174:1715
|
||||
0x06, 0xC9, 0x09, 0x06, // 175:1737
|
||||
0x06, 0xD2, 0x09, 0x06, // 176:1746
|
||||
0x06, 0xDB, 0x12, 0x0A, // 177:1755
|
||||
0x06, 0xED, 0x08, 0x05, // 178:1773
|
||||
0x06, 0xF5, 0x07, 0x05, // 179:1781
|
||||
0x06, 0xFC, 0x09, 0x06, // 180:1788
|
||||
0x07, 0x05, 0x0E, 0x07, // 181:1797
|
||||
0x07, 0x13, 0x0C, 0x07, // 182:1811
|
||||
0x07, 0x1F, 0x03, 0x03, // 183:1823
|
||||
0x07, 0x22, 0x08, 0x06, // 184:1826
|
||||
0x07, 0x2A, 0x07, 0x05, // 185:1834
|
||||
0x07, 0x31, 0x0C, 0x07, // 186:1841
|
||||
0x07, 0x3D, 0x0E, 0x07, // 187:1853
|
||||
0x07, 0x4B, 0x16, 0x0B, // 188:1867
|
||||
0x07, 0x61, 0x16, 0x0C, // 189:1889
|
||||
0x07, 0x77, 0x16, 0x0B, // 190:1911
|
||||
0x07, 0x8D, 0x0A, 0x06, // 191:1933
|
||||
0x07, 0x97, 0x10, 0x08, // 192:1943
|
||||
0x07, 0xA7, 0x10, 0x08, // 193:1959
|
||||
0x07, 0xB7, 0x10, 0x08, // 194:1975
|
||||
0x07, 0xC7, 0x10, 0x08, // 195:1991
|
||||
0x07, 0xD7, 0x0E, 0x07, // 196:2007
|
||||
0x07, 0xE5, 0x0E, 0x07, // 197:2021
|
||||
0x07, 0xF3, 0x14, 0x0B, // 198:2035
|
||||
0x08, 0x07, 0x10, 0x09, // 199:2055
|
||||
0x08, 0x17, 0x0C, 0x07, // 200:2071
|
||||
0x08, 0x23, 0x0C, 0x07, // 201:2083
|
||||
0x08, 0x2F, 0x0C, 0x07, // 202:2095
|
||||
0x08, 0x3B, 0x0C, 0x07, // 203:2107
|
||||
0x08, 0x47, 0x04, 0x03, // 204:2119
|
||||
0x08, 0x4B, 0x05, 0x03, // 205:2123
|
||||
0x08, 0x50, 0x05, 0x03, // 206:2128
|
||||
0x08, 0x55, 0x07, 0x05, // 207:2133
|
||||
0x08, 0x5C, 0x10, 0x09, // 208:2140
|
||||
0x08, 0x6C, 0x10, 0x09, // 209:2156
|
||||
0x08, 0x7C, 0x12, 0x0A, // 210:2172
|
||||
0x08, 0x8E, 0x12, 0x0A, // 211:2190
|
||||
0x08, 0xA0, 0x12, 0x0A, // 212:2208
|
||||
0x08, 0xB2, 0x12, 0x0A, // 213:2226
|
||||
0x08, 0xC4, 0x12, 0x0A, // 214:2244
|
||||
0x08, 0xD6, 0x10, 0x0A, // 215:2262
|
||||
0x08, 0xE6, 0x12, 0x0A, // 216:2278
|
||||
0x08, 0xF8, 0x10, 0x09, // 217:2296
|
||||
0x09, 0x08, 0x10, 0x09, // 218:2312
|
||||
0x09, 0x18, 0x10, 0x09, // 219:2328
|
||||
0x09, 0x28, 0x10, 0x09, // 220:2344
|
||||
0x09, 0x38, 0x0D, 0x07, // 221:2360
|
||||
0x09, 0x45, 0x0E, 0x08, // 222:2373
|
||||
0x09, 0x53, 0x0E, 0x08, // 223:2387
|
||||
0x09, 0x61, 0x0E, 0x08, // 224:2401
|
||||
0x09, 0x6F, 0x0E, 0x08, // 225:2415
|
||||
0x09, 0x7D, 0x0E, 0x08, // 226:2429
|
||||
0x09, 0x8B, 0x0E, 0x08, // 227:2443
|
||||
0x09, 0x99, 0x0E, 0x08, // 228:2457
|
||||
0x09, 0xA7, 0x0E, 0x08, // 229:2471
|
||||
0x09, 0xB5, 0x16, 0x0C, // 230:2485
|
||||
0x09, 0xCB, 0x0C, 0x07, // 231:2507
|
||||
0x09, 0xD7, 0x0E, 0x08, // 232:2519
|
||||
0x09, 0xE5, 0x0E, 0x08, // 233:2533
|
||||
0x09, 0xF3, 0x0E, 0x08, // 234:2547
|
||||
0x0A, 0x01, 0x0E, 0x08, // 235:2561
|
||||
0x0A, 0x0F, 0x04, 0x03, // 236:2575
|
||||
0x0A, 0x13, 0x05, 0x03, // 237:2579
|
||||
0x0A, 0x18, 0x05, 0x03, // 238:2584
|
||||
0x0A, 0x1D, 0x05, 0x03, // 239:2589
|
||||
0x0A, 0x22, 0x0E, 0x08, // 240:2594
|
||||
0x0A, 0x30, 0x0C, 0x07, // 241:2608
|
||||
0x0A, 0x3C, 0x0E, 0x08, // 242:2620
|
||||
0x0A, 0x4A, 0x0E, 0x08, // 243:2634
|
||||
0x0A, 0x58, 0x0E, 0x08, // 244:2648
|
||||
0x0A, 0x66, 0x0E, 0x08, // 245:2662
|
||||
0x0A, 0x74, 0x0E, 0x08, // 246:2676
|
||||
0x0A, 0x82, 0x11, 0x0A, // 247:2690
|
||||
0x0A, 0x93, 0x0E, 0x08, // 248:2707
|
||||
0x0A, 0xA1, 0x0C, 0x07, // 249:2721
|
||||
0x0A, 0xAD, 0x0C, 0x07, // 250:2733
|
||||
0x0A, 0xB9, 0x0C, 0x07, // 251:2745
|
||||
0x0A, 0xC5, 0x0C, 0x07, // 252:2757
|
||||
0x0A, 0xD1, 0x0D, 0x07, // 253:2769
|
||||
0x0A, 0xDE, 0x0E, 0x08, // 254:2782
|
||||
0x0A, 0xEC, 0x0B, 0x07, // 255:2796
|
||||
|
||||
// Font Data:
|
||||
0x00,0x00,0x00,0x00,0xF8,0x09, // 33
|
||||
0x00,0x00,0x38,0x00,0x00,0x00,0x38, // 34
|
||||
0x00,0x00,0x00,0x01,0x40,0x0D,0xC0,0x03,0x78,0x01,0x40,0x0F,0xE0,0x01,0x58,0x01,0x40, // 35
|
||||
0x00,0x00,0x70,0x08,0xC8,0x08,0xFC,0x1F,0x88,0x08,0x88,0x0D,0x18,0x07, // 36
|
||||
0x00,0x00,0x70,0x00,0x88,0x00,0x88,0x08,0x70,0x06,0x80,0x01,0x40,0x00,0x30,0x07,0x88,0x08,0x80,0x08,0x00,0x07, // 37
|
||||
0x00,0x00,0x80,0x07,0xF0,0x0C,0x48,0x08,0x88,0x09,0x08,0x0B,0x00,0x06,0x80,0x0F,0x80,0x08, // 38
|
||||
0x00,0x00,0x38, // 39
|
||||
0x00,0x00,0xF0,0x07,0x0C,0x18, // 40
|
||||
0x00,0x00,0x00,0x00,0x1C,0x18,0xE0,0x07, // 41
|
||||
0x00,0x00,0x50,0x00,0x60,0x00,0xF8,0x00,0x60,0x00,0x50, // 42
|
||||
0x00,0x00,0x00,0x01,0x00,0x01,0x00,0x01,0xF0,0x0F,0x00,0x01,0x00,0x01,0x00,0x01,0x00,0x01, // 43
|
||||
0x00,0x10,0x00,0x0C, // 44
|
||||
0x00,0x00,0x00,0x01,0x00,0x01,0x00,0x01, // 45
|
||||
0x00,0x00,0x00,0x08, // 46
|
||||
0x00,0x30,0x00,0x0F,0xE0,0x00,0x18, // 47
|
||||
0x00,0x00,0xE0,0x03,0x18,0x0C,0x08,0x08,0x08,0x08,0x18,0x0C,0xE0,0x03, // 48
|
||||
0x00,0x00,0x08,0x08,0x08,0x08,0xF8,0x0F,0x00,0x08,0x00,0x08, // 49
|
||||
0x00,0x00,0x18,0x0C,0x08,0x0E,0x08,0x0B,0x88,0x08,0x70,0x08, // 50
|
||||
0x00,0x0C,0x08,0x08,0x48,0x08,0x48,0x08,0xC8,0x0C,0xB0,0x07, // 51
|
||||
0x00,0x00,0x00,0x03,0xC0,0x02,0x60,0x02,0x18,0x02,0xF8,0x0F,0x00,0x02, // 52
|
||||
0x00,0x0C,0x78,0x08,0x48,0x08,0x48,0x08,0xC8,0x0C,0x80,0x07, // 53
|
||||
0x00,0x00,0xE0,0x03,0x90,0x0C,0x48,0x08,0x48,0x08,0xC8,0x0C,0x88,0x07, // 54
|
||||
0x00,0x00,0x08,0x00,0x08,0x08,0x08,0x0E,0xC8,0x03,0x78,0x00,0x18, // 55
|
||||
0x00,0x00,0x70,0x07,0x88,0x09,0x88,0x08,0x88,0x08,0x88,0x09,0x70,0x07, // 56
|
||||
0x00,0x00,0xF0,0x08,0x98,0x09,0x08,0x09,0x08,0x09,0x98,0x04,0xE0,0x03, // 57
|
||||
0x00,0x00,0x40,0x08, // 58
|
||||
0x00,0x10,0x20,0x0C, // 59
|
||||
0x00,0x00,0x80,0x01,0x80,0x01,0x80,0x03,0x40,0x02,0x40,0x02,0x60,0x04,0x20,0x04,0x20,0x04, // 60
|
||||
0x00,0x00,0x40,0x02,0x40,0x02,0x40,0x02,0x40,0x02,0x40,0x02,0x40,0x02,0x40,0x02,0x40,0x02, // 61
|
||||
0x00,0x00,0x20,0x04,0x20,0x04,0x40,0x02,0x40,0x02,0xC0,0x02,0x80,0x01,0x80,0x01,0x00,0x01, // 62
|
||||
0x00,0x00,0x08,0x00,0x88,0x0B,0xC8,0x00,0x70, // 63
|
||||
0x00,0x00,0xC0,0x07,0x20,0x08,0x10,0x10,0x88,0x23,0x48,0x24,0x48,0x24,0x48,0x24,0xD0,0x17,0x30,0x04,0xC0,0x03, // 64
|
||||
0x00,0x08,0x00,0x0F,0xE0,0x03,0x38,0x02,0x18,0x02,0xE0,0x02,0x00,0x07,0x00,0x0C, // 65
|
||||
0x00,0x00,0xF8,0x0F,0x88,0x08,0x88,0x08,0x88,0x08,0x88,0x08,0x70,0x07, // 66
|
||||
0x00,0x00,0xE0,0x03,0x10,0x04,0x08,0x08,0x08,0x08,0x08,0x08,0x08,0x08,0x10,0x04, // 67
|
||||
0x00,0x00,0xF8,0x0F,0x08,0x08,0x08,0x08,0x08,0x08,0x08,0x08,0x10,0x04,0xE0,0x03, // 68
|
||||
0x00,0x00,0xF8,0x0F,0x88,0x08,0x88,0x08,0x88,0x08,0x88,0x08, // 69
|
||||
0x00,0x00,0xF8,0x0F,0x88,0x00,0x88,0x00,0x88,0x00,0x08, // 70
|
||||
0x00,0x00,0xE0,0x03,0x10,0x04,0x08,0x08,0x08,0x08,0x08,0x08,0x88,0x08,0x88,0x08,0x90,0x07, // 71
|
||||
0x00,0x00,0xF8,0x0F,0x80,0x00,0x80,0x00,0x80,0x00,0x80,0x00,0x80,0x00,0xF8,0x0F, // 72
|
||||
0x00,0x00,0xF8,0x0F, // 73
|
||||
0x00,0x40,0xF8,0x3F, // 74
|
||||
0x00,0x00,0xF8,0x0F,0xC0,0x00,0x60,0x01,0x30,0x02,0x18,0x04,0x08,0x08, // 75
|
||||
0x00,0x00,0xF8,0x0F,0x00,0x08,0x00,0x08,0x00,0x08,0x00,0x08, // 76
|
||||
0x00,0x00,0xF8,0x0F,0x18,0x00,0xE0,0x00,0x00,0x03,0x00,0x03,0xE0,0x00,0x18,0x00,0xF8,0x0F, // 77
|
||||
0x00,0x00,0xF8,0x0F,0x18,0x00,0x60,0x00,0xC0,0x01,0x00,0x03,0x00,0x0C,0xF8,0x0F, // 78
|
||||
0x00,0x00,0xE0,0x03,0x10,0x04,0x08,0x08,0x08,0x08,0x08,0x08,0x08,0x08,0x10,0x04,0xE0,0x03, // 79
|
||||
0x00,0x00,0xF8,0x0F,0x88,0x00,0x88,0x00,0x88,0x00,0x88,0x00,0x70, // 80
|
||||
0x00,0x00,0xE0,0x03,0x10,0x04,0x08,0x08,0x08,0x08,0x08,0x08,0x08,0x18,0x10,0x24,0xE0,0x03, // 81
|
||||
0x00,0x00,0xF8,0x0F,0x88,0x00,0x88,0x00,0x88,0x00,0x88,0x01,0x70,0x07,0x00,0x0C, // 82
|
||||
0x00,0x00,0x70,0x0C,0xC8,0x08,0x88,0x08,0x88,0x08,0x88,0x08,0x18,0x07, // 83
|
||||
0x08,0x00,0x08,0x00,0x08,0x00,0xF8,0x0F,0x08,0x00,0x08,0x00,0x08, // 84
|
||||
0x00,0x00,0xF8,0x07,0x00,0x0C,0x00,0x08,0x00,0x08,0x00,0x08,0x00,0x0C,0xF8,0x07, // 85
|
||||
0x08,0x00,0x78,0x00,0xC0,0x01,0x00,0x0E,0x00,0x0E,0x80,0x03,0x70,0x00,0x18, // 86
|
||||
0x00,0x00,0xF8,0x00,0x80,0x0F,0x00,0x0C,0xC0,0x03,0x38,0x00,0x78,0x00,0x80,0x07,0x00,0x0C,0xC0,0x07,0x78, // 87
|
||||
0x00,0x00,0x08,0x0C,0x30,0x06,0xE0,0x01,0xC0,0x01,0x30,0x03,0x18,0x0C,0x00,0x08, // 88
|
||||
0x08,0x00,0x10,0x00,0x60,0x00,0x80,0x0F,0x60,0x00,0x18,0x00,0x08, // 89
|
||||
0x00,0x00,0x08,0x0C,0x08,0x0E,0x08,0x0B,0x88,0x08,0x68,0x08,0x38,0x08,0x18,0x08, // 90
|
||||
0x00,0x00,0xFC,0x1F,0x04,0x10, // 91
|
||||
0x18,0x00,0xE0,0x00,0x00,0x0F,0x00,0x30, // 92
|
||||
0x00,0x00,0x00,0x00,0x04,0x10,0xFC,0x1F, // 93
|
||||
0x00,0x00,0x40,0x00,0x20,0x00,0x30,0x00,0x18,0x00,0x08,0x00,0x10,0x00,0x20,0x00,0x40, // 94
|
||||
0x00,0x40,0x00,0x40,0x00,0x40,0x00,0x40,0x00,0x40,0x00,0x40, // 95
|
||||
0x00,0x00,0x02,0x00,0x0C, // 96
|
||||
0x00,0x00,0x60,0x06,0x20,0x09,0x20,0x09,0x20,0x09,0x60,0x05,0xC0,0x0F, // 97
|
||||
0x00,0x00,0xFC,0x0F,0x40,0x04,0x20,0x08,0x20,0x08,0x60,0x0C,0xC0,0x07, // 98
|
||||
0x00,0x00,0xC0,0x07,0x60,0x0C,0x20,0x08,0x20,0x08,0x20,0x08, // 99
|
||||
0x00,0x00,0xC0,0x07,0x60,0x0C,0x20,0x08,0x20,0x08,0x40,0x04,0xFC,0x0F, // 100
|
||||
0x00,0x00,0xC0,0x07,0x60,0x0D,0x20,0x09,0x20,0x09,0x60,0x09,0xC0,0x09, // 101
|
||||
0x20,0x00,0xF8,0x0F,0x24,0x00,0x24, // 102
|
||||
0x00,0x00,0xC0,0x07,0x60,0x4C,0x20,0x48,0x20,0x48,0x40,0x64,0xE0,0x3F, // 103
|
||||
0x00,0x00,0xFC,0x0F,0x40,0x00,0x20,0x00,0x20,0x00,0xC0,0x0F, // 104
|
||||
0x00,0x00,0xE4,0x0F, // 105
|
||||
0x00,0x40,0xE4,0x3F, // 106
|
||||
0x00,0x00,0xFC,0x0F,0x00,0x01,0x80,0x02,0x40,0x04,0x20,0x08, // 107
|
||||
0x00,0x00,0xFC,0x0F, // 108
|
||||
0x00,0x00,0xE0,0x0F,0x40,0x00,0x20,0x00,0x20,0x00,0xC0,0x0F,0x40,0x00,0x20,0x00,0x20,0x00,0xC0,0x0F, // 109
|
||||
0x00,0x00,0xE0,0x0F,0x40,0x00,0x20,0x00,0x20,0x00,0xC0,0x0F, // 110
|
||||
0x00,0x00,0xC0,0x07,0x60,0x0C,0x20,0x08,0x20,0x08,0x60,0x0C,0xC0,0x07, // 111
|
||||
0x00,0x00,0xE0,0x7F,0x40,0x04,0x20,0x08,0x20,0x08,0x60,0x0C,0xC0,0x07, // 112
|
||||
0x00,0x00,0xC0,0x07,0x60,0x0C,0x20,0x08,0x20,0x08,0x40,0x04,0xE0,0x7F, // 113
|
||||
0x00,0x00,0xE0,0x0F,0x40,0x00,0x20,0x00,0x20, // 114
|
||||
0x00,0x00,0xC0,0x08,0x20,0x09,0x20,0x09,0x20,0x09,0x20,0x06, // 115
|
||||
0x20,0x00,0xF8,0x0F,0x20,0x08,0x20,0x08, // 116
|
||||
0x00,0x00,0xE0,0x07,0x00,0x08,0x00,0x08,0x00,0x04,0xE0,0x0F, // 117
|
||||
0x00,0x00,0xE0,0x00,0x00,0x07,0x00,0x08,0x00,0x07,0xE0,0x01,0x20, // 118
|
||||
0x00,0x00,0xE0,0x01,0x00,0x0E,0x00,0x0F,0xE0,0x00,0xE0,0x01,0x00,0x0E,0x00,0x0F,0xE0, // 119
|
||||
0x00,0x00,0x20,0x0C,0xC0,0x06,0x80,0x01,0xC0,0x06,0x60,0x0C, // 120
|
||||
0x00,0x00,0xE0,0x40,0x00,0x67,0x00,0x38,0x00,0x07,0xE0,0x00,0x20, // 121
|
||||
0x00,0x00,0x20,0x0C,0x20,0x0E,0x20,0x0B,0xA0,0x08,0x60,0x08,0x20,0x08, // 122
|
||||
0x00,0x00,0x80,0x00,0x80,0x00,0x7C,0x3F,0x04,0x20,0x04,0x20, // 123
|
||||
0x00,0x00,0x00,0x00,0xFC,0x3F, // 124
|
||||
0x00,0x00,0x04,0x20,0x04,0x20,0x7C,0x3F,0x80,0x00,0x80, // 125
|
||||
0x00,0x00,0x00,0x01,0x80,0x00,0x80,0x00,0x80,0x00,0x00,0x01,0x00,0x01,0x00,0x01,0x80, // 126
|
||||
0xF8,0x3F,0x08,0x20,0x08,0x20,0x08,0x20,0x08,0x20,0xF8,0x3F, // 127
|
||||
0xF8,0x3F,0x08,0x20,0x08,0x20,0x08,0x20,0x08,0x20,0xF8,0x3F, // 128
|
||||
0xF8,0x3F,0x08,0x20,0x08,0x20,0x08,0x20,0x08,0x20,0xF8,0x3F, // 129
|
||||
0xF8,0x3F,0x08,0x20,0x08,0x20,0x08,0x20,0x08,0x20,0xF8,0x3F, // 130
|
||||
0xF8,0x3F,0x08,0x20,0x08,0x20,0x08,0x20,0x08,0x20,0xF8,0x3F, // 131
|
||||
0xF8,0x3F,0x08,0x20,0x08,0x20,0x08,0x20,0x08,0x20,0xF8,0x3F, // 132
|
||||
0xF8,0x3F,0x08,0x20,0x08,0x20,0x08,0x20,0x08,0x20,0xF8,0x3F, // 133
|
||||
0xF8,0x3F,0x08,0x20,0x08,0x20,0x08,0x20,0x08,0x20,0xF8,0x3F, // 134
|
||||
0xF8,0x3F,0x08,0x20,0x08,0x20,0x08,0x20,0x08,0x20,0xF8,0x3F, // 135
|
||||
0xF8,0x3F,0x08,0x20,0x08,0x20,0x08,0x20,0x08,0x20,0xF8,0x3F, // 136
|
||||
0xF8,0x3F,0x08,0x20,0x08,0x20,0x08,0x20,0x08,0x20,0xF8,0x3F, // 137
|
||||
0xF8,0x3F,0x08,0x20,0x08,0x20,0x08,0x20,0x08,0x20,0xF8,0x3F, // 138
|
||||
0xF8,0x3F,0x08,0x20,0x08,0x20,0x08,0x20,0x08,0x20,0xF8,0x3F, // 139
|
||||
0xF8,0x3F,0x08,0x20,0x08,0x20,0x08,0x20,0x08,0x20,0xF8,0x3F, // 140
|
||||
0xF8,0x3F,0x08,0x20,0x08,0x20,0x08,0x20,0x08,0x20,0xF8,0x3F, // 141
|
||||
0xF8,0x3F,0x08,0x20,0x08,0x20,0x08,0x20,0x08,0x20,0xF8,0x3F, // 142
|
||||
0xF8,0x3F,0x08,0x20,0x08,0x20,0x08,0x20,0x08,0x20,0xF8,0x3F, // 143
|
||||
0xF8,0x3F,0x08,0x20,0x08,0x20,0x08,0x20,0x08,0x20,0xF8,0x3F, // 144
|
||||
0xF8,0x3F,0x08,0x20,0x08,0x20,0x08,0x20,0x08,0x20,0xF8,0x3F, // 145
|
||||
0xF8,0x3F,0x08,0x20,0x08,0x20,0x08,0x20,0x08,0x20,0xF8,0x3F, // 146
|
||||
0xF8,0x3F,0x08,0x20,0x08,0x20,0x08,0x20,0x08,0x20,0xF8,0x3F, // 147
|
||||
0xF8,0x3F,0x08,0x20,0x08,0x20,0x08,0x20,0x08,0x20,0xF8,0x3F, // 148
|
||||
0xF8,0x3F,0x08,0x20,0x08,0x20,0x08,0x20,0x08,0x20,0xF8,0x3F, // 149
|
||||
0xF8,0x3F,0x08,0x20,0x08,0x20,0x08,0x20,0x08,0x20,0xF8,0x3F, // 150
|
||||
0xF8,0x3F,0x08,0x20,0x08,0x20,0x08,0x20,0x08,0x20,0xF8,0x3F, // 151
|
||||
0xF8,0x3F,0x08,0x20,0x08,0x20,0x08,0x20,0x08,0x20,0xF8,0x3F, // 152
|
||||
0xF8,0x3F,0x08,0x20,0x08,0x20,0x08,0x20,0x08,0x20,0xF8,0x3F, // 153
|
||||
0xF8,0x3F,0x08,0x20,0x08,0x20,0x08,0x20,0x08,0x20,0xF8,0x3F, // 154
|
||||
0xF8,0x3F,0x08,0x20,0x08,0x20,0x08,0x20,0x08,0x20,0xF8,0x3F, // 155
|
||||
0xF8,0x3F,0x08,0x20,0x08,0x20,0x08,0x20,0x08,0x20,0xF8,0x3F, // 156
|
||||
0xF8,0x3F,0x08,0x20,0x08,0x20,0x08,0x20,0x08,0x20,0xF8,0x3F, // 157
|
||||
0xF8,0x3F,0x08,0x20,0x08,0x20,0x08,0x20,0x08,0x20,0xF8,0x3F, // 158
|
||||
0xF8,0x3F,0x08,0x20,0x08,0x20,0x08,0x20,0x08,0x20,0xF8,0x3F, // 159
|
||||
0x00,0x00,0x00,0x00,0xC8,0x0F, // 161
|
||||
0x00,0x00,0xC0,0x07,0x60,0x0C,0x20,0x08,0xF0,0x3F,0x20,0x08,0x20,0x08, // 162
|
||||
0x00,0x00,0x80,0x08,0xF0,0x0F,0x88,0x08,0x88,0x08,0x88,0x08,0x08,0x08, // 163
|
||||
0x00,0x00,0xC0,0x07,0x40,0x04,0x40,0x04,0x40,0x04,0xC0,0x07, // 164
|
||||
0x00,0x00,0x58,0x01,0x60,0x01,0x80,0x0F,0x60,0x01,0x58,0x01, // 165
|
||||
0x00,0x00,0x00,0x00,0x78,0x3C, // 166
|
||||
0x00,0x00,0xB0,0x21,0x48,0x22,0x48,0x24,0x88,0x1C,0x00,0x03, // 167
|
||||
0x00,0x00,0x04,0x00,0x00,0x00,0x04, // 168
|
||||
0x00,0x00,0x00,0x00,0xE0,0x03,0x30,0x06,0xD8,0x0D,0x28,0x0A,0x28,0x0A,0x28,0x0A,0x18,0x0C,0x30,0x06,0xE0,0x03, // 169
|
||||
0x00,0x00,0xE8,0x02,0xA8,0x02,0xA8,0x02,0xF0,0x02, // 170
|
||||
0x00,0x00,0x00,0x01,0x80,0x02,0x40,0x05,0x80,0x01,0xC0,0x02,0x40,0x04, // 171
|
||||
0x00,0x00,0x80,0x00,0x80,0x00,0x80,0x00,0x80,0x00,0x80,0x00,0x80,0x00,0x80,0x00,0x80,0x07, // 172
|
||||
0x00,0x00,0x00,0x01,0x00,0x01,0x00,0x01, // 173
|
||||
0x00,0x00,0x00,0x00,0xE0,0x03,0x30,0x06,0x18,0x0C,0xE8,0x0B,0xA8,0x08,0x68,0x0B,0x18,0x0C,0x30,0x06,0xE0,0x03, // 174
|
||||
0x00,0x00,0x04,0x00,0x04,0x00,0x04,0x00,0x04, // 175
|
||||
0x00,0x00,0x30,0x00,0x48,0x00,0x48,0x00,0x30, // 176
|
||||
0x00,0x00,0x80,0x08,0x80,0x08,0x80,0x08,0xF0,0x0B,0x80,0x08,0x80,0x08,0x80,0x08,0x80,0x08, // 177
|
||||
0x08,0x01,0x88,0x01,0x48,0x01,0x38,0x01, // 178
|
||||
0x08,0x01,0x28,0x01,0x28,0x01,0xD8, // 179
|
||||
0x00,0x00,0x00,0x00,0x08,0x00,0x04,0x00,0x02, // 180
|
||||
0x00,0x00,0xE0,0x7F,0x00,0x08,0x00,0x08,0x00,0x08,0xE0,0x0F,0x00,0x08, // 181
|
||||
0x20,0x00,0xF0,0x00,0xF8,0x00,0xF8,0x3F,0x08,0x00,0xF8,0x3F, // 182
|
||||
0x00,0x00,0x80, // 183
|
||||
0x00,0x00,0x00,0x00,0x00,0x40,0x00,0x60, // 184
|
||||
0x00,0x00,0x88,0x00,0xF8,0x00,0x80, // 185
|
||||
0x00,0x00,0x70,0x02,0x88,0x02,0x88,0x02,0x88,0x02,0x70,0x02, // 186
|
||||
0x00,0x00,0x40,0x06,0x80,0x02,0x40,0x05,0xC0,0x02,0x80,0x01,0x00,0x01, // 187
|
||||
0x00,0x00,0x88,0x00,0xF8,0x00,0x80,0x0C,0x00,0x03,0x80,0x00,0x60,0x00,0x18,0x07,0x00,0x05,0x80,0x0F,0x00,0x04, // 188
|
||||
0x00,0x00,0x88,0x00,0xF8,0x00,0x80,0x08,0x00,0x06,0x80,0x01,0x40,0x00,0xB0,0x08,0x88,0x0C,0x80,0x0A,0x80,0x09, // 189
|
||||
0x88,0x00,0xA8,0x00,0xA8,0x00,0xD8,0x0C,0x00,0x03,0xC0,0x00,0x20,0x00,0x18,0x07,0x80,0x04,0x80,0x0F,0x00,0x04, // 190
|
||||
0x00,0x00,0x00,0x07,0x80,0x09,0xE8,0x08,0x00,0x08, // 191
|
||||
0x00,0x08,0x00,0x0F,0xE0,0x03,0x39,0x02,0x1A,0x02,0xE0,0x02,0x00,0x07,0x00,0x0C, // 192
|
||||
0x00,0x08,0x00,0x0F,0xE0,0x03,0x38,0x02,0x1B,0x02,0xE1,0x02,0x00,0x07,0x00,0x0C, // 193
|
||||
0x00,0x08,0x00,0x0F,0xE0,0x03,0x3A,0x02,0x1B,0x02,0xE0,0x02,0x00,0x07,0x00,0x0C, // 194
|
||||
0x00,0x08,0x00,0x0F,0xE3,0x03,0x39,0x02,0x1A,0x02,0xE3,0x02,0x00,0x07,0x00,0x0C, // 195
|
||||
0x00,0x0C,0x80,0x07,0xF2,0x02,0x08,0x02,0xF2,0x02,0x80,0x07,0x00,0x0C, // 196
|
||||
0x00,0x0C,0x80,0x03,0x77,0x02,0x19,0x02,0x66,0x02,0x80,0x03,0x00,0x0C, // 197
|
||||
0x00,0x0C,0x00,0x07,0xE0,0x03,0x38,0x02,0x08,0x02,0xF8,0x0F,0x88,0x08,0x88,0x08,0x88,0x08,0x88,0x08, // 198
|
||||
0x00,0x00,0xE0,0x03,0x10,0x06,0x08,0x0C,0x08,0x4C,0x08,0x7C,0x08,0x0C,0x10,0x04, // 199
|
||||
0x00,0x00,0xF8,0x0F,0x89,0x08,0x8A,0x08,0x88,0x08,0x88,0x08, // 200
|
||||
0x00,0x00,0xF8,0x0F,0x88,0x08,0x8A,0x08,0x89,0x08,0x88,0x08, // 201
|
||||
0x00,0x00,0xF8,0x0F,0x8A,0x08,0x89,0x08,0x8A,0x08,0x88,0x08, // 202
|
||||
0x00,0x00,0xF8,0x0F,0x8A,0x08,0x88,0x08,0x8A,0x08,0x88,0x08, // 203
|
||||
0x01,0x00,0xFA,0x0F, // 204
|
||||
0x00,0x00,0xFA,0x0F,0x01, // 205
|
||||
0x02,0x00,0xF9,0x0F,0x02, // 206
|
||||
0x00,0x00,0x02,0x00,0xF8,0x0F,0x02, // 207
|
||||
0x80,0x00,0xF8,0x0F,0x88,0x08,0x88,0x08,0x08,0x08,0x08,0x08,0x10,0x04,0xE0,0x03, // 208
|
||||
0x00,0x00,0xF8,0x0F,0x1A,0x00,0x61,0x00,0xC3,0x01,0x02,0x03,0x01,0x0C,0xF8,0x0F, // 209
|
||||
0x00,0x00,0xE0,0x03,0x10,0x04,0x08,0x08,0x09,0x08,0x0A,0x08,0x08,0x08,0x10,0x04,0xE0,0x03, // 210
|
||||
0x00,0x00,0xE0,0x03,0x10,0x04,0x08,0x08,0x0A,0x08,0x09,0x08,0x08,0x08,0x10,0x04,0xE0,0x03, // 211
|
||||
0x00,0x00,0xE0,0x03,0x10,0x04,0x0A,0x08,0x09,0x08,0x09,0x08,0x0A,0x08,0x10,0x04,0xE0,0x03, // 212
|
||||
0x00,0x00,0xE0,0x03,0x10,0x04,0x0B,0x08,0x09,0x08,0x0A,0x08,0x0B,0x08,0x10,0x04,0xE0,0x03, // 213
|
||||
0x00,0x00,0xE0,0x03,0x10,0x04,0x0A,0x08,0x08,0x08,0x08,0x08,0x0A,0x08,0x10,0x04,0xE0,0x03, // 214
|
||||
0x00,0x00,0x00,0x00,0x20,0x04,0x40,0x02,0x80,0x01,0x80,0x01,0x40,0x02,0x20,0x04, // 215
|
||||
0x00,0x00,0xE0,0x0B,0x10,0x04,0x08,0x0B,0x88,0x09,0xC8,0x08,0x68,0x08,0x10,0x04,0xE8,0x03, // 216
|
||||
0x00,0x00,0xF8,0x07,0x00,0x0C,0x01,0x08,0x02,0x08,0x00,0x08,0x00,0x0C,0xF8,0x07, // 217
|
||||
0x00,0x00,0xF8,0x07,0x00,0x0C,0x00,0x08,0x02,0x08,0x01,0x08,0x00,0x0C,0xF8,0x07, // 218
|
||||
0x00,0x00,0xF8,0x07,0x00,0x0C,0x03,0x08,0x01,0x08,0x03,0x08,0x00,0x0C,0xF8,0x07, // 219
|
||||
0x00,0x00,0xF8,0x07,0x00,0x0C,0x02,0x08,0x00,0x08,0x02,0x08,0x00,0x0C,0xF8,0x07, // 220
|
||||
0x08,0x00,0x10,0x00,0x60,0x00,0x82,0x0F,0x60,0x00,0x18,0x00,0x08, // 221
|
||||
0x00,0x00,0xF8,0x0F,0x20,0x02,0x20,0x02,0x20,0x02,0x20,0x02,0xC0,0x01, // 222
|
||||
0x00,0x00,0xF8,0x0F,0x04,0x00,0xE4,0x08,0x94,0x08,0x18,0x09,0x00,0x06, // 223
|
||||
0x00,0x00,0x60,0x06,0x24,0x09,0x28,0x09,0x30,0x09,0x60,0x05,0xC0,0x0F, // 224
|
||||
0x00,0x00,0x60,0x06,0x20,0x09,0x30,0x09,0x28,0x09,0x64,0x05,0xC0,0x0F, // 225
|
||||
0x00,0x00,0x60,0x06,0x38,0x09,0x24,0x09,0x2C,0x09,0x70,0x05,0xC0,0x0F, // 226
|
||||
0x00,0x00,0x60,0x06,0x2C,0x09,0x24,0x09,0x28,0x09,0x6C,0x05,0xC0,0x0F, // 227
|
||||
0x00,0x00,0x60,0x06,0x24,0x09,0x20,0x09,0x24,0x09,0x60,0x05,0xC0,0x0F, // 228
|
||||
0x00,0x00,0x60,0x06,0x24,0x09,0x2A,0x09,0x2A,0x09,0x64,0x05,0xC0,0x0F, // 229
|
||||
0x00,0x00,0x20,0x07,0xA0,0x08,0xA0,0x08,0xA0,0x0C,0xC0,0x07,0x60,0x0D,0x20,0x09,0x20,0x09,0x60,0x09,0xC0,0x09, // 230
|
||||
0x00,0x00,0xC0,0x07,0x60,0x0C,0x20,0x4C,0x20,0x7C,0x20,0x04, // 231
|
||||
0x00,0x00,0xC0,0x07,0x64,0x0D,0x2C,0x09,0x20,0x09,0x60,0x09,0xC0,0x09, // 232
|
||||
0x00,0x00,0xC0,0x07,0x60,0x0D,0x20,0x09,0x2C,0x09,0x64,0x09,0xC0,0x09, // 233
|
||||
0x00,0x00,0xC0,0x07,0x68,0x0D,0x24,0x09,0x24,0x09,0x68,0x09,0xC0,0x09, // 234
|
||||
0x00,0x00,0xC0,0x07,0x60,0x0D,0x24,0x09,0x20,0x09,0x64,0x09,0xC0,0x09, // 235
|
||||
0x04,0x00,0xF8,0x0F, // 236
|
||||
0x00,0x00,0xF8,0x0F,0x04, // 237
|
||||
0x08,0x00,0xE4,0x0F,0x08, // 238
|
||||
0x04,0x00,0xE0,0x0F,0x04, // 239
|
||||
0x00,0x00,0xC0,0x07,0x74,0x0C,0x2C,0x08,0x38,0x08,0x24,0x0C,0xC0,0x07, // 240
|
||||
0x00,0x00,0xE0,0x0F,0x4C,0x00,0x2C,0x00,0x2C,0x00,0xC0,0x0F, // 241
|
||||
0x00,0x00,0xC0,0x07,0x64,0x0C,0x2C,0x08,0x20,0x08,0x60,0x0C,0xC0,0x07, // 242
|
||||
0x00,0x00,0xC0,0x07,0x60,0x0C,0x20,0x08,0x2C,0x08,0x64,0x0C,0xC0,0x07, // 243
|
||||
0x00,0x00,0xC0,0x07,0x68,0x0C,0x24,0x08,0x24,0x08,0x68,0x0C,0xC0,0x07, // 244
|
||||
0x00,0x00,0xC0,0x07,0x6C,0x0C,0x24,0x08,0x28,0x08,0x6C,0x0C,0xC0,0x07, // 245
|
||||
0x00,0x00,0xC0,0x07,0x64,0x0C,0x20,0x08,0x20,0x08,0x64,0x0C,0xC0,0x07, // 246
|
||||
0x00,0x00,0x80,0x00,0x80,0x00,0x80,0x00,0xA0,0x02,0x80,0x00,0x80,0x00,0x80,0x00,0x80, // 247
|
||||
0x00,0x00,0xC0,0x0F,0x60,0x0C,0x20,0x0B,0xA0,0x08,0x60,0x0C,0xE0,0x07, // 248
|
||||
0x00,0x00,0xE0,0x07,0x04,0x08,0x18,0x08,0x00,0x04,0xE0,0x0F, // 249
|
||||
0x00,0x00,0xE0,0x07,0x00,0x08,0x18,0x08,0x04,0x04,0xE0,0x0F, // 250
|
||||
0x00,0x00,0xE0,0x07,0x18,0x08,0x04,0x08,0x18,0x04,0xE0,0x0F, // 251
|
||||
0x00,0x00,0xE0,0x07,0x04,0x08,0x00,0x08,0x04,0x04,0xE0,0x0F, // 252
|
||||
0x00,0x00,0xE0,0x40,0x00,0x67,0x10,0x38,0x0C,0x07,0xE4,0x01,0x20, // 253
|
||||
0x00,0x00,0xFC,0x7F,0x40,0x04,0x20,0x08,0x20,0x08,0x60,0x0C,0xC0,0x07, // 254
|
||||
0x00,0x00,0xE0,0x40,0x04,0x47,0x00,0x38,0x84,0x07,0xE0 // 255
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
@@ -0,0 +1,831 @@
|
||||
/**
|
||||
* The MIT License (MIT)
|
||||
*
|
||||
* Copyright (c) 2016 by Daniel Eichhorn
|
||||
* Copyright (c) 2016 by Fabrice Weinberg
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in all
|
||||
* copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
* SOFTWARE.
|
||||
*
|
||||
* Credits for parts of this code go to Mike Rankin. Thank you so much for sharing!
|
||||
*/
|
||||
|
||||
#include "OLEDDisplay.h"
|
||||
|
||||
OLEDDisplay::~OLEDDisplay() {
|
||||
end();
|
||||
}
|
||||
|
||||
bool OLEDDisplay::init() {
|
||||
if (!this->connect()) {
|
||||
DEBUG_OLEDDISPLAY("[OLEDDISPLAY][init] Can't establish connection to display\n");
|
||||
return false;
|
||||
}
|
||||
if(this->buffer==NULL) {
|
||||
this->buffer = (uint8_t*) malloc(sizeof(uint8_t) * DISPLAY_BUFFER_SIZE);
|
||||
if(!this->buffer) {
|
||||
DEBUG_OLEDDISPLAY("[OLEDDISPLAY][init] Not enough memory to create display\n");
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
#ifdef OLEDDISPLAY_DOUBLE_BUFFER
|
||||
if(this->buffer_back==NULL) {
|
||||
this->buffer_back = (uint8_t*) malloc(sizeof(uint8_t) * DISPLAY_BUFFER_SIZE);
|
||||
if(!this->buffer_back) {
|
||||
DEBUG_OLEDDISPLAY("[OLEDDISPLAY][init] Not enough memory to create back buffer\n");
|
||||
free(this->buffer);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
sendInitCommands();
|
||||
resetDisplay();
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
void OLEDDisplay::end() {
|
||||
if (this->buffer) { free(this->buffer); this->buffer = NULL; }
|
||||
#ifdef OLEDDISPLAY_DOUBLE_BUFFER
|
||||
if (this->buffer_back) { free(this->buffer_back); this->buffer_back = NULL; }
|
||||
#endif
|
||||
if (this->logBuffer != NULL) { free(this->logBuffer); this->logBuffer = NULL; }
|
||||
}
|
||||
|
||||
void OLEDDisplay::resetDisplay(void) {
|
||||
clear();
|
||||
#ifdef OLEDDISPLAY_DOUBLE_BUFFER
|
||||
memset(buffer_back, 1, DISPLAY_BUFFER_SIZE);
|
||||
#endif
|
||||
display();
|
||||
}
|
||||
|
||||
void OLEDDisplay::setColor(OLEDDISPLAY_COLOR color) {
|
||||
this->color = color;
|
||||
}
|
||||
|
||||
void OLEDDisplay::setPixel(int16_t x, int16_t y) {
|
||||
if (x >= 0 && x < this->width() && y >= 0 && y < this->height()) {
|
||||
switch (color) {
|
||||
case WHITE: buffer[x + (y / 8) * this->width()] |= (1 << (y & 7)); break;
|
||||
case BLACK: buffer[x + (y / 8) * this->width()] &= ~(1 << (y & 7)); break;
|
||||
case INVERSE: buffer[x + (y / 8) * this->width()] ^= (1 << (y & 7)); break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Bresenham's algorithm - thx wikipedia and Adafruit_GFX
|
||||
void OLEDDisplay::drawLine(int16_t x0, int16_t y0, int16_t x1, int16_t y1) {
|
||||
int16_t steep = abs(y1 - y0) > abs(x1 - x0);
|
||||
if (steep) {
|
||||
_swap_int16_t(x0, y0);
|
||||
_swap_int16_t(x1, y1);
|
||||
}
|
||||
|
||||
if (x0 > x1) {
|
||||
_swap_int16_t(x0, x1);
|
||||
_swap_int16_t(y0, y1);
|
||||
}
|
||||
|
||||
int16_t dx, dy;
|
||||
dx = x1 - x0;
|
||||
dy = abs(y1 - y0);
|
||||
|
||||
int16_t err = dx / 2;
|
||||
int16_t ystep;
|
||||
|
||||
if (y0 < y1) {
|
||||
ystep = 1;
|
||||
} else {
|
||||
ystep = -1;
|
||||
}
|
||||
|
||||
for (; x0<=x1; x0++) {
|
||||
if (steep) {
|
||||
setPixel(y0, x0);
|
||||
} else {
|
||||
setPixel(x0, y0);
|
||||
}
|
||||
err -= dy;
|
||||
if (err < 0) {
|
||||
y0 += ystep;
|
||||
err += dx;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void OLEDDisplay::drawRect(int16_t x, int16_t y, int16_t width, int16_t height) {
|
||||
drawHorizontalLine(x, y, width);
|
||||
drawVerticalLine(x, y, height);
|
||||
drawVerticalLine(x + width - 1, y, height);
|
||||
drawHorizontalLine(x, y + height - 1, width);
|
||||
}
|
||||
|
||||
void OLEDDisplay::fillRect(int16_t xMove, int16_t yMove, int16_t width, int16_t height) {
|
||||
for (int16_t x = xMove; x < xMove + width; x++) {
|
||||
drawVerticalLine(x, yMove, height);
|
||||
}
|
||||
}
|
||||
|
||||
void OLEDDisplay::drawCircle(int16_t x0, int16_t y0, int16_t radius) {
|
||||
int16_t x = 0, y = radius;
|
||||
int16_t dp = 1 - radius;
|
||||
do {
|
||||
if (dp < 0)
|
||||
dp = dp + 2 * (++x) + 3;
|
||||
else
|
||||
dp = dp + 2 * (++x) - 2 * (--y) + 5;
|
||||
|
||||
setPixel(x0 + x, y0 + y); //For the 8 octants
|
||||
setPixel(x0 - x, y0 + y);
|
||||
setPixel(x0 + x, y0 - y);
|
||||
setPixel(x0 - x, y0 - y);
|
||||
setPixel(x0 + y, y0 + x);
|
||||
setPixel(x0 - y, y0 + x);
|
||||
setPixel(x0 + y, y0 - x);
|
||||
setPixel(x0 - y, y0 - x);
|
||||
|
||||
} while (x < y);
|
||||
|
||||
setPixel(x0 + radius, y0);
|
||||
setPixel(x0, y0 + radius);
|
||||
setPixel(x0 - radius, y0);
|
||||
setPixel(x0, y0 - radius);
|
||||
}
|
||||
|
||||
void OLEDDisplay::drawCircleQuads(int16_t x0, int16_t y0, int16_t radius, uint8_t quads) {
|
||||
int16_t x = 0, y = radius;
|
||||
int16_t dp = 1 - radius;
|
||||
while (x < y) {
|
||||
if (dp < 0)
|
||||
dp = dp + 2 * (++x) + 3;
|
||||
else
|
||||
dp = dp + 2 * (++x) - 2 * (--y) + 5;
|
||||
if (quads & 0x1) {
|
||||
setPixel(x0 + x, y0 - y);
|
||||
setPixel(x0 + y, y0 - x);
|
||||
}
|
||||
if (quads & 0x2) {
|
||||
setPixel(x0 - y, y0 - x);
|
||||
setPixel(x0 - x, y0 - y);
|
||||
}
|
||||
if (quads & 0x4) {
|
||||
setPixel(x0 - y, y0 + x);
|
||||
setPixel(x0 - x, y0 + y);
|
||||
}
|
||||
if (quads & 0x8) {
|
||||
setPixel(x0 + x, y0 + y);
|
||||
setPixel(x0 + y, y0 + x);
|
||||
}
|
||||
}
|
||||
if (quads & 0x1 && quads & 0x8) {
|
||||
setPixel(x0 + radius, y0);
|
||||
}
|
||||
if (quads & 0x4 && quads & 0x8) {
|
||||
setPixel(x0, y0 + radius);
|
||||
}
|
||||
if (quads & 0x2 && quads & 0x4) {
|
||||
setPixel(x0 - radius, y0);
|
||||
}
|
||||
if (quads & 0x1 && quads & 0x2) {
|
||||
setPixel(x0, y0 - radius);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void OLEDDisplay::fillCircle(int16_t x0, int16_t y0, int16_t radius) {
|
||||
int16_t x = 0, y = radius;
|
||||
int16_t dp = 1 - radius;
|
||||
do {
|
||||
if (dp < 0)
|
||||
dp = dp + 2 * (++x) + 3;
|
||||
else
|
||||
dp = dp + 2 * (++x) - 2 * (--y) + 5;
|
||||
|
||||
drawHorizontalLine(x0 - x, y0 - y, 2*x);
|
||||
drawHorizontalLine(x0 - x, y0 + y, 2*x);
|
||||
drawHorizontalLine(x0 - y, y0 - x, 2*y);
|
||||
drawHorizontalLine(x0 - y, y0 + x, 2*y);
|
||||
|
||||
|
||||
} while (x < y);
|
||||
drawHorizontalLine(x0 - radius, y0, 2 * radius);
|
||||
|
||||
}
|
||||
|
||||
void OLEDDisplay::drawHorizontalLine(int16_t x, int16_t y, int16_t length) {
|
||||
if (y < 0 || y >= this->height()) { return; }
|
||||
|
||||
if (x < 0) {
|
||||
length += x;
|
||||
x = 0;
|
||||
}
|
||||
|
||||
if ( (x + length) > this->width()) {
|
||||
length = (this->width() - x);
|
||||
}
|
||||
|
||||
if (length <= 0) { return; }
|
||||
|
||||
uint8_t * bufferPtr = buffer;
|
||||
bufferPtr += (y >> 3) * this->width();
|
||||
bufferPtr += x;
|
||||
|
||||
uint8_t drawBit = 1 << (y & 7);
|
||||
|
||||
switch (color) {
|
||||
case WHITE: while (length--) {
|
||||
*bufferPtr++ |= drawBit;
|
||||
}; break;
|
||||
case BLACK: drawBit = ~drawBit; while (length--) {
|
||||
*bufferPtr++ &= drawBit;
|
||||
}; break;
|
||||
case INVERSE: while (length--) {
|
||||
*bufferPtr++ ^= drawBit;
|
||||
}; break;
|
||||
}
|
||||
}
|
||||
|
||||
void OLEDDisplay::drawVerticalLine(int16_t x, int16_t y, int16_t length) {
|
||||
if (x < 0 || x >= this->width()) return;
|
||||
|
||||
if (y < 0) {
|
||||
length += y;
|
||||
y = 0;
|
||||
}
|
||||
|
||||
if ( (y + length) > this->height()) {
|
||||
length = (this->height() - y);
|
||||
}
|
||||
|
||||
if (length <= 0) return;
|
||||
|
||||
|
||||
uint8_t yOffset = y & 7;
|
||||
uint8_t drawBit;
|
||||
uint8_t *bufferPtr = buffer;
|
||||
|
||||
bufferPtr += (y >> 3) * this->width();
|
||||
bufferPtr += x;
|
||||
|
||||
if (yOffset) {
|
||||
yOffset = 8 - yOffset;
|
||||
drawBit = ~(0xFF >> (yOffset));
|
||||
|
||||
if (length < yOffset) {
|
||||
drawBit &= (0xFF >> (yOffset - length));
|
||||
}
|
||||
|
||||
switch (color) {
|
||||
case WHITE: *bufferPtr |= drawBit; break;
|
||||
case BLACK: *bufferPtr &= ~drawBit; break;
|
||||
case INVERSE: *bufferPtr ^= drawBit; break;
|
||||
}
|
||||
|
||||
if (length < yOffset) return;
|
||||
|
||||
length -= yOffset;
|
||||
bufferPtr += this->width();
|
||||
}
|
||||
|
||||
if (length >= 8) {
|
||||
switch (color) {
|
||||
case WHITE:
|
||||
case BLACK:
|
||||
drawBit = (color == WHITE) ? 0xFF : 0x00;
|
||||
do {
|
||||
*bufferPtr = drawBit;
|
||||
bufferPtr += this->width();
|
||||
length -= 8;
|
||||
} while (length >= 8);
|
||||
break;
|
||||
case INVERSE:
|
||||
do {
|
||||
*bufferPtr = ~(*bufferPtr);
|
||||
bufferPtr += this->width();
|
||||
length -= 8;
|
||||
} while (length >= 8);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (length > 0) {
|
||||
drawBit = (1 << (length & 7)) - 1;
|
||||
switch (color) {
|
||||
case WHITE: *bufferPtr |= drawBit; break;
|
||||
case BLACK: *bufferPtr &= ~drawBit; break;
|
||||
case INVERSE: *bufferPtr ^= drawBit; break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void OLEDDisplay::drawProgressBar(uint16_t x, uint16_t y, uint16_t width, uint16_t height, uint8_t progress) {
|
||||
uint16_t radius = height / 2;
|
||||
uint16_t xRadius = x + radius;
|
||||
uint16_t yRadius = y + radius;
|
||||
uint16_t doubleRadius = 2 * radius;
|
||||
uint16_t innerRadius = radius - 2;
|
||||
|
||||
setColor(WHITE);
|
||||
drawCircleQuads(xRadius, yRadius, radius, 0b00000110);
|
||||
drawHorizontalLine(xRadius, y, width - doubleRadius + 1);
|
||||
drawHorizontalLine(xRadius, y + height, width - doubleRadius + 1);
|
||||
drawCircleQuads(x + width - radius, yRadius, radius, 0b00001001);
|
||||
|
||||
uint16_t maxProgressWidth = (width - doubleRadius + 1) * progress / 100;
|
||||
|
||||
fillCircle(xRadius, yRadius, innerRadius);
|
||||
fillRect(xRadius + 1, y + 2, maxProgressWidth, height - 3);
|
||||
fillCircle(xRadius + maxProgressWidth, yRadius, innerRadius);
|
||||
}
|
||||
|
||||
void OLEDDisplay::drawFastImage(int16_t xMove, int16_t yMove, int16_t width, int16_t height, const char *image) {
|
||||
drawInternal(xMove, yMove, width, height, image, 0, 0);
|
||||
}
|
||||
|
||||
void OLEDDisplay::drawXbm(int16_t xMove, int16_t yMove, int16_t width, int16_t height, const char *xbm) {
|
||||
int16_t widthInXbm = (width + 7) / 8;
|
||||
uint8_t data = 0;
|
||||
|
||||
for(int16_t y = 0; y < height; y++) {
|
||||
for(int16_t x = 0; x < width; x++ ) {
|
||||
if (x & 7) {
|
||||
data >>= 1; // Move a bit
|
||||
} else { // Read new data every 8 bit
|
||||
data = pgm_read_byte(xbm + (x / 8) + y * widthInXbm);
|
||||
}
|
||||
// if there is a bit draw it
|
||||
if (data & 0x01) {
|
||||
setPixel(xMove + x, yMove + y);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void OLEDDisplay::drawStringInternal(int16_t xMove, int16_t yMove, char* text, uint16_t textLength, uint16_t textWidth) {
|
||||
uint8_t textHeight = pgm_read_byte(fontData + HEIGHT_POS);
|
||||
uint8_t firstChar = pgm_read_byte(fontData + FIRST_CHAR_POS);
|
||||
uint16_t sizeOfJumpTable = pgm_read_byte(fontData + CHAR_NUM_POS) * JUMPTABLE_BYTES;
|
||||
|
||||
uint8_t cursorX = 0;
|
||||
uint8_t cursorY = 0;
|
||||
|
||||
switch (textAlignment) {
|
||||
case TEXT_ALIGN_CENTER_BOTH:
|
||||
yMove -= textHeight >> 1;
|
||||
// Fallthrough
|
||||
case TEXT_ALIGN_CENTER:
|
||||
xMove -= textWidth >> 1; // divide by 2
|
||||
break;
|
||||
case TEXT_ALIGN_RIGHT:
|
||||
xMove -= textWidth;
|
||||
break;
|
||||
case TEXT_ALIGN_LEFT:
|
||||
break;
|
||||
}
|
||||
|
||||
// Don't draw anything if it is not on the screen.
|
||||
if (xMove + textWidth < 0 || xMove > this->width() ) {return;}
|
||||
if (yMove + textHeight < 0 || yMove > this->width() ) {return;}
|
||||
|
||||
for (uint16_t j = 0; j < textLength; j++) {
|
||||
int16_t xPos = xMove + cursorX;
|
||||
int16_t yPos = yMove + cursorY;
|
||||
|
||||
byte code = text[j];
|
||||
if (code >= firstChar) {
|
||||
byte charCode = code - firstChar;
|
||||
|
||||
// 4 Bytes per char code
|
||||
byte msbJumpToChar = pgm_read_byte( fontData + JUMPTABLE_START + charCode * JUMPTABLE_BYTES ); // MSB \ JumpAddress
|
||||
byte lsbJumpToChar = pgm_read_byte( fontData + JUMPTABLE_START + charCode * JUMPTABLE_BYTES + JUMPTABLE_LSB); // LSB /
|
||||
byte charByteSize = pgm_read_byte( fontData + JUMPTABLE_START + charCode * JUMPTABLE_BYTES + JUMPTABLE_SIZE); // Size
|
||||
byte currentCharWidth = pgm_read_byte( fontData + JUMPTABLE_START + charCode * JUMPTABLE_BYTES + JUMPTABLE_WIDTH); // Width
|
||||
|
||||
// Test if the char is drawable
|
||||
if (!(msbJumpToChar == 255 && lsbJumpToChar == 255)) {
|
||||
// Get the position of the char data
|
||||
uint16_t charDataPosition = JUMPTABLE_START + sizeOfJumpTable + ((msbJumpToChar << 8) + lsbJumpToChar);
|
||||
drawInternal(xPos, yPos, currentCharWidth, textHeight, fontData, charDataPosition, charByteSize);
|
||||
}
|
||||
|
||||
cursorX += currentCharWidth;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void OLEDDisplay::drawString(int16_t xMove, int16_t yMove, String strUser) {
|
||||
uint16_t lineHeight = pgm_read_byte(fontData + HEIGHT_POS);
|
||||
|
||||
// char* text must be freed!
|
||||
char* text = utf8ascii(strUser);
|
||||
|
||||
uint16_t yOffset = 0;
|
||||
// If the string should be centered vertically too
|
||||
// we need to now how heigh the string is.
|
||||
if (textAlignment == TEXT_ALIGN_CENTER_BOTH) {
|
||||
uint16_t lb = 0;
|
||||
// Find number of linebreaks in text
|
||||
for (uint16_t i=0;text[i] != 0; i++) {
|
||||
lb += (text[i] == 10);
|
||||
}
|
||||
// Calculate center
|
||||
yOffset = (lb * lineHeight) / 2;
|
||||
}
|
||||
|
||||
uint16_t line = 0;
|
||||
char* textPart = strtok(text,"\n");
|
||||
while (textPart != NULL) {
|
||||
uint16_t length = strlen(textPart);
|
||||
drawStringInternal(xMove, yMove - yOffset + (line++) * lineHeight, textPart, length, getStringWidth(textPart, length));
|
||||
textPart = strtok(NULL, "\n");
|
||||
}
|
||||
free(text);
|
||||
}
|
||||
|
||||
void OLEDDisplay::drawStringMaxWidth(int16_t xMove, int16_t yMove, uint16_t maxLineWidth, String strUser) {
|
||||
uint16_t firstChar = pgm_read_byte(fontData + FIRST_CHAR_POS);
|
||||
uint16_t lineHeight = pgm_read_byte(fontData + HEIGHT_POS);
|
||||
|
||||
char* text = utf8ascii(strUser);
|
||||
|
||||
uint16_t length = strlen(text);
|
||||
uint16_t lastDrawnPos = 0;
|
||||
uint16_t lineNumber = 0;
|
||||
uint16_t strWidth = 0;
|
||||
|
||||
uint16_t preferredBreakpoint = 0;
|
||||
uint16_t widthAtBreakpoint = 0;
|
||||
|
||||
for (uint16_t i = 0; i < length; i++) {
|
||||
strWidth += pgm_read_byte(fontData + JUMPTABLE_START + (text[i] - firstChar) * JUMPTABLE_BYTES + JUMPTABLE_WIDTH);
|
||||
|
||||
// Always try to break on a space or dash
|
||||
if (text[i] == ' ' || text[i]== '-') {
|
||||
preferredBreakpoint = i;
|
||||
widthAtBreakpoint = strWidth;
|
||||
}
|
||||
|
||||
if (strWidth >= maxLineWidth) {
|
||||
if (preferredBreakpoint == 0) {
|
||||
preferredBreakpoint = i;
|
||||
widthAtBreakpoint = strWidth;
|
||||
}
|
||||
drawStringInternal(xMove, yMove + (lineNumber++) * lineHeight , &text[lastDrawnPos], preferredBreakpoint - lastDrawnPos, widthAtBreakpoint);
|
||||
lastDrawnPos = preferredBreakpoint + 1;
|
||||
// It is possible that we did not draw all letters to i so we need
|
||||
// to account for the width of the chars from `i - preferredBreakpoint`
|
||||
// by calculating the width we did not draw yet.
|
||||
strWidth = strWidth - widthAtBreakpoint;
|
||||
preferredBreakpoint = 0;
|
||||
}
|
||||
}
|
||||
|
||||
// Draw last part if needed
|
||||
if (lastDrawnPos < length) {
|
||||
drawStringInternal(xMove, yMove + lineNumber * lineHeight , &text[lastDrawnPos], length - lastDrawnPos, getStringWidth(&text[lastDrawnPos], length - lastDrawnPos));
|
||||
}
|
||||
|
||||
free(text);
|
||||
}
|
||||
|
||||
uint16_t OLEDDisplay::getStringWidth(const char* text, uint16_t length) {
|
||||
uint16_t firstChar = pgm_read_byte(fontData + FIRST_CHAR_POS);
|
||||
|
||||
uint16_t stringWidth = 0;
|
||||
uint16_t maxWidth = 0;
|
||||
|
||||
while (length--) {
|
||||
stringWidth += pgm_read_byte(fontData + JUMPTABLE_START + (text[length] - firstChar) * JUMPTABLE_BYTES + JUMPTABLE_WIDTH);
|
||||
if (text[length] == 10) {
|
||||
maxWidth = max(maxWidth, stringWidth);
|
||||
stringWidth = 0;
|
||||
}
|
||||
}
|
||||
|
||||
return max(maxWidth, stringWidth);
|
||||
}
|
||||
|
||||
uint16_t OLEDDisplay::getStringWidth(String strUser) {
|
||||
char* text = utf8ascii(strUser);
|
||||
uint16_t length = strlen(text);
|
||||
uint16_t width = getStringWidth(text, length);
|
||||
free(text);
|
||||
return width;
|
||||
}
|
||||
|
||||
void OLEDDisplay::setTextAlignment(OLEDDISPLAY_TEXT_ALIGNMENT textAlignment) {
|
||||
this->textAlignment = textAlignment;
|
||||
}
|
||||
|
||||
void OLEDDisplay::setFont(const char *fontData) {
|
||||
this->fontData = fontData;
|
||||
}
|
||||
|
||||
void OLEDDisplay::displayOn(void) {
|
||||
sendCommand(DISPLAYON);
|
||||
}
|
||||
|
||||
void OLEDDisplay::displayOff(void) {
|
||||
sendCommand(DISPLAYOFF);
|
||||
}
|
||||
|
||||
void OLEDDisplay::invertDisplay(void) {
|
||||
sendCommand(INVERTDISPLAY);
|
||||
}
|
||||
|
||||
void OLEDDisplay::normalDisplay(void) {
|
||||
sendCommand(NORMALDISPLAY);
|
||||
}
|
||||
|
||||
void OLEDDisplay::setContrast(char contrast, char precharge, char comdetect) {
|
||||
sendCommand(SETPRECHARGE); //0xD9
|
||||
sendCommand(precharge); //0xF1 default, to lower the contrast, put 1-1F
|
||||
sendCommand(SETCONTRAST);
|
||||
sendCommand(contrast); // 0-255
|
||||
sendCommand(SETVCOMDETECT); //0xDB, (additionally needed to lower the contrast)
|
||||
sendCommand(comdetect); //0x40 default, to lower the contrast, put 0
|
||||
sendCommand(DISPLAYALLON_RESUME);
|
||||
sendCommand(NORMALDISPLAY);
|
||||
sendCommand(DISPLAYON);
|
||||
}
|
||||
|
||||
void OLEDDisplay::flipScreenVertically() {
|
||||
sendCommand(SEGREMAP | 0x01);
|
||||
sendCommand(COMSCANDEC); //Rotate screen 180 Deg
|
||||
}
|
||||
|
||||
void OLEDDisplay::clear(void) {
|
||||
memset(buffer, 0, DISPLAY_BUFFER_SIZE);
|
||||
}
|
||||
|
||||
void OLEDDisplay::drawLogBuffer(uint16_t xMove, uint16_t yMove) {
|
||||
uint16_t lineHeight = pgm_read_byte(fontData + HEIGHT_POS);
|
||||
// Always align left
|
||||
setTextAlignment(TEXT_ALIGN_LEFT);
|
||||
|
||||
// State values
|
||||
uint16_t length = 0;
|
||||
uint16_t line = 0;
|
||||
uint16_t lastPos = 0;
|
||||
|
||||
for (uint16_t i=0;i<this->logBufferFilled;i++){
|
||||
// Everytime we have a \n print
|
||||
if (this->logBuffer[i] == 10) {
|
||||
length++;
|
||||
// Draw string on line `line` from lastPos to length
|
||||
// Passing 0 as the lenght because we are in TEXT_ALIGN_LEFT
|
||||
drawStringInternal(xMove, yMove + (line++) * lineHeight, &this->logBuffer[lastPos], length, 0);
|
||||
// Remember last pos
|
||||
lastPos = i;
|
||||
// Reset length
|
||||
length = 0;
|
||||
} else {
|
||||
// Count chars until next linebreak
|
||||
length++;
|
||||
}
|
||||
}
|
||||
// Draw the remaining string
|
||||
if (length > 0) {
|
||||
drawStringInternal(xMove, yMove + line * lineHeight, &this->logBuffer[lastPos], length, 0);
|
||||
}
|
||||
}
|
||||
|
||||
bool OLEDDisplay::setLogBuffer(uint16_t lines, uint16_t chars){
|
||||
if (logBuffer != NULL) free(logBuffer);
|
||||
uint16_t size = lines * chars;
|
||||
if (size > 0) {
|
||||
this->logBufferLine = 0; // Lines printed
|
||||
this->logBufferFilled = 0; // Nothing stored yet
|
||||
this->logBufferMaxLines = lines; // Lines max printable
|
||||
this->logBufferSize = size; // Total number of characters the buffer can hold
|
||||
this->logBuffer = (char *) malloc(size * sizeof(uint8_t));
|
||||
if(!this->logBuffer) {
|
||||
DEBUG_OLEDDISPLAY("[OLEDDISPLAY][setLogBuffer] Not enough memory to create log buffer\n");
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
size_t OLEDDisplay::write(uint8_t c) {
|
||||
if (this->logBufferSize > 0) {
|
||||
// Don't waste space on \r\n line endings, dropping \r
|
||||
if (c == 13) return 1;
|
||||
|
||||
bool maxLineNotReached = this->logBufferLine < this->logBufferMaxLines;
|
||||
bool bufferNotFull = this->logBufferFilled < this->logBufferSize;
|
||||
|
||||
// Can we write to the buffer?
|
||||
if (bufferNotFull && maxLineNotReached) {
|
||||
this->logBuffer[logBufferFilled] = utf8ascii(c);
|
||||
this->logBufferFilled++;
|
||||
// Keep track of lines written
|
||||
if (c == 10) this->logBufferLine++;
|
||||
} else {
|
||||
// Max line number is reached
|
||||
if (!maxLineNotReached) this->logBufferLine--;
|
||||
|
||||
// Find the end of the first line
|
||||
uint16_t firstLineEnd = 0;
|
||||
for (uint16_t i=0;i<this->logBufferFilled;i++) {
|
||||
if (this->logBuffer[i] == 10){
|
||||
// Include last char too
|
||||
firstLineEnd = i + 1;
|
||||
break;
|
||||
}
|
||||
}
|
||||
// If there was a line ending
|
||||
if (firstLineEnd > 0) {
|
||||
// Calculate the new logBufferFilled value
|
||||
this->logBufferFilled = logBufferFilled - firstLineEnd;
|
||||
// Now we move the lines infront of the buffer
|
||||
memcpy(this->logBuffer, &this->logBuffer[firstLineEnd], logBufferFilled);
|
||||
} else {
|
||||
// Let's reuse the buffer if it was full
|
||||
if (!bufferNotFull) {
|
||||
this->logBufferFilled = 0;
|
||||
}// else {
|
||||
// Nothing to do here
|
||||
//}
|
||||
}
|
||||
write(c);
|
||||
}
|
||||
}
|
||||
// We are always writing all uint8_t to the buffer
|
||||
return 1;
|
||||
}
|
||||
|
||||
size_t OLEDDisplay::write(const char* str) {
|
||||
if (str == NULL) return 0;
|
||||
size_t length = strlen(str);
|
||||
for (size_t i = 0; i < length; i++) {
|
||||
write(str[i]);
|
||||
}
|
||||
return length;
|
||||
}
|
||||
|
||||
// Private functions
|
||||
void OLEDDisplay::sendInitCommands(void) {
|
||||
sendCommand(DISPLAYOFF);
|
||||
sendCommand(SETDISPLAYCLOCKDIV);
|
||||
sendCommand(0xF0); // Increase speed of the display max ~96Hz
|
||||
sendCommand(SETMULTIPLEX);
|
||||
sendCommand(this->height() - 1);
|
||||
sendCommand(SETDISPLAYOFFSET);
|
||||
sendCommand(0x00);
|
||||
sendCommand(SETSTARTLINE);
|
||||
sendCommand(CHARGEPUMP);
|
||||
sendCommand(0x14);
|
||||
sendCommand(MEMORYMODE);
|
||||
sendCommand(0x00);
|
||||
sendCommand(SEGREMAP);
|
||||
sendCommand(COMSCANINC);
|
||||
sendCommand(SETCOMPINS);
|
||||
sendCommand(0x12); // according to the adafruit lib, sometimes this may need to be 0x02
|
||||
sendCommand(SETCONTRAST);
|
||||
sendCommand(0xCF);
|
||||
sendCommand(SETPRECHARGE);
|
||||
sendCommand(0xF1);
|
||||
sendCommand(SETVCOMDETECT); //0xDB, (additionally needed to lower the contrast)
|
||||
sendCommand(0x40); //0x40 default, to lower the contrast, put 0
|
||||
sendCommand(DISPLAYALLON_RESUME);
|
||||
sendCommand(NORMALDISPLAY);
|
||||
sendCommand(0x2e); // stop scroll
|
||||
sendCommand(DISPLAYON);
|
||||
}
|
||||
|
||||
void inline OLEDDisplay::drawInternal(int16_t xMove, int16_t yMove, int16_t width, int16_t height, const char *data, uint16_t offset, uint16_t bytesInData) {
|
||||
if (width < 0 || height < 0) return;
|
||||
if (yMove + height < 0 || yMove > this->height()) return;
|
||||
if (xMove + width < 0 || xMove > this->width()) return;
|
||||
|
||||
uint8_t rasterHeight = 1 + ((height - 1) >> 3); // fast ceil(height / 8.0)
|
||||
int8_t yOffset = yMove & 7;
|
||||
|
||||
bytesInData = bytesInData == 0 ? width * rasterHeight : bytesInData;
|
||||
|
||||
int16_t initYMove = yMove;
|
||||
int8_t initYOffset = yOffset;
|
||||
|
||||
|
||||
for (uint16_t i = 0; i < bytesInData; i++) {
|
||||
|
||||
// Reset if next horizontal drawing phase is started.
|
||||
if ( i % rasterHeight == 0) {
|
||||
yMove = initYMove;
|
||||
yOffset = initYOffset;
|
||||
}
|
||||
|
||||
byte currentByte = pgm_read_byte(data + offset + i);
|
||||
|
||||
int16_t xPos = xMove + (i / rasterHeight);
|
||||
int16_t yPos = ((yMove >> 3) + (i % rasterHeight)) * this->width();
|
||||
|
||||
// int16_t yScreenPos = yMove + yOffset;
|
||||
int16_t dataPos = xPos + yPos;
|
||||
|
||||
if (dataPos >= 0 && dataPos < DISPLAY_BUFFER_SIZE &&
|
||||
xPos >= 0 && xPos < this->width() ) {
|
||||
|
||||
if (yOffset >= 0) {
|
||||
switch (this->color) {
|
||||
case WHITE: buffer[dataPos] |= currentByte << yOffset; break;
|
||||
case BLACK: buffer[dataPos] &= ~(currentByte << yOffset); break;
|
||||
case INVERSE: buffer[dataPos] ^= currentByte << yOffset; break;
|
||||
}
|
||||
if (dataPos < (DISPLAY_BUFFER_SIZE - this->width())) {
|
||||
switch (this->color) {
|
||||
case WHITE: buffer[dataPos + this->width()] |= currentByte >> (8 - yOffset); break;
|
||||
case BLACK: buffer[dataPos + this->width()] &= ~(currentByte >> (8 - yOffset)); break;
|
||||
case INVERSE: buffer[dataPos + this->width()] ^= currentByte >> (8 - yOffset); break;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
// Make new offset position
|
||||
yOffset = -yOffset;
|
||||
|
||||
switch (this->color) {
|
||||
case WHITE: buffer[dataPos] |= currentByte >> yOffset; break;
|
||||
case BLACK: buffer[dataPos] &= ~(currentByte >> yOffset); break;
|
||||
case INVERSE: buffer[dataPos] ^= currentByte >> yOffset; break;
|
||||
}
|
||||
|
||||
// Prepare for next iteration by moving one block up
|
||||
yMove -= 8;
|
||||
|
||||
// and setting the new yOffset
|
||||
yOffset = 8 - yOffset;
|
||||
}
|
||||
|
||||
yield();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Code form http://playground.arduino.cc/Main/Utf8ascii
|
||||
uint8_t OLEDDisplay::utf8ascii(byte ascii) {
|
||||
static uint8_t LASTCHAR;
|
||||
|
||||
if ( ascii < 128 ) { // Standard ASCII-set 0..0x7F handling
|
||||
LASTCHAR = 0;
|
||||
return ascii;
|
||||
}
|
||||
|
||||
uint8_t last = LASTCHAR; // get last char
|
||||
LASTCHAR = ascii;
|
||||
|
||||
switch (last) { // conversion depnding on first UTF8-character
|
||||
case 0xC2: return (ascii); break;
|
||||
case 0xC3: return (ascii | 0xC0); break;
|
||||
case 0x82: if (ascii == 0xAC) return (0x80); // special case Euro-symbol
|
||||
}
|
||||
|
||||
return 0; // otherwise: return zero, if character has to be ignored
|
||||
}
|
||||
|
||||
// You need to free the char!
|
||||
char* OLEDDisplay::utf8ascii(String str) {
|
||||
uint16_t k = 0;
|
||||
uint16_t length = str.length() + 1;
|
||||
|
||||
// Copy the string into a char array
|
||||
char* s = (char*) malloc(length * sizeof(char));
|
||||
if(!s) {
|
||||
DEBUG_OLEDDISPLAY("[OLEDDISPLAY][utf8ascii] Can't allocate another char array. Drop support for UTF-8.\n");
|
||||
return (char*) str.c_str();
|
||||
}
|
||||
str.toCharArray(s, length);
|
||||
|
||||
length--;
|
||||
|
||||
for (uint16_t i=0; i < length; i++) {
|
||||
char c = utf8ascii(s[i]);
|
||||
if (c!=0) {
|
||||
s[k++]=c;
|
||||
}
|
||||
}
|
||||
|
||||
s[k]=0;
|
||||
|
||||
// This will leak 's' be sure to free it in the calling function.
|
||||
return s;
|
||||
}
|
||||
@@ -0,0 +1,283 @@
|
||||
/**
|
||||
* The MIT License (MIT)
|
||||
*
|
||||
* Copyright (c) 2016 by Daniel Eichhorn
|
||||
* Copyright (c) 2016 by Fabrice Weinberg
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in all
|
||||
* copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
* SOFTWARE.
|
||||
*
|
||||
* Credits for parts of this code go to Mike Rankin. Thank you so much for sharing!
|
||||
*/
|
||||
|
||||
#ifndef OLEDDISPLAY_h
|
||||
#define OLEDDISPLAY_h
|
||||
|
||||
#include <Arduino.h>
|
||||
#include "OLEDDisplayFonts.h"
|
||||
|
||||
//#define DEBUG_OLEDDISPLAY(...) Serial.printf( __VA_ARGS__ )
|
||||
|
||||
#ifndef DEBUG_OLEDDISPLAY
|
||||
#define DEBUG_OLEDDISPLAY(...)
|
||||
#endif
|
||||
|
||||
// Use DOUBLE BUFFERING by default
|
||||
#ifndef OLEDDISPLAY_REDUCE_MEMORY
|
||||
#define OLEDDISPLAY_DOUBLE_BUFFER
|
||||
#endif
|
||||
|
||||
|
||||
// Display settings
|
||||
#ifndef DISPLAY_WIDTH
|
||||
#define DISPLAY_WIDTH 128
|
||||
#endif
|
||||
#ifndef DISPLAY_HEIGHT
|
||||
#define DISPLAY_HEIGHT 64
|
||||
#endif
|
||||
#define DISPLAY_BUFFER_SIZE DISPLAY_WIDTH * DISPLAY_HEIGHT / 8
|
||||
|
||||
// Header Values
|
||||
#define JUMPTABLE_BYTES 4
|
||||
|
||||
#define JUMPTABLE_LSB 1
|
||||
#define JUMPTABLE_SIZE 2
|
||||
#define JUMPTABLE_WIDTH 3
|
||||
#define JUMPTABLE_START 4
|
||||
|
||||
#define WIDTH_POS 0
|
||||
#define HEIGHT_POS 1
|
||||
#define FIRST_CHAR_POS 2
|
||||
#define CHAR_NUM_POS 3
|
||||
|
||||
|
||||
// Display commands
|
||||
#define CHARGEPUMP 0x8D
|
||||
#define COLUMNADDR 0x21
|
||||
#define COMSCANDEC 0xC8
|
||||
#define COMSCANINC 0xC0
|
||||
#define DISPLAYALLON 0xA5
|
||||
#define DISPLAYALLON_RESUME 0xA4
|
||||
#define DISPLAYOFF 0xAE
|
||||
#define DISPLAYON 0xAF
|
||||
#define EXTERNALVCC 0x1
|
||||
#define INVERTDISPLAY 0xA7
|
||||
#define MEMORYMODE 0x20
|
||||
#define NORMALDISPLAY 0xA6
|
||||
#define PAGEADDR 0x22
|
||||
#define SEGREMAP 0xA0
|
||||
#define SETCOMPINS 0xDA
|
||||
#define SETCONTRAST 0x81
|
||||
#define SETDISPLAYCLOCKDIV 0xD5
|
||||
#define SETDISPLAYOFFSET 0xD3
|
||||
#define SETHIGHCOLUMN 0x10
|
||||
#define SETLOWCOLUMN 0x00
|
||||
#define SETMULTIPLEX 0xA8
|
||||
#define SETPRECHARGE 0xD9
|
||||
#define SETSEGMENTREMAP 0xA1
|
||||
#define SETSTARTLINE 0x40
|
||||
#define SETVCOMDETECT 0xDB
|
||||
#define SWITCHCAPVCC 0x2
|
||||
|
||||
#ifndef _swap_int16_t
|
||||
#define _swap_int16_t(a, b) { int16_t t = a; a = b; b = t; }
|
||||
#endif
|
||||
|
||||
enum OLEDDISPLAY_COLOR {
|
||||
BLACK = 0,
|
||||
WHITE = 1,
|
||||
INVERSE = 2
|
||||
};
|
||||
|
||||
enum OLEDDISPLAY_TEXT_ALIGNMENT {
|
||||
TEXT_ALIGN_LEFT = 0,
|
||||
TEXT_ALIGN_RIGHT = 1,
|
||||
TEXT_ALIGN_CENTER = 2,
|
||||
TEXT_ALIGN_CENTER_BOTH = 3
|
||||
};
|
||||
|
||||
|
||||
class OLEDDisplay : public Print {
|
||||
private:
|
||||
const int _width, _height;
|
||||
|
||||
public:
|
||||
OLEDDisplay(const int width = DISPLAY_WIDTH, const int height = DISPLAY_HEIGHT) : _width(width), _height(height){ };
|
||||
virtual ~OLEDDisplay();
|
||||
|
||||
const int width(void) const { return _width; };
|
||||
const int height(void) const { return _height; };
|
||||
|
||||
// Initialize the display
|
||||
bool init();
|
||||
|
||||
// Free the memory used by the display
|
||||
void end();
|
||||
|
||||
// Cycle through the initialization
|
||||
void resetDisplay(void);
|
||||
|
||||
/* Drawing functions */
|
||||
// Sets the color of all pixel operations
|
||||
void setColor(OLEDDISPLAY_COLOR color);
|
||||
|
||||
// Draw a pixel at given position
|
||||
void setPixel(int16_t x, int16_t y);
|
||||
|
||||
// Draw a line from position 0 to position 1
|
||||
void drawLine(int16_t x0, int16_t y0, int16_t x1, int16_t y1);
|
||||
|
||||
// Draw the border of a rectangle at the given location
|
||||
void drawRect(int16_t x, int16_t y, int16_t width, int16_t height);
|
||||
|
||||
// Fill the rectangle
|
||||
void fillRect(int16_t x, int16_t y, int16_t width, int16_t height);
|
||||
|
||||
// Draw the border of a circle
|
||||
void drawCircle(int16_t x, int16_t y, int16_t radius);
|
||||
|
||||
// Draw all Quadrants specified in the quads bit mask
|
||||
void drawCircleQuads(int16_t x0, int16_t y0, int16_t radius, uint8_t quads);
|
||||
|
||||
// Fill circle
|
||||
void fillCircle(int16_t x, int16_t y, int16_t radius);
|
||||
|
||||
// Draw a line horizontally
|
||||
void drawHorizontalLine(int16_t x, int16_t y, int16_t length);
|
||||
|
||||
// Draw a lin vertically
|
||||
void drawVerticalLine(int16_t x, int16_t y, int16_t length);
|
||||
|
||||
// Draws a rounded progress bar with the outer dimensions given by width and height. Progress is
|
||||
// a unsigned byte value between 0 and 100
|
||||
void drawProgressBar(uint16_t x, uint16_t y, uint16_t width, uint16_t height, uint8_t progress);
|
||||
|
||||
// Draw a bitmap in the internal image format
|
||||
void drawFastImage(int16_t x, int16_t y, int16_t width, int16_t height, const char *image);
|
||||
|
||||
// Draw a XBM
|
||||
void drawXbm(int16_t x, int16_t y, int16_t width, int16_t height, const char *xbm);
|
||||
|
||||
/* Text functions */
|
||||
|
||||
// Draws a string at the given location
|
||||
void drawString(int16_t x, int16_t y, String text);
|
||||
|
||||
// Draws a String with a maximum width at the given location.
|
||||
// If the given String is wider than the specified width
|
||||
// The text will be wrapped to the next line at a space or dash
|
||||
void drawStringMaxWidth(int16_t x, int16_t y, uint16_t maxLineWidth, String text);
|
||||
|
||||
// Returns the width of the const char* with the current
|
||||
// font settings
|
||||
uint16_t getStringWidth(const char* text, uint16_t length);
|
||||
|
||||
// Convencience method for the const char version
|
||||
uint16_t getStringWidth(String text);
|
||||
|
||||
// Specifies relative to which anchor point
|
||||
// the text is rendered. Available constants:
|
||||
// TEXT_ALIGN_LEFT, TEXT_ALIGN_CENTER, TEXT_ALIGN_RIGHT, TEXT_ALIGN_CENTER_BOTH
|
||||
void setTextAlignment(OLEDDISPLAY_TEXT_ALIGNMENT textAlignment);
|
||||
|
||||
// Sets the current font. Available default fonts
|
||||
// ArialMT_Plain_10, ArialMT_Plain_16, ArialMT_Plain_24
|
||||
void setFont(const char *fontData);
|
||||
|
||||
/* Display functions */
|
||||
|
||||
// Turn the display on
|
||||
void displayOn(void);
|
||||
|
||||
// Turn the display offs
|
||||
void displayOff(void);
|
||||
|
||||
// Inverted display mode
|
||||
void invertDisplay(void);
|
||||
|
||||
// Normal display mode
|
||||
void normalDisplay(void);
|
||||
|
||||
// Set display contrast
|
||||
// really low brightness & contrast: contrast = 10, precharge = 5, comdetect = 0
|
||||
// normal brightness & contrast: contrast = 100
|
||||
void setContrast(char contrast, char precharge = 241, char comdetect = 64);
|
||||
|
||||
// Turn the display upside down
|
||||
void flipScreenVertically();
|
||||
|
||||
// Write the buffer to the display memory
|
||||
virtual void display(void) = 0;
|
||||
|
||||
// Clear the local pixel buffer
|
||||
void clear(void);
|
||||
|
||||
// Log buffer implementation
|
||||
|
||||
// This will define the lines and characters you can
|
||||
// print to the screen. When you exeed the buffer size (lines * chars)
|
||||
// the output may be truncated due to the size constraint.
|
||||
bool setLogBuffer(uint16_t lines, uint16_t chars);
|
||||
|
||||
// Draw the log buffer at position (x, y)
|
||||
void drawLogBuffer(uint16_t x, uint16_t y);
|
||||
|
||||
// Implementent needed function to be compatible with Print class
|
||||
size_t write(uint8_t c);
|
||||
size_t write(const char* s);
|
||||
|
||||
uint8_t *buffer = NULL;
|
||||
|
||||
#ifdef OLEDDISPLAY_DOUBLE_BUFFER
|
||||
uint8_t *buffer_back = NULL;
|
||||
#endif
|
||||
|
||||
protected:
|
||||
|
||||
OLEDDISPLAY_TEXT_ALIGNMENT textAlignment = TEXT_ALIGN_LEFT;
|
||||
OLEDDISPLAY_COLOR color = WHITE;
|
||||
|
||||
const char *fontData = ArialMT_Plain_10;
|
||||
|
||||
// State values for logBuffer
|
||||
uint16_t logBufferSize = 0;
|
||||
uint16_t logBufferFilled = 0;
|
||||
uint16_t logBufferLine = 0;
|
||||
uint16_t logBufferMaxLines = 0;
|
||||
char *logBuffer = NULL;
|
||||
|
||||
// Send a command to the display (low level function)
|
||||
virtual void sendCommand(uint8_t com) {(void)com;};
|
||||
|
||||
// Connect to the display
|
||||
virtual bool connect() { return false; };
|
||||
|
||||
// Send all the init commands
|
||||
void sendInitCommands();
|
||||
|
||||
// converts utf8 characters to extended ascii
|
||||
static char* utf8ascii(String s);
|
||||
static byte utf8ascii(byte ascii);
|
||||
|
||||
void inline drawInternal(int16_t xMove, int16_t yMove, int16_t width, int16_t height, const char *data, uint16_t offset, uint16_t bytesInData) __attribute__((always_inline));
|
||||
|
||||
void drawStringInternal(int16_t xMove, int16_t yMove, char* text, uint16_t textLength, uint16_t textWidth);
|
||||
|
||||
};
|
||||
|
||||
#endif
|
||||
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,406 @@
|
||||
/**
|
||||
* The MIT License (MIT)
|
||||
*
|
||||
* Copyright (c) 2016 by Daniel Eichhorn
|
||||
* Copyright (c) 2016 by Fabrice Weinberg
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in all
|
||||
* copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
* SOFTWARE.
|
||||
*
|
||||
*/
|
||||
|
||||
#include "OLEDDisplayUi.h"
|
||||
|
||||
OLEDDisplayUi::OLEDDisplayUi(OLEDDisplay *display) {
|
||||
this->display = display;
|
||||
}
|
||||
|
||||
void OLEDDisplayUi::init() {
|
||||
this->display->init();
|
||||
}
|
||||
|
||||
void OLEDDisplayUi::setTargetFPS(uint8_t fps){
|
||||
float oldInterval = this->updateInterval;
|
||||
this->updateInterval = ((float) 1.0 / (float) fps) * 1000;
|
||||
|
||||
// Calculate new ticksPerFrame
|
||||
float changeRatio = oldInterval / (float) this->updateInterval;
|
||||
this->ticksPerFrame *= changeRatio;
|
||||
this->ticksPerTransition *= changeRatio;
|
||||
}
|
||||
|
||||
// -/------ Automatic controll ------\-
|
||||
|
||||
void OLEDDisplayUi::enableAutoTransition(){
|
||||
this->autoTransition = true;
|
||||
}
|
||||
void OLEDDisplayUi::disableAutoTransition(){
|
||||
this->autoTransition = false;
|
||||
}
|
||||
void OLEDDisplayUi::setAutoTransitionForwards(){
|
||||
this->state.frameTransitionDirection = 1;
|
||||
this->lastTransitionDirection = 1;
|
||||
}
|
||||
void OLEDDisplayUi::setAutoTransitionBackwards(){
|
||||
this->state.frameTransitionDirection = -1;
|
||||
this->lastTransitionDirection = -1;
|
||||
}
|
||||
void OLEDDisplayUi::setTimePerFrame(uint16_t time){
|
||||
this->ticksPerFrame = (int) ( (float) time / (float) updateInterval);
|
||||
}
|
||||
void OLEDDisplayUi::setTimePerTransition(uint16_t time){
|
||||
this->ticksPerTransition = (int) ( (float) time / (float) updateInterval);
|
||||
}
|
||||
|
||||
// -/------ Customize indicator position and style -------\-
|
||||
void OLEDDisplayUi::enableIndicator(){
|
||||
this->state.isIndicatorDrawen = true;
|
||||
}
|
||||
|
||||
void OLEDDisplayUi::disableIndicator(){
|
||||
this->state.isIndicatorDrawen = false;
|
||||
}
|
||||
|
||||
void OLEDDisplayUi::enableAllIndicators(){
|
||||
this->shouldDrawIndicators = true;
|
||||
}
|
||||
|
||||
void OLEDDisplayUi::disableAllIndicators(){
|
||||
this->shouldDrawIndicators = false;
|
||||
}
|
||||
|
||||
void OLEDDisplayUi::setIndicatorPosition(IndicatorPosition pos) {
|
||||
this->indicatorPosition = pos;
|
||||
}
|
||||
void OLEDDisplayUi::setIndicatorDirection(IndicatorDirection dir) {
|
||||
this->indicatorDirection = dir;
|
||||
}
|
||||
void OLEDDisplayUi::setActiveSymbol(const char* symbol) {
|
||||
this->activeSymbol = symbol;
|
||||
}
|
||||
void OLEDDisplayUi::setInactiveSymbol(const char* symbol) {
|
||||
this->inactiveSymbol = symbol;
|
||||
}
|
||||
|
||||
|
||||
// -/----- Frame settings -----\-
|
||||
void OLEDDisplayUi::setFrameAnimation(AnimationDirection dir) {
|
||||
this->frameAnimationDirection = dir;
|
||||
}
|
||||
void OLEDDisplayUi::setFrames(FrameCallback* frameFunctions, uint8_t frameCount) {
|
||||
this->frameFunctions = frameFunctions;
|
||||
this->frameCount = frameCount;
|
||||
this->resetState();
|
||||
}
|
||||
|
||||
// -/----- Overlays ------\-
|
||||
void OLEDDisplayUi::setOverlays(OverlayCallback* overlayFunctions, uint8_t overlayCount){
|
||||
this->overlayFunctions = overlayFunctions;
|
||||
this->overlayCount = overlayCount;
|
||||
}
|
||||
|
||||
// -/----- Loading Process -----\-
|
||||
|
||||
void OLEDDisplayUi::setLoadingDrawFunction(LoadingDrawFunction loadingDrawFunction) {
|
||||
this->loadingDrawFunction = loadingDrawFunction;
|
||||
}
|
||||
|
||||
void OLEDDisplayUi::runLoadingProcess(LoadingStage* stages, uint8_t stagesCount) {
|
||||
uint8_t progress = 0;
|
||||
uint8_t increment = 100 / stagesCount;
|
||||
|
||||
for (uint8_t i = 0; i < stagesCount; i++) {
|
||||
display->clear();
|
||||
this->loadingDrawFunction(this->display, &stages[i], progress);
|
||||
display->display();
|
||||
|
||||
stages[i].callback();
|
||||
|
||||
progress += increment;
|
||||
yield();
|
||||
}
|
||||
|
||||
display->clear();
|
||||
this->loadingDrawFunction(this->display, &stages[stagesCount-1], progress);
|
||||
display->display();
|
||||
|
||||
delay(150);
|
||||
}
|
||||
|
||||
// -/----- Manuel control -----\-
|
||||
void OLEDDisplayUi::nextFrame() {
|
||||
if (this->state.frameState != IN_TRANSITION) {
|
||||
this->state.manuelControll = true;
|
||||
this->state.frameState = IN_TRANSITION;
|
||||
this->state.ticksSinceLastStateSwitch = 0;
|
||||
this->lastTransitionDirection = this->state.frameTransitionDirection;
|
||||
this->state.frameTransitionDirection = 1;
|
||||
}
|
||||
}
|
||||
void OLEDDisplayUi::previousFrame() {
|
||||
if (this->state.frameState != IN_TRANSITION) {
|
||||
this->state.manuelControll = true;
|
||||
this->state.frameState = IN_TRANSITION;
|
||||
this->state.ticksSinceLastStateSwitch = 0;
|
||||
this->lastTransitionDirection = this->state.frameTransitionDirection;
|
||||
this->state.frameTransitionDirection = -1;
|
||||
}
|
||||
}
|
||||
|
||||
void OLEDDisplayUi::switchToFrame(uint8_t frame) {
|
||||
if (frame >= this->frameCount) return;
|
||||
this->state.ticksSinceLastStateSwitch = 0;
|
||||
if (frame == this->state.currentFrame) return;
|
||||
this->state.frameState = FIXED;
|
||||
this->state.currentFrame = frame;
|
||||
this->state.isIndicatorDrawen = true;
|
||||
}
|
||||
|
||||
void OLEDDisplayUi::transitionToFrame(uint8_t frame) {
|
||||
if (frame >= this->frameCount) return;
|
||||
this->state.ticksSinceLastStateSwitch = 0;
|
||||
if (frame == this->state.currentFrame) return;
|
||||
this->nextFrameNumber = frame;
|
||||
this->lastTransitionDirection = this->state.frameTransitionDirection;
|
||||
this->state.manuelControll = true;
|
||||
this->state.frameState = IN_TRANSITION;
|
||||
this->state.frameTransitionDirection = frame < this->state.currentFrame ? -1 : 1;
|
||||
}
|
||||
|
||||
|
||||
// -/----- State information -----\-
|
||||
OLEDDisplayUiState* OLEDDisplayUi::getUiState(){
|
||||
return &this->state;
|
||||
}
|
||||
|
||||
|
||||
int8_t OLEDDisplayUi::update(){
|
||||
long frameStart = millis();
|
||||
int8_t timeBudget = this->updateInterval - (frameStart - this->state.lastUpdate);
|
||||
if ( timeBudget <= 0) {
|
||||
// Implement frame skipping to ensure time budget is keept
|
||||
if (this->autoTransition && this->state.lastUpdate != 0) this->state.ticksSinceLastStateSwitch += ceil(-timeBudget / this->updateInterval);
|
||||
|
||||
this->state.lastUpdate = frameStart;
|
||||
this->tick();
|
||||
}
|
||||
return this->updateInterval - (millis() - frameStart);
|
||||
}
|
||||
|
||||
|
||||
void OLEDDisplayUi::tick() {
|
||||
this->state.ticksSinceLastStateSwitch++;
|
||||
|
||||
switch (this->state.frameState) {
|
||||
case IN_TRANSITION:
|
||||
if (this->state.ticksSinceLastStateSwitch >= this->ticksPerTransition){
|
||||
this->state.frameState = FIXED;
|
||||
this->state.currentFrame = getNextFrameNumber();
|
||||
this->state.ticksSinceLastStateSwitch = 0;
|
||||
this->nextFrameNumber = -1;
|
||||
}
|
||||
break;
|
||||
case FIXED:
|
||||
// Revert manuelControll
|
||||
if (this->state.manuelControll) {
|
||||
this->state.frameTransitionDirection = this->lastTransitionDirection;
|
||||
this->state.manuelControll = false;
|
||||
}
|
||||
if (this->state.ticksSinceLastStateSwitch >= this->ticksPerFrame){
|
||||
if (this->autoTransition){
|
||||
this->state.frameState = IN_TRANSITION;
|
||||
}
|
||||
this->state.ticksSinceLastStateSwitch = 0;
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
this->display->clear();
|
||||
this->drawFrame();
|
||||
if (shouldDrawIndicators) {
|
||||
this->drawIndicator();
|
||||
}
|
||||
this->drawOverlays();
|
||||
this->display->display();
|
||||
}
|
||||
|
||||
void OLEDDisplayUi::resetState() {
|
||||
this->state.lastUpdate = 0;
|
||||
this->state.ticksSinceLastStateSwitch = 0;
|
||||
this->state.frameState = FIXED;
|
||||
this->state.currentFrame = 0;
|
||||
this->state.isIndicatorDrawen = true;
|
||||
}
|
||||
|
||||
void OLEDDisplayUi::drawFrame(){
|
||||
switch (this->state.frameState){
|
||||
case IN_TRANSITION: {
|
||||
float progress = (float) this->state.ticksSinceLastStateSwitch / (float) this->ticksPerTransition;
|
||||
int16_t x = 0, y = 0, x1 = 0, y1 = 0;
|
||||
switch(this->frameAnimationDirection){
|
||||
case SLIDE_LEFT:
|
||||
x = -this->display->width() * progress;
|
||||
y = 0;
|
||||
x1 = x + this->display->width();
|
||||
y1 = 0;
|
||||
break;
|
||||
case SLIDE_RIGHT:
|
||||
x = this->display->width() * progress;
|
||||
y = 0;
|
||||
x1 = x - this->display->width();
|
||||
y1 = 0;
|
||||
break;
|
||||
case SLIDE_UP:
|
||||
x = 0;
|
||||
y = -this->display->height() * progress;
|
||||
x1 = 0;
|
||||
y1 = y + this->display->height();
|
||||
break;
|
||||
case SLIDE_DOWN:
|
||||
x = 0;
|
||||
y = this->display->height() * progress;
|
||||
x1 = 0;
|
||||
y1 = y - this->display->height();
|
||||
break;
|
||||
}
|
||||
|
||||
// Invert animation if direction is reversed.
|
||||
int8_t dir = this->state.frameTransitionDirection >= 0 ? 1 : -1;
|
||||
x *= dir; y *= dir; x1 *= dir; y1 *= dir;
|
||||
|
||||
bool drawenCurrentFrame;
|
||||
|
||||
|
||||
// Prope each frameFunction for the indicator Drawen state
|
||||
this->enableIndicator();
|
||||
(this->frameFunctions[this->state.currentFrame])(this->display, &this->state, x, y);
|
||||
drawenCurrentFrame = this->state.isIndicatorDrawen;
|
||||
|
||||
this->enableIndicator();
|
||||
(this->frameFunctions[this->getNextFrameNumber()])(this->display, &this->state, x1, y1);
|
||||
|
||||
// Build up the indicatorDrawState
|
||||
if (drawenCurrentFrame && !this->state.isIndicatorDrawen) {
|
||||
// Drawen now but not next
|
||||
this->indicatorDrawState = 2;
|
||||
} else if (!drawenCurrentFrame && this->state.isIndicatorDrawen) {
|
||||
// Not drawen now but next
|
||||
this->indicatorDrawState = 1;
|
||||
} else if (!drawenCurrentFrame && !this->state.isIndicatorDrawen) {
|
||||
// Not drawen in both frames
|
||||
this->indicatorDrawState = 3;
|
||||
}
|
||||
|
||||
// If the indicator isn't draw in the current frame
|
||||
// reflect it in state.isIndicatorDrawen
|
||||
if (!drawenCurrentFrame) this->state.isIndicatorDrawen = false;
|
||||
|
||||
break;
|
||||
}
|
||||
case FIXED:
|
||||
// Always assume that the indicator is drawn!
|
||||
// And set indicatorDrawState to "not known yet"
|
||||
this->indicatorDrawState = 0;
|
||||
this->enableIndicator();
|
||||
(this->frameFunctions[this->state.currentFrame])(this->display, &this->state, 0, 0);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
void OLEDDisplayUi::drawIndicator() {
|
||||
|
||||
// Only draw if the indicator is invisible
|
||||
// for both frames or
|
||||
// the indiactor is shown and we are IN_TRANSITION
|
||||
if (this->indicatorDrawState == 3 || (!this->state.isIndicatorDrawen && this->state.frameState != IN_TRANSITION)) {
|
||||
return;
|
||||
}
|
||||
|
||||
uint8_t posOfHighlightFrame = 0;
|
||||
float indicatorFadeProgress = 0;
|
||||
|
||||
// if the indicator needs to be slided in we want to
|
||||
// highlight the next frame in the transition
|
||||
uint8_t frameToHighlight = this->indicatorDrawState == 1 ? this->getNextFrameNumber() : this->state.currentFrame;
|
||||
|
||||
// Calculate the frame that needs to be highlighted
|
||||
// based on the Direction the indiactor is drawn
|
||||
switch (this->indicatorDirection){
|
||||
case LEFT_RIGHT:
|
||||
posOfHighlightFrame = frameToHighlight;
|
||||
break;
|
||||
case RIGHT_LEFT:
|
||||
posOfHighlightFrame = this->frameCount - frameToHighlight;
|
||||
break;
|
||||
}
|
||||
|
||||
switch (this->indicatorDrawState) {
|
||||
case 1: // Indicator was not drawn in this frame but will be in next
|
||||
// Slide IN
|
||||
indicatorFadeProgress = 1 - ((float) this->state.ticksSinceLastStateSwitch / (float) this->ticksPerTransition);
|
||||
break;
|
||||
case 2: // Indicator was drawn in this frame but not in next
|
||||
// Slide OUT
|
||||
indicatorFadeProgress = ((float) this->state.ticksSinceLastStateSwitch / (float) this->ticksPerTransition);
|
||||
break;
|
||||
}
|
||||
|
||||
uint16_t frameStartPos = (12 * frameCount / 2);
|
||||
const char *image;
|
||||
uint16_t x = 0, y = 0;
|
||||
for (byte i = 0; i < this->frameCount; i++) {
|
||||
|
||||
switch (this->indicatorPosition){
|
||||
case TOP:
|
||||
y = 0 - (8 * indicatorFadeProgress);
|
||||
x = (this->display->width() / 2) - frameStartPos + 12 * i;
|
||||
break;
|
||||
case BOTTOM:
|
||||
y = (this->display->height() - 8) + (8 * indicatorFadeProgress);
|
||||
x = (this->display->width() / 2) - frameStartPos + 12 * i;
|
||||
break;
|
||||
case RIGHT:
|
||||
x = (this->display->width() - 8) + (8 * indicatorFadeProgress);
|
||||
y = (this->display->height() / 2) - frameStartPos + 2 + 12 * i;
|
||||
break;
|
||||
case LEFT:
|
||||
x = 0 - (8 * indicatorFadeProgress);
|
||||
y = (this->display->height() / 2) - frameStartPos + 2 + 12 * i;
|
||||
break;
|
||||
}
|
||||
|
||||
if (posOfHighlightFrame == i) {
|
||||
image = this->activeSymbol;
|
||||
} else {
|
||||
image = this->inactiveSymbol;
|
||||
}
|
||||
|
||||
this->display->drawFastImage(x, y, 8, 8, image);
|
||||
}
|
||||
}
|
||||
|
||||
void OLEDDisplayUi::drawOverlays() {
|
||||
for (uint8_t i=0;i<this->overlayCount;i++){
|
||||
(this->overlayFunctions[i])(this->display, &this->state);
|
||||
}
|
||||
}
|
||||
|
||||
uint8_t OLEDDisplayUi::getNextFrameNumber(){
|
||||
if (this->nextFrameNumber != -1) return this->nextFrameNumber;
|
||||
return (this->state.currentFrame + this->frameCount + this->state.frameTransitionDirection) % this->frameCount;
|
||||
}
|
||||
@@ -0,0 +1,305 @@
|
||||
/**
|
||||
* The MIT License (MIT)
|
||||
*
|
||||
* Copyright (c) 2016 by Daniel Eichhorn
|
||||
* Copyright (c) 2016 by Fabrice Weinberg
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in all
|
||||
* copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
* SOFTWARE.
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef OLEDDISPLAYUI_h
|
||||
#define OLEDDISPLAYUI_h
|
||||
|
||||
#include <Arduino.h>
|
||||
#include "OLEDDisplay.h"
|
||||
|
||||
//#define DEBUG_OLEDDISPLAYUI(...) Serial.printf( __VA_ARGS__ )
|
||||
|
||||
#ifndef DEBUG_OLEDDISPLAYUI
|
||||
#define DEBUG_OLEDDISPLAYUI(...)
|
||||
#endif
|
||||
|
||||
enum AnimationDirection {
|
||||
SLIDE_UP,
|
||||
SLIDE_DOWN,
|
||||
SLIDE_LEFT,
|
||||
SLIDE_RIGHT
|
||||
};
|
||||
|
||||
enum IndicatorPosition {
|
||||
TOP,
|
||||
RIGHT,
|
||||
BOTTOM,
|
||||
LEFT
|
||||
};
|
||||
|
||||
enum IndicatorDirection {
|
||||
LEFT_RIGHT,
|
||||
RIGHT_LEFT
|
||||
};
|
||||
|
||||
enum FrameState {
|
||||
IN_TRANSITION,
|
||||
FIXED
|
||||
};
|
||||
|
||||
|
||||
const char ANIMATION_activeSymbol[] PROGMEM = {
|
||||
0x00, 0x18, 0x3c, 0x7e, 0x7e, 0x3c, 0x18, 0x00
|
||||
};
|
||||
|
||||
const char ANIMATION_inactiveSymbol[] PROGMEM = {
|
||||
0x00, 0x0, 0x0, 0x18, 0x18, 0x0, 0x0, 0x00
|
||||
};
|
||||
|
||||
|
||||
// Structure of the UiState
|
||||
struct OLEDDisplayUiState {
|
||||
uint64_t lastUpdate = 0;
|
||||
uint16_t ticksSinceLastStateSwitch = 0;
|
||||
|
||||
FrameState frameState = FIXED;
|
||||
uint8_t currentFrame = 0;
|
||||
|
||||
bool isIndicatorDrawen = true;
|
||||
|
||||
// Normal = 1, Inverse = -1;
|
||||
int8_t frameTransitionDirection = 1;
|
||||
|
||||
bool manuelControll = false;
|
||||
|
||||
// Custom data that can be used by the user
|
||||
void* userData = NULL;
|
||||
};
|
||||
|
||||
struct LoadingStage {
|
||||
const char* process;
|
||||
void (*callback)();
|
||||
};
|
||||
|
||||
typedef void (*FrameCallback)(OLEDDisplay *display, OLEDDisplayUiState* state, int16_t x, int16_t y);
|
||||
typedef void (*OverlayCallback)(OLEDDisplay *display, OLEDDisplayUiState* state);
|
||||
typedef void (*LoadingDrawFunction)(OLEDDisplay *display, LoadingStage* stage, uint8_t progress);
|
||||
|
||||
class OLEDDisplayUi {
|
||||
private:
|
||||
OLEDDisplay *display;
|
||||
|
||||
// Symbols for the Indicator
|
||||
IndicatorPosition indicatorPosition = BOTTOM;
|
||||
IndicatorDirection indicatorDirection = LEFT_RIGHT;
|
||||
|
||||
const char* activeSymbol = ANIMATION_activeSymbol;
|
||||
const char* inactiveSymbol = ANIMATION_inactiveSymbol;
|
||||
|
||||
bool shouldDrawIndicators = true;
|
||||
|
||||
// Values for the Frames
|
||||
AnimationDirection frameAnimationDirection = SLIDE_RIGHT;
|
||||
|
||||
int8_t lastTransitionDirection = 1;
|
||||
|
||||
uint16_t ticksPerFrame = 151; // ~ 5000ms at 30 FPS
|
||||
uint16_t ticksPerTransition = 15; // ~ 500ms at 30 FPS
|
||||
|
||||
bool autoTransition = true;
|
||||
|
||||
FrameCallback* frameFunctions;
|
||||
uint8_t frameCount = 0;
|
||||
|
||||
// Internally used to transition to a specific frame
|
||||
int8_t nextFrameNumber = -1;
|
||||
|
||||
// Values for Overlays
|
||||
OverlayCallback* overlayFunctions;
|
||||
uint8_t overlayCount = 0;
|
||||
|
||||
// Will the Indicator be drawen
|
||||
// 3 Not drawn in both frames
|
||||
// 2 Drawn this frame but not next
|
||||
// 1 Not drown this frame but next
|
||||
// 0 Not known yet
|
||||
uint8_t indicatorDrawState = 1;
|
||||
|
||||
// Loading screen
|
||||
LoadingDrawFunction loadingDrawFunction = [](OLEDDisplay *display, LoadingStage* stage, uint8_t progress) {
|
||||
display->setTextAlignment(TEXT_ALIGN_CENTER);
|
||||
display->setFont(ArialMT_Plain_10);
|
||||
display->drawString(64, 18, stage->process);
|
||||
display->drawProgressBar(4, 32, 120, 8, progress);
|
||||
};
|
||||
|
||||
// UI State
|
||||
OLEDDisplayUiState state;
|
||||
|
||||
// Bookeeping for update
|
||||
uint8_t updateInterval = 33;
|
||||
|
||||
uint8_t getNextFrameNumber();
|
||||
void drawIndicator();
|
||||
void drawFrame();
|
||||
void drawOverlays();
|
||||
void tick();
|
||||
void resetState();
|
||||
|
||||
public:
|
||||
|
||||
OLEDDisplayUi(OLEDDisplay *display);
|
||||
|
||||
/**
|
||||
* Initialise the display
|
||||
*/
|
||||
void init();
|
||||
|
||||
/**
|
||||
* Configure the internal used target FPS
|
||||
*/
|
||||
void setTargetFPS(uint8_t fps);
|
||||
|
||||
// Automatic Controll
|
||||
/**
|
||||
* Enable automatic transition to next frame after the some time can be configured with `setTimePerFrame` and `setTimePerTransition`.
|
||||
*/
|
||||
void enableAutoTransition();
|
||||
|
||||
/**
|
||||
* Disable automatic transition to next frame.
|
||||
*/
|
||||
void disableAutoTransition();
|
||||
|
||||
/**
|
||||
* Set the direction if the automatic transitioning
|
||||
*/
|
||||
void setAutoTransitionForwards();
|
||||
void setAutoTransitionBackwards();
|
||||
|
||||
/**
|
||||
* Set the approx. time a frame is displayed
|
||||
*/
|
||||
void setTimePerFrame(uint16_t time);
|
||||
|
||||
/**
|
||||
* Set the approx. time a transition will take
|
||||
*/
|
||||
void setTimePerTransition(uint16_t time);
|
||||
|
||||
// Customize indicator position and style
|
||||
|
||||
/**
|
||||
* Draw the indicator.
|
||||
* This is the defaut state for all frames if
|
||||
* the indicator was hidden on the previous frame
|
||||
* it will be slided in.
|
||||
*/
|
||||
void enableIndicator();
|
||||
|
||||
/**
|
||||
* Don't draw the indicator.
|
||||
* This will slide out the indicator
|
||||
* when transitioning to the next frame.
|
||||
*/
|
||||
void disableIndicator();
|
||||
|
||||
/**
|
||||
* Enable drawing of indicators
|
||||
*/
|
||||
void enableAllIndicators();
|
||||
|
||||
/**
|
||||
* Disable draw of indicators.
|
||||
*/
|
||||
void disableAllIndicators();
|
||||
|
||||
/**
|
||||
* Set the position of the indicator bar.
|
||||
*/
|
||||
void setIndicatorPosition(IndicatorPosition pos);
|
||||
|
||||
/**
|
||||
* Set the direction of the indicator bar. Defining the order of frames ASCENDING / DESCENDING
|
||||
*/
|
||||
void setIndicatorDirection(IndicatorDirection dir);
|
||||
|
||||
/**
|
||||
* Set the symbol to indicate an active frame in the indicator bar.
|
||||
*/
|
||||
void setActiveSymbol(const char* symbol);
|
||||
|
||||
/**
|
||||
* Set the symbol to indicate an inactive frame in the indicator bar.
|
||||
*/
|
||||
void setInactiveSymbol(const char* symbol);
|
||||
|
||||
|
||||
// Frame settings
|
||||
|
||||
/**
|
||||
* Configure what animation is used to transition from one frame to another
|
||||
*/
|
||||
void setFrameAnimation(AnimationDirection dir);
|
||||
|
||||
/**
|
||||
* Add frame drawing functions
|
||||
*/
|
||||
void setFrames(FrameCallback* frameFunctions, uint8_t frameCount);
|
||||
|
||||
// Overlay
|
||||
|
||||
/**
|
||||
* Add overlays drawing functions that are draw independent of the Frames
|
||||
*/
|
||||
void setOverlays(OverlayCallback* overlayFunctions, uint8_t overlayCount);
|
||||
|
||||
|
||||
// Loading animation
|
||||
/**
|
||||
* Set the function that will draw each step
|
||||
* in the loading animation
|
||||
*/
|
||||
void setLoadingDrawFunction(LoadingDrawFunction loadingFunction);
|
||||
|
||||
|
||||
/**
|
||||
* Run the loading process
|
||||
*/
|
||||
void runLoadingProcess(LoadingStage* stages, uint8_t stagesCount);
|
||||
|
||||
|
||||
// Manual Control
|
||||
void nextFrame();
|
||||
void previousFrame();
|
||||
|
||||
/**
|
||||
* Switch without transition to frame `frame`.
|
||||
*/
|
||||
void switchToFrame(uint8_t frame);
|
||||
|
||||
/**
|
||||
* Transition to frame `frame`, when the `frame` number is bigger than the current
|
||||
* frame the forward animation will be used, otherwise the backwards animation is used.
|
||||
*/
|
||||
void transitionToFrame(uint8_t frame);
|
||||
|
||||
// State Info
|
||||
OLEDDisplayUiState* getUiState();
|
||||
|
||||
int8_t update();
|
||||
};
|
||||
#endif
|
||||
@@ -0,0 +1,45 @@
|
||||
#ifndef OLED_SSD1306_SH1106_IMAGES_H
|
||||
#define OLED_SSD1306_SH1106_IMAGES_H
|
||||
|
||||
#define espeasy_logo_width 36
|
||||
#define espeasy_logo_height 36
|
||||
const char espeasy_logo_bits[] PROGMEM= {
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x60, 0x40, 0xc0, 0x00, 0x00, 0x70, 0xf0, 0xe0,
|
||||
0x01, 0x00, 0x78, 0xf8, 0xf0, 0x01, 0x00, 0x3c, 0x7c, 0xf8, 0x00, 0x00,
|
||||
0x1e, 0x3e, 0x7c, 0x00, 0x00, 0x0f, 0x1f, 0x3e, 0x00, 0x80, 0x87, 0x0f,
|
||||
0x1f, 0x00, 0xc0, 0xc3, 0x87, 0x0f, 0x00, 0xe0, 0xe1, 0xc3, 0x07, 0x00,
|
||||
0xf0, 0xf0, 0xe1, 0xc3, 0x00, 0x78, 0xf8, 0xf0, 0xe1, 0x01, 0x30, 0x7c,
|
||||
0xf8, 0xf0, 0x00, 0x00, 0x3e, 0x7c, 0x78, 0x00, 0x00, 0x1f, 0x3e, 0x3c,
|
||||
0x00, 0x80, 0x0f, 0x1f, 0x1e, 0x00, 0xc0, 0x87, 0x0f, 0x0f, 0x00, 0xe0,
|
||||
0xc3, 0x87, 0x07, 0x00, 0xf0, 0xe1, 0xc3, 0x03, 0x00, 0xf0, 0xf0, 0xe1,
|
||||
0x01, 0x00, 0x78, 0xf8, 0xf0, 0x00, 0x00, 0x30, 0x7c, 0x78, 0x00, 0x00,
|
||||
0x00, 0x3e, 0x3c, 0x00, 0x00, 0x00, 0x1f, 0x1e, 0x00, 0x00, 0x80, 0x0f,
|
||||
0x0f, 0x78, 0x00, 0xc0, 0x87, 0x07, 0xfc, 0x00, 0xe0, 0xc3, 0x03, 0xfc,
|
||||
0x01, 0xf0, 0xe1, 0x01, 0xfc, 0x01, 0xf8, 0xf0, 0x00, 0xfc, 0x00, 0x78,
|
||||
0x70, 0x00, 0x78, 0x00, 0x10, 0x20, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
|
||||
|
||||
const char activeSymbole[] PROGMEM = {
|
||||
B00000000,
|
||||
B00000000,
|
||||
B00011000,
|
||||
B00100100,
|
||||
B01000010,
|
||||
B01000010,
|
||||
B00100100,
|
||||
B00011000
|
||||
};
|
||||
|
||||
const char inactiveSymbole[] PROGMEM = {
|
||||
B00000000,
|
||||
B00000000,
|
||||
B00000000,
|
||||
B00000000,
|
||||
B00011000,
|
||||
B00011000,
|
||||
B00000000,
|
||||
B00000000
|
||||
};
|
||||
|
||||
#endif
|
||||
@@ -1,20 +1,34 @@
|
||||
# esp8266-oled-ssd1306
|
||||
esp8266-oled-ssd1306 [](https://travis-ci.org/squix78/esp8266-oled-ssd1306)
|
||||
============
|
||||
|
||||
> We just released version 3.0.0. Please have a look at our [upgrade guide](UPGRADE-3.0.md)
|
||||
|
||||
This is a driver for the SSD1306 based 128x64 pixel OLED display running on the Arduino/ESP8266 platform.
|
||||
Can be used with either the I2C or SPI version of the display
|
||||
|
||||
You can either download this library as a zip file and unpack it to your Arduino/libraries folder or (once it has been added) choose it from the Arduino library manager.
|
||||
|
||||
It is also available as a platformio library. Just execute the following command:
|
||||
```
|
||||
platformio lib install 562
|
||||
```
|
||||
|
||||
## Credits
|
||||
Many thanks go to Fabrice Weinberg (@FWeinb) for optimizing and refactoring the UI library.
|
||||
The init sequence for the SSD1306 was inspired by Adafruits library for the same display.
|
||||
This library has initially been written by Daniel Eichhorn (@squix78). Many thanks go to Fabrice Weinberg (@FWeinb) for optimizing and refactoring many aspects of the library. Also many thanks to the many committers who helped to add new features and who fixed many bugs.
|
||||
The init sequence for the SSD1306 was inspired by Adafruit's library for the same display.
|
||||
|
||||
## Usage
|
||||
|
||||
The SSD1306Demo is a very comprehensive example demonstrating the most important features of the library.
|
||||
Check out the examples folder for a few comprehensive demonstrations how to use the library. Also check out the ESP8266 Weather Station library (https://github.com/squix78/esp8266-weather-station) which uses the OLED library to display beautiful weather information.
|
||||
|
||||
## Upgrade
|
||||
|
||||
The API changed a lot with the 3.0 release. If you were using this library with older versions please have a look at the [Upgrade Guide](UPGRADE-3.0.md).
|
||||
|
||||
## Features
|
||||
|
||||
* Draw pixels at given coordinates
|
||||
* Draw lines from given coordinates to given coordinates
|
||||
* Draw or fill a rectangle with given dimensions
|
||||
* Draw Text at given coordinates:
|
||||
* Define Alignment: Left, Right and Center
|
||||
@@ -32,20 +46,72 @@ Fonts are defined in a proprietary but open format. You can create new font file
|
||||
of open sourced Fonts from this web app: http://oleddisplay.squix.ch
|
||||
Choose the font family, style and size, check the preview image and if you like what you see click the "Create" button. This will create the font array in a text area form where you can copy and paste it into a new or existing header file.
|
||||
|
||||
|
||||

|
||||
|
||||
## Hardware Abstraction
|
||||
|
||||
The library supports different protocols to access the OLED display. Currently there is support for I2C using the built in Wire.h library, I2C by using the much faster BRZO I2C library [https://github.com/pasko-zh/brzo_i2c] written in assembler and it also supports displays which come with the SPI interface.
|
||||
|
||||
### I2C with Wire.h
|
||||
|
||||
```C++
|
||||
#include <Wire.h>
|
||||
#include "SSD1306.h"
|
||||
|
||||
SSD1306 display(ADDRESS, SDA, SDC);
|
||||
```
|
||||
or for a SH1106:
|
||||
```C++
|
||||
#include <Wire.h>
|
||||
#include "SH1106.h"
|
||||
|
||||
SH1106 display(ADDRESS, SDA, SDC);
|
||||
```
|
||||
|
||||
### I2C with brzo_i2c
|
||||
|
||||
```C++
|
||||
#include <brzo_i2c.h>
|
||||
#include "SSD1306Brzo.h"
|
||||
|
||||
SSD1306Brzo display(ADDRESS, SDA, SDC);
|
||||
```
|
||||
or for the SH1106:
|
||||
```C++
|
||||
#include <brzo_i2c.h>
|
||||
#include "SH1106Brzo.h"
|
||||
|
||||
SH1106Brzo display(ADDRESS, SDA, SDC);
|
||||
```
|
||||
|
||||
### SPI
|
||||
|
||||
```C++
|
||||
#include <SPI.h>
|
||||
#include "SSD1306Spi.h"
|
||||
|
||||
SSD1306Spi display(RES, DC, CS);
|
||||
```
|
||||
or for the SH1106:
|
||||
```C++
|
||||
#include <SPI.h>
|
||||
#include "SH1106Spi.h"
|
||||
|
||||
SH1106Spi display(RES, DC, CS);
|
||||
```
|
||||
|
||||
## API
|
||||
|
||||
### Display Control
|
||||
|
||||
```C++
|
||||
// Create the display object connected to pin sda and sdc
|
||||
SSD1306(int i2cAddress, int sda, int sdc);
|
||||
|
||||
// Initialize the display
|
||||
void init();
|
||||
|
||||
// Free the memory used by the display
|
||||
void end();
|
||||
|
||||
// Cycle through the initialization
|
||||
void resetDisplay(void);
|
||||
|
||||
@@ -64,101 +130,227 @@ void clear(void);
|
||||
// Write the buffer to the display memory
|
||||
void display(void);
|
||||
|
||||
// Inverted display mode
|
||||
void invertDisplay(void);
|
||||
|
||||
// Normal display mode
|
||||
void normalDisplay(void);
|
||||
|
||||
// Set display contrast
|
||||
void setContrast(char contrast);
|
||||
|
||||
// Turn the display upside down
|
||||
void flipScreenVertically();
|
||||
|
||||
// Send a command to the display (low level function)
|
||||
void sendCommand(unsigned char com);
|
||||
|
||||
// Send all the init commands
|
||||
void sendInitCommands(void);
|
||||
```
|
||||
|
||||
## Pixel drawing
|
||||
|
||||
```C++
|
||||
// Draw a pixel at given position
|
||||
void setPixel(int x, int y);
|
||||
|
||||
// Draw 8 bits at the given position
|
||||
void setChar(int x, int y, unsigned char data);
|
||||
/* Drawing functions */
|
||||
// Sets the color of all pixel operations
|
||||
void setColor(OLEDDISPLAY_COLOR color);
|
||||
|
||||
// Draw a pixel at given position
|
||||
void setPixel(int16_t x, int16_t y);
|
||||
|
||||
// Draw a line from position 0 to position 1
|
||||
void drawLine(int16_t x0, int16_t y0, int16_t x1, int16_t y1);
|
||||
|
||||
// Draw the border of a rectangle at the given location
|
||||
void drawRect(int x, int y, int width, int height);
|
||||
void drawRect(int16_t x, int16_t y, int16_t width, int16_t height);
|
||||
|
||||
// Fill the rectangle
|
||||
void fillRect(int x, int y, int width, int height);
|
||||
void fillRect(int16_t x, int16_t y, int16_t width, int16_t height);
|
||||
|
||||
// Draw a bitmap with the given dimensions
|
||||
void drawBitmap(int x, int y, int width, int height, const char *bitmap);
|
||||
// Draw the border of a circle
|
||||
void drawCircle(int16_t x, int16_t y, int16_t radius);
|
||||
|
||||
// Draw an XBM image with the given dimensions
|
||||
void drawXbm(int x, int y, int width, int height, const char *xbm);
|
||||
// Fill circle
|
||||
void fillCircle(int16_t x, int16_t y, int16_t radius);
|
||||
|
||||
// Sets the color of all pixel operations
|
||||
void setColor(int color);
|
||||
// Draw a line horizontally
|
||||
void drawHorizontalLine(int16_t x, int16_t y, int16_t length);
|
||||
|
||||
// Draw a lin vertically
|
||||
void drawVerticalLine(int16_t x, int16_t y, int16_t length);
|
||||
|
||||
// Draws a rounded progress bar with the outer dimensions given by width and height. Progress is
|
||||
// a unsigned byte value between 0 and 100
|
||||
void drawProgressBar(uint16_t x, uint16_t y, uint16_t width, uint16_t height, uint8_t progress);
|
||||
|
||||
// Draw a bitmap in the internal image format
|
||||
void drawFastImage(int16_t x, int16_t y, int16_t width, int16_t height, const char *image);
|
||||
|
||||
// Draw a XBM
|
||||
void drawXbm(int16_t x, int16_t y, int16_t width, int16_t height, const char* xbm);
|
||||
```
|
||||
|
||||
## Text operations
|
||||
|
||||
``` C++
|
||||
// Draws a string at the given location
|
||||
void drawString(int x, int y, String text);
|
||||
void drawString(int16_t x, int16_t y, String text);
|
||||
|
||||
// Draws a String with a maximum width at the given location.
|
||||
// If the given String is wider than the specified width
|
||||
// The text will be wrapped to the next line at a space or dash
|
||||
void drawStringMaxWidth(int x, int y, int maxLineWidth, String text);
|
||||
void drawStringMaxWidth(int16_t x, int16_t y, int16_t maxLineWidth, String text);
|
||||
|
||||
// Returns the width of the String with the current
|
||||
// Returns the width of the const char* with the current
|
||||
// font settings
|
||||
int getStringWidth(String text);
|
||||
uint16_t getStringWidth(const char* text, uint16_t length);
|
||||
|
||||
// Convencience method for the const char version
|
||||
uint16_t getStringWidth(String text);
|
||||
|
||||
// Specifies relative to which anchor point
|
||||
// the text is rendered. Available constants:
|
||||
// TEXT_ALIGN_LEFT, TEXT_ALIGN_CENTER, TEXT_ALIGN_RIGHT
|
||||
void setTextAlignment(int textAlignment);
|
||||
// TEXT_ALIGN_LEFT, TEXT_ALIGN_CENTER, TEXT_ALIGN_RIGHT, TEXT_ALIGN_CENTER_BOTH
|
||||
void setTextAlignment(OLEDDISPLAY_TEXT_ALIGNMENT textAlignment);
|
||||
|
||||
// Sets the current font. Available default fonts
|
||||
// defined in SSD1306Fonts.h:
|
||||
// ArialMT_Plain_10, ArialMT_Plain_16, ArialMT_Plain_24
|
||||
// Or create one with the font tool at http://oleddisplay.squix.ch
|
||||
void setFont(const char *fontData);
|
||||
void setFont(const char* fontData);
|
||||
```
|
||||
|
||||
## Frame Transition Functions
|
||||
## Ui Library (OLEDDisplayUi)
|
||||
|
||||
The Ui Library is used to provide a basic set of Ui elements called, `Frames` and `Overlays`. A `Frame` is used to provide
|
||||
information the default behaviour is to display a `Frame` for a defined time and than move to the next. The library also provides an `Indicator` that will be updated accordingly. An `Overlay` on the other hand is a pieces of information (e.g. a clock) that is displayed always at the same position.
|
||||
|
||||
The Frame Transition functions are a set of functions on top of the basic library. They allow you to easily write frames which will be shifted in regular intervals. The frame animation (including the frame indicators) will only be activated if you define callback functions with setFrameCallacks(..). If no callback methods are defined no indicators will be displayed.
|
||||
|
||||
```C++
|
||||
// Sets the callback methods of the format void method(x,y). As soon as you define the callbacks
|
||||
// the library is in "frame mode" and indicators will be drawn.
|
||||
void setFrameCallbacks(int frameCount, void (*frameCallbacks[])(SSD1306 *display, SSD1306UiState* state,int x, int y));
|
||||
/**
|
||||
* Initialise the display
|
||||
*/
|
||||
void init();
|
||||
|
||||
// Tells the framework to move to the next tick. The
|
||||
// current visible frame callback will be called once
|
||||
// per tick
|
||||
void nextFrameTick(void);
|
||||
/**
|
||||
* Configure the internal used target FPS
|
||||
*/
|
||||
void setTargetFPS(uint8_t fps);
|
||||
|
||||
// Draws the frame indicators. In a normal setup
|
||||
// the framework does this for you
|
||||
void drawIndicators(int frameCount, int activeFrame);
|
||||
/**
|
||||
* Enable automatic transition to next frame after the some time can be configured with
|
||||
* `setTimePerFrame` and `setTimePerTransition`.
|
||||
*/
|
||||
void enableAutoTransition();
|
||||
|
||||
// defines how many ticks a frame should remain visible
|
||||
// This does not include the transition
|
||||
void setFrameWaitTicks(int frameWaitTicks);
|
||||
/**
|
||||
* Disable automatic transition to next frame.
|
||||
*/
|
||||
void disableAutoTransition();
|
||||
|
||||
// Defines how many ticks should be used for a transition
|
||||
void setFrameTransitionTicks(int frameTransitionTicks);
|
||||
/**
|
||||
* Set the direction if the automatic transitioning
|
||||
*/
|
||||
void setAutoTransitionForwards();
|
||||
void setAutoTransitionBackwards();
|
||||
|
||||
// Returns the current state of the internal state machine
|
||||
// Possible values: FRAME_STATE_FIX, FRAME_STATE_TRANSITION
|
||||
// You can use this to detect when there is no transition
|
||||
// on the way to execute operations that would
|
||||
int getFrameState();
|
||||
/**
|
||||
* Set the approx. time a frame is displayed
|
||||
*/
|
||||
void setTimePerFrame(uint16_t time);
|
||||
|
||||
/**
|
||||
* Set the approx. time a transition will take
|
||||
*/
|
||||
void setTimePerTransition(uint16_t time);
|
||||
|
||||
/**
|
||||
* Draw the indicator.
|
||||
* This is the default state for all frames if
|
||||
* the indicator was hidden on the previous frame
|
||||
* it will be slided in.
|
||||
*/
|
||||
void enableIndicator();
|
||||
|
||||
/**
|
||||
* Don't draw the indicator.
|
||||
* This will slide out the indicator
|
||||
* when transitioning to the next frame.
|
||||
*/
|
||||
void disableIndicator();
|
||||
|
||||
/**
|
||||
* Enable drawing of all indicators.
|
||||
*/
|
||||
void enableAllIndicators();
|
||||
|
||||
/**
|
||||
* Disable drawing of all indicators.
|
||||
*/
|
||||
void disableAllIndicators();
|
||||
|
||||
/**
|
||||
* Set the position of the indicator bar.
|
||||
*/
|
||||
void setIndicatorPosition(IndicatorPosition pos);
|
||||
|
||||
/**
|
||||
* Set the direction of the indicator bar. Defining the order of frames ASCENDING / DESCENDING
|
||||
*/
|
||||
void setIndicatorDirection(IndicatorDirection dir);
|
||||
|
||||
/**
|
||||
* Set the symbol to indicate an active frame in the indicator bar.
|
||||
*/
|
||||
void setActiveSymbol(const char* symbol);
|
||||
|
||||
/**
|
||||
* Set the symbol to indicate an inactive frame in the indicator bar.
|
||||
*/
|
||||
void setInactiveSymbol(const char* symbol);
|
||||
|
||||
/**
|
||||
* Configure what animation is used to transition from one frame to another
|
||||
*/
|
||||
void setFrameAnimation(AnimationDirection dir);
|
||||
|
||||
/**
|
||||
* Add frame drawing functions
|
||||
*/
|
||||
void setFrames(FrameCallback* frameFunctions, uint8_t frameCount);
|
||||
|
||||
/**
|
||||
* Add overlays drawing functions that are draw independent of the Frames
|
||||
*/
|
||||
void setOverlays(OverlayCallback* overlayFunctions, uint8_t overlayCount);
|
||||
|
||||
/**
|
||||
* Set the function that will draw each step
|
||||
* in the loading animation
|
||||
*/
|
||||
void setLoadingDrawFunction(LoadingDrawFunction loadingDrawFunction);
|
||||
|
||||
/**
|
||||
* Run the loading process
|
||||
*/
|
||||
void runLoadingProcess(LoadingStage* stages, uint8_t stagesCount);
|
||||
|
||||
// Manuell Controll
|
||||
void nextFrame();
|
||||
void previousFrame();
|
||||
|
||||
/**
|
||||
* Switch without transition to frame `frame`.
|
||||
*/
|
||||
void switchToFrame(uint8_t frame);
|
||||
|
||||
/**
|
||||
* Transition to frame `frame`, when the `frame` number is bigger than the current
|
||||
* frame the forward animation will be used, otherwise the backwards animation is used.
|
||||
*/
|
||||
void transitionToFrame(uint8_t frame);
|
||||
|
||||
// State Info
|
||||
OLEDDisplayUiState* getUiState();
|
||||
|
||||
// This needs to be called in the main loop
|
||||
// the returned value is the remaining time (in ms)
|
||||
// you have to draw after drawing to keep the frame budget.
|
||||
int8_t update();
|
||||
```
|
||||
|
||||
## Example: SSD1306Demo
|
||||
@@ -187,3 +379,15 @@ This frame demonstrates the text alignment. The coordinates in the frame show re
|
||||

|
||||
|
||||
This shows how to use define a maximum width after which the driver automatically wraps a word to the next line. This comes in very handy if you have longer texts to display.
|
||||
|
||||
### SPI version
|
||||
|
||||

|
||||
|
||||
This shows the code working on the SPI version of the display. See demo code for ESP8266 pins used.
|
||||
|
||||
## Project using this library
|
||||
|
||||
* [QRCode ESP8266](https://github.com/anunpanya/ESP8266_QRcode) (by @anunpanya)
|
||||
* [Scan I2C](https://github.com/hallard/Scan-I2C-WiFi) (by @hallard)
|
||||
* [Weather Station](https://github.com/squix78/esp8266-weather-station) (by @squix)
|
||||
|
||||
@@ -0,0 +1,36 @@
|
||||
/**
|
||||
* The MIT License (MIT)
|
||||
*
|
||||
* Copyright (c) 2016 by Daniel Eichhorn
|
||||
* Copyright (c) 2016 by Fabrice Weinberg
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in all
|
||||
* copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
* SOFTWARE.
|
||||
*
|
||||
* Credits for parts of this code go to Mike Rankin. Thank you so much for sharing!
|
||||
*/
|
||||
|
||||
#ifndef SH1106_h
|
||||
#define SH1106_h
|
||||
#include "SH1106Wire.h"
|
||||
|
||||
// For make SH1106 an alias for SH1106Wire
|
||||
typedef SH1106Wire SH1106;
|
||||
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,133 @@
|
||||
/**
|
||||
* The MIT License (MIT)
|
||||
*
|
||||
* Copyright (c) 2016 by Daniel Eichhorn
|
||||
* Copyright (c) 2016 by Fabrice Weinberg
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in all
|
||||
* copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
* SOFTWARE.
|
||||
*
|
||||
* Credits for parts of this code go to Mike Rankin. Thank you so much for sharing!
|
||||
*/
|
||||
|
||||
#ifndef SH1106Brzo_h
|
||||
#define SH1106Brzo_h
|
||||
|
||||
#include "OLEDDisplay.h"
|
||||
#include <brzo_i2c.h>
|
||||
|
||||
#if F_CPU == 160000000L
|
||||
#define BRZO_I2C_SPEED 1000
|
||||
#else
|
||||
#define BRZO_I2C_SPEED 800
|
||||
#endif
|
||||
|
||||
class SH1106Brzo : public OLEDDisplay {
|
||||
private:
|
||||
uint8_t _address;
|
||||
uint8_t _sda;
|
||||
uint8_t _scl;
|
||||
|
||||
public:
|
||||
SH1106Brzo(uint8_t _address, uint8_t _sda, uint8_t _scl) {
|
||||
this->_address = _address;
|
||||
this->_sda = _sda;
|
||||
this->_scl = _scl;
|
||||
}
|
||||
|
||||
bool connect(){
|
||||
brzo_i2c_setup(_sda, _scl, 0);
|
||||
return true;
|
||||
}
|
||||
|
||||
void display(void) {
|
||||
#ifdef OLEDDISPLAY_DOUBLE_BUFFER
|
||||
uint8_t minBoundY = ~0;
|
||||
uint8_t maxBoundY = 0;
|
||||
|
||||
uint8_t minBoundX = ~0;
|
||||
uint8_t maxBoundX = 0;
|
||||
uint8_t x, y;
|
||||
|
||||
// Calculate the Y bounding box of changes
|
||||
// and copy buffer[pos] to buffer_back[pos];
|
||||
for (y = 0; y < (DISPLAY_HEIGHT / 8); y++) {
|
||||
for (x = 0; x < DISPLAY_WIDTH; x++) {
|
||||
uint16_t pos = x + y * DISPLAY_WIDTH;
|
||||
if (buffer[pos] != buffer_back[pos]) {
|
||||
minBoundY = _min(minBoundY, y);
|
||||
maxBoundY = _max(maxBoundY, y);
|
||||
minBoundX = _min(minBoundX, x);
|
||||
maxBoundX = _max(maxBoundX, x);
|
||||
}
|
||||
buffer_back[pos] = buffer[pos];
|
||||
}
|
||||
yield();
|
||||
}
|
||||
|
||||
// If the minBoundY wasn't updated
|
||||
// we can savely assume that buffer_back[pos] == buffer[pos]
|
||||
// holdes true for all values of pos
|
||||
if (minBoundY == ~0) return;
|
||||
|
||||
byte k = 0;
|
||||
uint8_t sendBuffer[17];
|
||||
sendBuffer[0] = 0x40;
|
||||
|
||||
// Calculate the colum offset
|
||||
uint8_t minBoundXp2H = (minBoundX + 2) & 0x0F;
|
||||
uint8_t minBoundXp2L = 0x10 | ((minBoundX + 2) >> 4 );
|
||||
|
||||
brzo_i2c_start_transaction(this->_address, BRZO_I2C_SPEED);
|
||||
|
||||
for (y = minBoundY; y <= maxBoundY; y++) {
|
||||
sendCommand(0xB0 + y);
|
||||
sendCommand(minBoundXp2H);
|
||||
sendCommand(minBoundXp2L);
|
||||
for (x = minBoundX; x <= maxBoundX; x++) {
|
||||
k++;
|
||||
sendBuffer[k] = buffer[x + y * DISPLAY_WIDTH];
|
||||
if (k == 16) {
|
||||
brzo_i2c_write(sendBuffer, 17, true);
|
||||
k = 0;
|
||||
}
|
||||
}
|
||||
if (k != 0) {
|
||||
brzo_i2c_write(sendBuffer, k + 1, true);
|
||||
k = 0;
|
||||
}
|
||||
yield();
|
||||
}
|
||||
if (k != 0) {
|
||||
brzo_i2c_write(sendBuffer, k + 1, true);
|
||||
}
|
||||
brzo_i2c_end_transaction();
|
||||
#else
|
||||
#endif
|
||||
}
|
||||
|
||||
private:
|
||||
inline void sendCommand(uint8_t com) __attribute__((always_inline)){
|
||||
uint8_t command[2] = {0x80 /* command mode */, com};
|
||||
brzo_i2c_start_transaction(_address, BRZO_I2C_SPEED);
|
||||
brzo_i2c_write(command, 2, true);
|
||||
brzo_i2c_end_transaction();
|
||||
}
|
||||
};
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,128 @@
|
||||
/**
|
||||
* The MIT License (MIT)
|
||||
*
|
||||
* Copyright (c) 2016 by Daniel Eichhorn
|
||||
* Copyright (c) 2016 by Fabrice Weinberg
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in all
|
||||
* copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
* SOFTWARE.
|
||||
*
|
||||
* Credits for parts of this code go to Mike Rankin. Thank you so much for sharing!
|
||||
*/
|
||||
|
||||
#ifndef SH1106Spi_h
|
||||
#define SH1106Spi_h
|
||||
|
||||
#include "OLEDDisplay.h"
|
||||
#include <SPI.h>
|
||||
|
||||
class SH1106Spi : public OLEDDisplay {
|
||||
private:
|
||||
uint8_t _rst;
|
||||
uint8_t _dc;
|
||||
|
||||
public:
|
||||
|
||||
SH1106Spi(uint8_t _rst, uint8_t _dc) {
|
||||
this->_rst = _rst;
|
||||
this->_dc = _dc;
|
||||
}
|
||||
|
||||
bool connect(){
|
||||
pinMode(_dc, OUTPUT);
|
||||
pinMode(_rst, OUTPUT);
|
||||
|
||||
SPI.begin ();
|
||||
SPI.setClockDivider (SPI_CLOCK_DIV2);
|
||||
|
||||
// Pulse Reset low for 10ms
|
||||
digitalWrite(_rst, HIGH);
|
||||
delay(1);
|
||||
digitalWrite(_rst, LOW);
|
||||
delay(10);
|
||||
digitalWrite(_rst, HIGH);
|
||||
return true;
|
||||
}
|
||||
|
||||
void display(void) {
|
||||
#ifdef OLEDDISPLAY_DOUBLE_BUFFER
|
||||
uint8_t minBoundY = ~0;
|
||||
uint8_t maxBoundY = 0;
|
||||
|
||||
uint8_t minBoundX = ~0;
|
||||
uint8_t maxBoundX = 0;
|
||||
|
||||
uint8_t x, y;
|
||||
|
||||
// Calculate the Y bounding box of changes
|
||||
// and copy buffer[pos] to buffer_back[pos];
|
||||
for (y = 0; y < (DISPLAY_HEIGHT / 8); y++) {
|
||||
for (x = 0; x < DISPLAY_WIDTH; x++) {
|
||||
uint16_t pos = x + y * DISPLAY_WIDTH;
|
||||
if (buffer[pos] != buffer_back[pos]) {
|
||||
minBoundY = _min(minBoundY, y);
|
||||
maxBoundY = _max(maxBoundY, y);
|
||||
minBoundX = _min(minBoundX, x);
|
||||
maxBoundX = _max(maxBoundX, x);
|
||||
}
|
||||
buffer_back[pos] = buffer[pos];
|
||||
}
|
||||
yield();
|
||||
}
|
||||
|
||||
// If the minBoundY wasn't updated
|
||||
// we can savely assume that buffer_back[pos] == buffer[pos]
|
||||
// holdes true for all values of pos
|
||||
if (minBoundY == ~0) return;
|
||||
|
||||
// Calculate the colum offset
|
||||
uint8_t minBoundXp2H = (minBoundX + 2) & 0x0F;
|
||||
uint8_t minBoundXp2L = 0x10 | ((minBoundX + 2) >> 4 );
|
||||
|
||||
for (y = minBoundY; y <= maxBoundY; y++) {
|
||||
sendCommand(0xB0 + y);
|
||||
sendCommand(minBoundXp2H);
|
||||
sendCommand(minBoundXp2L);
|
||||
digitalWrite(_dc, HIGH); // data mode
|
||||
for (x = minBoundX; x <= maxBoundX; x++) {
|
||||
SPI.transfer(buffer[x + y * DISPLAY_WIDTH]);
|
||||
}
|
||||
yield();
|
||||
}
|
||||
#else
|
||||
for (uint8_t y=0; y<DISPLAY_HEIGHT/8; y++) {
|
||||
sendCommand(0xB0 + y);
|
||||
sendCommand(0x02);
|
||||
sendCommand(0x10);
|
||||
digitalWrite(_dc, HIGH); // data mode
|
||||
for( uint8_t x=0; x < DISPLAY_WIDTH; x++) {
|
||||
SPI.transfer(buffer[x + y * DISPLAY_WIDTH]);
|
||||
}
|
||||
yield();
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
private:
|
||||
inline void sendCommand(uint8_t com) __attribute__((always_inline)){
|
||||
digitalWrite(_dc, LOW);
|
||||
SPI.transfer(com);
|
||||
}
|
||||
};
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,152 @@
|
||||
/**
|
||||
* The MIT License (MIT)
|
||||
*
|
||||
* Copyright (c) 2016 by Daniel Eichhorn
|
||||
* Copyright (c) 2016 by Fabrice Weinberg
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in all
|
||||
* copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
* SOFTWARE.
|
||||
*
|
||||
* Credits for parts of this code go to Mike Rankin. Thank you so much for sharing!
|
||||
*/
|
||||
|
||||
#ifndef SH1106Wire_h
|
||||
#define SH1106Wire_h
|
||||
|
||||
#include "OLEDDisplay.h"
|
||||
#include <Wire.h>
|
||||
|
||||
#define SH1106_SET_PUMP_VOLTAGE 0X30
|
||||
#define SH1106_SET_PUMP_MODE 0XAD
|
||||
#define SH1106_PUMP_ON 0X8B
|
||||
#define SH1106_PUMP_OFF 0X8A
|
||||
//--------------------------------------
|
||||
|
||||
class SH1106Wire : public OLEDDisplay {
|
||||
private:
|
||||
uint8_t _address;
|
||||
uint8_t _sda;
|
||||
uint8_t _scl;
|
||||
|
||||
public:
|
||||
SH1106Wire(uint8_t _address, uint8_t _sda, uint8_t _scl) {
|
||||
this->_address = _address;
|
||||
this->_sda = _sda;
|
||||
this->_scl = _scl;
|
||||
}
|
||||
|
||||
bool connect() {
|
||||
Wire.begin(this->_sda, this->_scl);
|
||||
// Let's use ~700khz if ESP8266 is in 160Mhz mode
|
||||
// this will be limited to ~400khz if the ESP8266 in 80Mhz mode.
|
||||
Wire.setClock(700000);
|
||||
return true;
|
||||
}
|
||||
|
||||
void display(void) {
|
||||
#ifdef OLEDDISPLAY_DOUBLE_BUFFER
|
||||
uint8_t minBoundY = ~0;
|
||||
uint8_t maxBoundY = 0;
|
||||
|
||||
uint8_t minBoundX = ~0;
|
||||
uint8_t maxBoundX = 0;
|
||||
|
||||
uint8_t x, y;
|
||||
|
||||
// Calculate the Y bounding box of changes
|
||||
// and copy buffer[pos] to buffer_back[pos];
|
||||
for (y = 0; y < (DISPLAY_HEIGHT / 8); y++) {
|
||||
for (x = 0; x < DISPLAY_WIDTH; x++) {
|
||||
uint16_t pos = x + y * DISPLAY_WIDTH;
|
||||
if (buffer[pos] != buffer_back[pos]) {
|
||||
minBoundY = _min(minBoundY, y);
|
||||
maxBoundY = _max(maxBoundY, y);
|
||||
minBoundX = _min(minBoundX, x);
|
||||
maxBoundX = _max(maxBoundX, x);
|
||||
}
|
||||
buffer_back[pos] = buffer[pos];
|
||||
}
|
||||
yield();
|
||||
}
|
||||
|
||||
// If the minBoundY wasn't updated
|
||||
// we can savely assume that buffer_back[pos] == buffer[pos]
|
||||
// holdes true for all values of pos
|
||||
if (minBoundY == ~0) return;
|
||||
|
||||
// Calculate the colum offset
|
||||
uint8_t minBoundXp2H = (minBoundX + 2) & 0x0F;
|
||||
uint8_t minBoundXp2L = 0x10 | ((minBoundX + 2) >> 4 );
|
||||
|
||||
byte k = 0;
|
||||
for (y = minBoundY; y <= maxBoundY; y++) {
|
||||
sendCommand(0xB0 + y);
|
||||
sendCommand(minBoundXp2H);
|
||||
sendCommand(minBoundXp2L);
|
||||
for (x = minBoundX; x <= maxBoundX; x++) {
|
||||
if (k == 0) {
|
||||
Wire.beginTransmission(_address);
|
||||
Wire.write(0x40);
|
||||
}
|
||||
Wire.write(buffer[x + y * DISPLAY_WIDTH]);
|
||||
k++;
|
||||
if (k == 16) {
|
||||
Wire.endTransmission();
|
||||
k = 0;
|
||||
}
|
||||
}
|
||||
if (k != 0) {
|
||||
Wire.endTransmission();
|
||||
k = 0;
|
||||
}
|
||||
yield();
|
||||
}
|
||||
|
||||
if (k != 0) {
|
||||
Wire.endTransmission();
|
||||
}
|
||||
#else
|
||||
uint8_t * p = &buffer[0];
|
||||
for (uint8_t y=0; y<8; y++) {
|
||||
sendCommand(0xB0+y);
|
||||
sendCommand(0x02);
|
||||
sendCommand(0x10);
|
||||
for( uint8_t x=0; x<8; x++) {
|
||||
Wire.beginTransmission(_address);
|
||||
Wire.write(0x40);
|
||||
for (uint8_t k = 0; k < 16; k++) {
|
||||
Wire.write(*p++);
|
||||
}
|
||||
Wire.endTransmission();
|
||||
}
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
private:
|
||||
inline void sendCommand(uint8_t command) __attribute__((always_inline)){
|
||||
Wire.beginTransmission(_address);
|
||||
Wire.write(0x80);
|
||||
Wire.write(command);
|
||||
Wire.endTransmission();
|
||||
}
|
||||
|
||||
|
||||
};
|
||||
|
||||
#endif
|
||||
@@ -1,363 +0,0 @@
|
||||
/**The MIT License (MIT)
|
||||
|
||||
Copyright (c) 2015 by Daniel Eichhorn
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
||||
|
||||
See more at http://blog.squix.ch
|
||||
|
||||
Credits for parts of this code go to Mike Rankin. Thank you so much for sharing!
|
||||
*/
|
||||
|
||||
#include "../esp8266-oled-ssd1306/SSD1306.h"
|
||||
#include <Wire.h>
|
||||
|
||||
|
||||
SSD1306::SSD1306(int i2cAddress, int sda, int sdc) {
|
||||
myI2cAddress = i2cAddress;
|
||||
mySda = sda;
|
||||
mySdc = sdc;
|
||||
}
|
||||
|
||||
void SSD1306::init() {
|
||||
Wire.begin(mySda, mySdc);
|
||||
Wire.setClock(400000);
|
||||
sendInitCommands();
|
||||
resetDisplay();
|
||||
}
|
||||
|
||||
// Local override of init to avoid having to pass the sda and sdc in global section.
|
||||
|
||||
void SSD1306::init(int i2cAddress) {
|
||||
myI2cAddress = i2cAddress;
|
||||
|
||||
Wire.setClock(400000);
|
||||
sendInitCommands();
|
||||
resetDisplay();
|
||||
}
|
||||
|
||||
void SSD1306::resetDisplay(void) {
|
||||
displayOff();
|
||||
clear();
|
||||
display();
|
||||
displayOn();
|
||||
}
|
||||
|
||||
void SSD1306::reconnect() {
|
||||
Wire.begin(mySda, mySdc);
|
||||
}
|
||||
|
||||
void SSD1306::displayOn(void) {
|
||||
sendCommand(0xaf); //display on
|
||||
}
|
||||
|
||||
void SSD1306::displayOff(void) {
|
||||
sendCommand(0xae); //display off
|
||||
}
|
||||
|
||||
void SSD1306::setContrast(char contrast) {
|
||||
sendCommand(0x81);
|
||||
sendCommand(contrast);
|
||||
}
|
||||
|
||||
void SSD1306::flipScreenVertically() {
|
||||
sendCommand(0xA0 | 0x1); //SEGREMAP //Rotate screen 180 deg
|
||||
sendCommand(0xC8); //COMSCANDEC Rotate screen 180 Deg
|
||||
}
|
||||
|
||||
void SSD1306::clear(void) {
|
||||
memset(buffer, 0, (128 * 64 / 8));
|
||||
}
|
||||
|
||||
void SSD1306::display(void) {
|
||||
sendCommand(COLUMNADDR);
|
||||
sendCommand(0x0);
|
||||
sendCommand(0x7F);
|
||||
|
||||
sendCommand(PAGEADDR);
|
||||
sendCommand(0x0);
|
||||
sendCommand(0x7);
|
||||
|
||||
for (uint16_t i=0; i<(128*64/8); i++) {
|
||||
// send a bunch of data in one xmission
|
||||
Wire.beginTransmission(myI2cAddress);
|
||||
Wire.write(0x40);
|
||||
for (uint8_t x=0; x<16; x++) {
|
||||
Wire.write(buffer[i]);
|
||||
i++;
|
||||
}
|
||||
i--;
|
||||
yield();
|
||||
Wire.endTransmission();
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
void SSD1306::setPixel(int x, int y) {
|
||||
if (x >= 0 && x < 128 && y >= 0 && y < 64) {
|
||||
|
||||
switch (myColor) {
|
||||
case WHITE: buffer[x + (y/8)*128] |= (1 << (y&7)); break;
|
||||
case BLACK: buffer[x + (y/8)*128] &= ~(1 << (y&7)); break;
|
||||
case INVERSE: buffer[x + (y/8)*128] ^= (1 << (y&7)); break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void SSD1306::setChar(int x, int y, unsigned char data) {
|
||||
for (int i = 0; i < 8; i++) {
|
||||
if (bitRead(data, i)) {
|
||||
setPixel(x,y + i);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Code form http://playground.arduino.cc/Main/Utf8ascii
|
||||
byte SSD1306::utf8ascii(byte ascii) {
|
||||
if ( ascii<128 ) { // Standard ASCII-set 0..0x7F handling
|
||||
lastChar=0;
|
||||
return( ascii );
|
||||
}
|
||||
|
||||
// get previous input
|
||||
byte last = lastChar; // get last char
|
||||
lastChar=ascii; // remember actual character
|
||||
|
||||
switch (last) // conversion depnding on first UTF8-character
|
||||
{ case 0xC2: return (ascii); break;
|
||||
case 0xC3: return (ascii | 0xC0); break;
|
||||
case 0x82: if(ascii==0xAC) return(0x80); // special case Euro-symbol
|
||||
}
|
||||
|
||||
return (0); // otherwise: return zero, if character has to be ignored
|
||||
}
|
||||
|
||||
// Code form http://playground.arduino.cc/Main/Utf8ascii
|
||||
String SSD1306::utf8ascii(String s) {
|
||||
String r= "";
|
||||
char c;
|
||||
for (int i=0; i<s.length(); i++)
|
||||
{
|
||||
c = utf8ascii(s.charAt(i));
|
||||
if (c!=0) r+=c;
|
||||
}
|
||||
return r;
|
||||
}
|
||||
|
||||
void SSD1306::drawString(int x, int y, String text) {
|
||||
text = utf8ascii(text);
|
||||
unsigned char currentByte;
|
||||
int charX, charY;
|
||||
int currentBitCount;
|
||||
int charCode;
|
||||
int currentCharWidth;
|
||||
int currentCharStartPos;
|
||||
int cursorX = 0;
|
||||
int numberOfChars = pgm_read_byte(myFontData + CHAR_NUM_POS);
|
||||
// iterate over string
|
||||
int firstChar = pgm_read_byte(myFontData + FIRST_CHAR_POS);
|
||||
int charHeight = pgm_read_byte(myFontData + HEIGHT_POS);
|
||||
int currentCharByteNum = 0;
|
||||
int startX = 0;
|
||||
int startY = y;
|
||||
|
||||
if (myTextAlignment == TEXT_ALIGN_LEFT) {
|
||||
startX = x;
|
||||
} else if (myTextAlignment == TEXT_ALIGN_CENTER) {
|
||||
int width = getStringWidth(text);
|
||||
startX = x - width / 2;
|
||||
} else if (myTextAlignment == TEXT_ALIGN_RIGHT) {
|
||||
int width = getStringWidth(text);
|
||||
startX = x - width;
|
||||
}
|
||||
|
||||
for (int j=0; j < text.length(); j++) {
|
||||
|
||||
charCode = text.charAt(j)-0x20;
|
||||
|
||||
currentCharWidth = pgm_read_byte(myFontData + CHAR_WIDTH_START_POS + charCode);
|
||||
// Jump to font data beginning
|
||||
currentCharStartPos = CHAR_WIDTH_START_POS + numberOfChars;
|
||||
|
||||
for (int m = 0; m < charCode; m++) {
|
||||
|
||||
currentCharStartPos += pgm_read_byte(myFontData + CHAR_WIDTH_START_POS + m) * charHeight / 8 + 1;
|
||||
}
|
||||
|
||||
currentCharByteNum = ((charHeight * currentCharWidth) / 8) + 1;
|
||||
// iterate over all bytes of character
|
||||
for (int i = 0; i < currentCharByteNum; i++) {
|
||||
|
||||
currentByte = pgm_read_byte(myFontData + currentCharStartPos + i);
|
||||
//Serial.println(String(charCode) + ", " + String(currentCharWidth) + ", " + String(currentByte));
|
||||
// iterate over all bytes of character
|
||||
for(int bit = 0; bit < 8; bit++) {
|
||||
//int currentBit = bitRead(currentByte, bit);
|
||||
|
||||
currentBitCount = i * 8 + bit;
|
||||
|
||||
charX = currentBitCount % currentCharWidth;
|
||||
charY = currentBitCount / currentCharWidth;
|
||||
|
||||
if (bitRead(currentByte, bit)) {
|
||||
setPixel(startX + cursorX + charX, startY + charY);
|
||||
}
|
||||
|
||||
}
|
||||
yield();
|
||||
}
|
||||
cursorX += currentCharWidth;
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
void SSD1306::drawStringMaxWidth(int x, int y, int maxLineWidth, String text) {
|
||||
int currentLineWidth = 0;
|
||||
int startsAt = 0;
|
||||
int endsAt = 0;
|
||||
int lineNumber = 0;
|
||||
char currentChar = ' ';
|
||||
int lineHeight = pgm_read_byte(myFontData + HEIGHT_POS);
|
||||
String currentLine = "";
|
||||
for (int i = 0; i < text.length(); i++) {
|
||||
currentChar = text.charAt(i);
|
||||
if (currentChar == ' ' || currentChar == '-') {
|
||||
String lineCandidate = text.substring(startsAt, i);
|
||||
if (getStringWidth(lineCandidate) <= maxLineWidth) {
|
||||
endsAt = i;
|
||||
} else {
|
||||
|
||||
drawString(x, y + lineNumber * lineHeight, text.substring(startsAt, endsAt));
|
||||
lineNumber++;
|
||||
startsAt = endsAt + 1;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
drawString(x, y + lineNumber * lineHeight, text.substring(startsAt));
|
||||
}
|
||||
|
||||
int SSD1306::getStringWidth(String text) {
|
||||
text = utf8ascii(text);
|
||||
int stringWidth = 0;
|
||||
char charCode;
|
||||
for (int j=0; j < text.length(); j++) {
|
||||
charCode = text.charAt(j)-0x20;
|
||||
stringWidth += pgm_read_byte(myFontData + CHAR_WIDTH_START_POS + charCode);
|
||||
}
|
||||
return stringWidth;
|
||||
}
|
||||
|
||||
void SSD1306::setTextAlignment(int textAlignment) {
|
||||
myTextAlignment = textAlignment;
|
||||
}
|
||||
|
||||
void SSD1306::setFont(const char *fontData) {
|
||||
myFontData = fontData;
|
||||
}
|
||||
|
||||
void SSD1306::drawBitmap(int x, int y, int width, int height, const char *bitmap) {
|
||||
for (int i = 0; i < width * height / 8; i++ ){
|
||||
unsigned char charColumn = 255 - pgm_read_byte(bitmap + i);
|
||||
for (int j = 0; j < 8; j++) {
|
||||
int targetX = i % width + x;
|
||||
int targetY = (i / (width)) * 8 + j + y;
|
||||
if (bitRead(charColumn, j)) {
|
||||
setPixel(targetX, targetY);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void SSD1306::setColor(int color) {
|
||||
myColor = color;
|
||||
}
|
||||
|
||||
void SSD1306::drawRect(int x, int y, int width, int height) {
|
||||
for (int i = x; i < x + width; i++) {
|
||||
setPixel(i, y);
|
||||
setPixel(i, y + height);
|
||||
}
|
||||
for (int i = y; i < y + height; i++) {
|
||||
setPixel(x, i);
|
||||
setPixel(x + width, i);
|
||||
}
|
||||
}
|
||||
|
||||
void SSD1306::fillRect(int x, int y, int width, int height) {
|
||||
for (int i = x; i < x + width; i++) {
|
||||
for (int j = y; j < y + height; j++) {
|
||||
setPixel(i, j);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void SSD1306::drawXbm(int x, int y, int width, int height, const char *xbm) {
|
||||
if (width % 8 != 0) {
|
||||
width = ((width / 8) + 1) * 8;
|
||||
}
|
||||
for (int i = 0; i < width * height / 8; i++ ){
|
||||
unsigned char charColumn = pgm_read_byte(xbm + i);
|
||||
for (int j = 0; j < 8; j++) {
|
||||
int targetX = (i * 8 + j) % width + x;
|
||||
int targetY = (8 * i / (width)) + y;
|
||||
if (bitRead(charColumn, j)) {
|
||||
setPixel(targetX, targetY);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void SSD1306::sendCommand(unsigned char com) {
|
||||
Wire.beginTransmission(myI2cAddress); //begin transmitting
|
||||
Wire.write(0x80); //command mode
|
||||
Wire.write(com);
|
||||
Wire.endTransmission(); // stop transmitting
|
||||
}
|
||||
|
||||
void SSD1306::sendInitCommands(void) {
|
||||
sendCommand(DISPLAYOFF);
|
||||
sendCommand(NORMALDISPLAY);
|
||||
sendCommand(SETDISPLAYCLOCKDIV);
|
||||
sendCommand(0x80);
|
||||
sendCommand(SETMULTIPLEX);
|
||||
sendCommand(0x3F);
|
||||
sendCommand(SETDISPLAYOFFSET);
|
||||
sendCommand(0x00);
|
||||
sendCommand(SETSTARTLINE | 0x00);
|
||||
sendCommand(CHARGEPUMP);
|
||||
sendCommand(0x14);
|
||||
sendCommand(MEMORYMODE);
|
||||
sendCommand(0x00);
|
||||
sendCommand(SEGREMAP);
|
||||
sendCommand(COMSCANINC);
|
||||
sendCommand(SETCOMPINS);
|
||||
sendCommand(0x12);
|
||||
sendCommand(SETCONTRAST);
|
||||
sendCommand(0xCF);
|
||||
sendCommand(SETPRECHARGE);
|
||||
sendCommand(0xF1);
|
||||
sendCommand(SETVCOMDETECT);
|
||||
sendCommand(0x40);
|
||||
sendCommand(DISPLAYALLON_RESUME);
|
||||
sendCommand(NORMALDISPLAY);
|
||||
sendCommand(0x2e); // stop scroll
|
||||
sendCommand(DISPLAYON);
|
||||
}
|
||||
@@ -1,176 +1,36 @@
|
||||
/**The MIT License (MIT)
|
||||
/**
|
||||
* The MIT License (MIT)
|
||||
*
|
||||
* Copyright (c) 2016 by Daniel Eichhorn
|
||||
* Copyright (c) 2016 by Fabrice Weinberg
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in all
|
||||
* copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
* SOFTWARE.
|
||||
*
|
||||
* Credits for parts of this code go to Mike Rankin. Thank you so much for sharing!
|
||||
*/
|
||||
|
||||
Copyright (c) 2015 by Daniel Eichhorn
|
||||
#ifndef SSD1306_h
|
||||
#define SSD1306_h
|
||||
#include "SSD1306Wire.h"
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
// For legacy support make SSD1306 an alias for SSD1306
|
||||
typedef SSD1306Wire SSD1306;
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
||||
|
||||
See more at http://blog.squix.ch
|
||||
|
||||
Credits for parts of this code go to Mike Rankin. Thank you so much for sharing!
|
||||
*/
|
||||
#pragma once
|
||||
|
||||
#include <Arduino.h>
|
||||
#include "SSD1306Fonts.h"
|
||||
|
||||
#define BLACK 0
|
||||
#define WHITE 1
|
||||
#define INVERSE 2
|
||||
|
||||
#define WIDTH_POS 0
|
||||
#define HEIGHT_POS 1
|
||||
#define FIRST_CHAR_POS 2
|
||||
#define CHAR_NUM_POS 3
|
||||
#define CHAR_WIDTH_START_POS 4
|
||||
|
||||
#define TEXT_ALIGN_LEFT 0
|
||||
#define TEXT_ALIGN_CENTER 1
|
||||
#define TEXT_ALIGN_RIGHT 2
|
||||
|
||||
#define CHARGEPUMP 0x8D
|
||||
#define COLUMNADDR 0x21
|
||||
#define COMSCANDEC 0xC8
|
||||
#define COMSCANINC 0xC0
|
||||
#define DISPLAYALLON 0xA5
|
||||
#define DISPLAYALLON_RESUME 0xA4
|
||||
#define DISPLAYOFF 0xAE
|
||||
#define DISPLAYON 0xAF
|
||||
#define EXTERNALVCC 0x1
|
||||
#define INVERTDISPLAY 0xA7
|
||||
#define MEMORYMODE 0x20
|
||||
#define NORMALDISPLAY 0xA6
|
||||
#define PAGEADDR 0x22
|
||||
#define SEGREMAP 0xA0
|
||||
#define SETCOMPINS 0xDA
|
||||
#define SETCONTRAST 0x81
|
||||
#define SETDISPLAYCLOCKDIV 0xD5
|
||||
#define SETDISPLAYOFFSET 0xD3
|
||||
#define SETHIGHCOLUMN 0x10
|
||||
#define SETLOWCOLUMN 0x00
|
||||
#define SETMULTIPLEX 0xA8
|
||||
#define SETPRECHARGE 0xD9
|
||||
#define SETSEGMENTREMAP 0xA1
|
||||
#define SETSTARTLINE 0x40
|
||||
#define SETVCOMDETECT 0xDB
|
||||
#define SWITCHCAPVCC 0x2
|
||||
|
||||
class SSD1306 {
|
||||
|
||||
private:
|
||||
int myI2cAddress;
|
||||
int mySda;
|
||||
int mySdc;
|
||||
uint8_t buffer[128 * 64 / 8];
|
||||
int myTextAlignment = TEXT_ALIGN_LEFT;
|
||||
int myColor = WHITE;
|
||||
byte lastChar;
|
||||
const char *myFontData = ArialMT_Plain_10;
|
||||
|
||||
public:
|
||||
// Create the display object connected to pin sda and sdc
|
||||
SSD1306(int i2cAddress, int sda, int sdc);
|
||||
|
||||
// Initialize the display
|
||||
void init();
|
||||
|
||||
// Initialize the display - Neil's version to setting of address
|
||||
void init(int i2cAddress); //local override to allow init to set the address
|
||||
|
||||
// Cycle through the initialization
|
||||
void resetDisplay(void);
|
||||
|
||||
// Connect again to the display through I2C
|
||||
void reconnect(void);
|
||||
|
||||
// Turn the display on
|
||||
void displayOn(void);
|
||||
|
||||
// Turn the display offs
|
||||
void displayOff(void);
|
||||
|
||||
// Clear the local pixel buffer
|
||||
void clear(void);
|
||||
|
||||
// Write the buffer to the display memory
|
||||
void display(void);
|
||||
|
||||
// Set display contrast
|
||||
void setContrast(char contrast);
|
||||
|
||||
// Turn the display upside down
|
||||
void flipScreenVertically();
|
||||
|
||||
// Send a command to the display (low level function)
|
||||
void sendCommand(unsigned char com);
|
||||
|
||||
// Send all the init commands
|
||||
void sendInitCommands(void);
|
||||
|
||||
// Draw a pixel at given position
|
||||
void setPixel(int x, int y);
|
||||
|
||||
// Draw 8 bits at the given position
|
||||
void setChar(int x, int y, unsigned char data);
|
||||
|
||||
// Draw the border of a rectangle at the given location
|
||||
void drawRect(int x, int y, int width, int height);
|
||||
|
||||
// Fill the rectangle
|
||||
void fillRect(int x, int y, int width, int height);
|
||||
|
||||
// Draw a bitmap with the given dimensions
|
||||
void drawBitmap(int x, int y, int width, int height, const char *bitmap);
|
||||
|
||||
// Draw an XBM image with the given dimensions
|
||||
void drawXbm(int x, int y, int width, int height, const char *xbm);
|
||||
|
||||
// Sets the color of all pixel operations
|
||||
void setColor(int color);
|
||||
|
||||
// converts utf8 characters to extended ascii
|
||||
// taken from http://playground.arduino.cc/Main/Utf8ascii
|
||||
byte utf8ascii(byte ascii);
|
||||
|
||||
// converts utf8 string to extended ascii
|
||||
// taken from http://playground.arduino.cc/Main/Utf8ascii
|
||||
String utf8ascii(String s);
|
||||
|
||||
// Draws a string at the given location
|
||||
void drawString(int x, int y, String text);
|
||||
|
||||
// Draws a String with a maximum width at the given location.
|
||||
// If the given String is wider than the specified width
|
||||
// The text will be wrapped to the next line at a space or dash
|
||||
void drawStringMaxWidth(int x, int y, int maxLineWidth, String text);
|
||||
|
||||
// Returns the width of the String with the current
|
||||
// font settings
|
||||
int getStringWidth(String text);
|
||||
|
||||
// Specifies relative to which anchor point
|
||||
// the text is rendered. Available constants:
|
||||
// TEXT_ALIGN_LEFT, TEXT_ALIGN_CENTER, TEXT_ALIGN_RIGHT
|
||||
void setTextAlignment(int textAlignment);
|
||||
|
||||
// Sets the current font. Available default fonts
|
||||
// defined in SSD1306Fonts.h:
|
||||
// ArialMT_Plain_10, ArialMT_Plain_16, ArialMT_Plain_24
|
||||
void setFont(const char *fontData);
|
||||
|
||||
};
|
||||
#endif
|
||||
|
||||
@@ -0,0 +1,149 @@
|
||||
/**
|
||||
* The MIT License (MIT)
|
||||
*
|
||||
* Copyright (c) 2016 by Daniel Eichhorn
|
||||
* Copyright (c) 2016 by Fabrice Weinberg
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in all
|
||||
* copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
* SOFTWARE.
|
||||
*
|
||||
* Credits for parts of this code go to Mike Rankin. Thank you so much for sharing!
|
||||
*/
|
||||
|
||||
#ifndef SSD1306Brzo_h
|
||||
#define SSD1306Brzo_h
|
||||
|
||||
#include "OLEDDisplay.h"
|
||||
#include <brzo_i2c.h>
|
||||
|
||||
#if F_CPU == 160000000L
|
||||
#define BRZO_I2C_SPEED 1000
|
||||
#else
|
||||
#define BRZO_I2C_SPEED 800
|
||||
#endif
|
||||
|
||||
class SSD1306Brzo : public OLEDDisplay {
|
||||
private:
|
||||
uint8_t _address;
|
||||
uint8_t _sda;
|
||||
uint8_t _scl;
|
||||
|
||||
public:
|
||||
SSD1306Brzo(uint8_t _address, uint8_t _sda, uint8_t _scl) {
|
||||
this->_address = _address;
|
||||
this->_sda = _sda;
|
||||
this->_scl = _scl;
|
||||
}
|
||||
|
||||
bool connect(){
|
||||
brzo_i2c_setup(_sda, _scl, 0);
|
||||
return true;
|
||||
}
|
||||
|
||||
void display(void) {
|
||||
#ifdef OLEDDISPLAY_DOUBLE_BUFFER
|
||||
uint8_t minBoundY = ~0;
|
||||
uint8_t maxBoundY = 0;
|
||||
|
||||
uint8_t minBoundX = ~0;
|
||||
uint8_t maxBoundX = 0;
|
||||
|
||||
uint8_t x, y;
|
||||
|
||||
// Calculate the Y bounding box of changes
|
||||
// and copy buffer[pos] to buffer_back[pos];
|
||||
for (y = 0; y < (DISPLAY_HEIGHT / 8); y++) {
|
||||
for (x = 0; x < DISPLAY_WIDTH; x++) {
|
||||
uint16_t pos = x + y * DISPLAY_WIDTH;
|
||||
if (buffer[pos] != buffer_back[pos]) {
|
||||
minBoundY = _min(minBoundY, y);
|
||||
maxBoundY = _max(maxBoundY, y);
|
||||
minBoundX = _min(minBoundX, x);
|
||||
maxBoundX = _max(maxBoundX, x);
|
||||
}
|
||||
buffer_back[pos] = buffer[pos];
|
||||
}
|
||||
yield();
|
||||
}
|
||||
|
||||
// If the minBoundY wasn't updated
|
||||
// we can savely assume that buffer_back[pos] == buffer[pos]
|
||||
// holdes true for all values of pos
|
||||
if (minBoundY == ~0) return;
|
||||
|
||||
sendCommand(COLUMNADDR);
|
||||
sendCommand(minBoundX);
|
||||
sendCommand(maxBoundX);
|
||||
|
||||
sendCommand(PAGEADDR);
|
||||
sendCommand(minBoundY);
|
||||
sendCommand(maxBoundY);
|
||||
|
||||
byte k = 0;
|
||||
uint8_t sendBuffer[17];
|
||||
sendBuffer[0] = 0x40;
|
||||
brzo_i2c_start_transaction(this->_address, BRZO_I2C_SPEED);
|
||||
for (y = minBoundY; y <= maxBoundY; y++) {
|
||||
for (x = minBoundX; x <= maxBoundX; x++) {
|
||||
k++;
|
||||
sendBuffer[k] = buffer[x + y * DISPLAY_WIDTH];
|
||||
if (k == 16) {
|
||||
brzo_i2c_write(sendBuffer, 17, true);
|
||||
k = 0;
|
||||
}
|
||||
}
|
||||
yield();
|
||||
}
|
||||
brzo_i2c_write(sendBuffer, k + 1, true);
|
||||
brzo_i2c_end_transaction();
|
||||
#else
|
||||
// No double buffering
|
||||
sendCommand(COLUMNADDR);
|
||||
sendCommand(0x0);
|
||||
sendCommand(0x7F);
|
||||
|
||||
sendCommand(PAGEADDR);
|
||||
sendCommand(0x0);
|
||||
sendCommand(0x7);
|
||||
|
||||
uint8_t sendBuffer[17];
|
||||
sendBuffer[0] = 0x40;
|
||||
brzo_i2c_start_transaction(this->_address, BRZO_I2C_SPEED);
|
||||
for (uint16_t i=0; i<DISPLAY_BUFFER_SIZE; i++) {
|
||||
for (uint8_t x=1; x<17; x++) {
|
||||
sendBuffer[x] = buffer[i];
|
||||
i++;
|
||||
}
|
||||
i--;
|
||||
brzo_i2c_write(sendBuffer, 17, true);
|
||||
yield();
|
||||
}
|
||||
brzo_i2c_end_transaction();
|
||||
#endif
|
||||
}
|
||||
|
||||
private:
|
||||
inline void sendCommand(uint8_t com) __attribute__((always_inline)){
|
||||
uint8_t command[2] = {0x80 /* command mode */, com};
|
||||
brzo_i2c_start_transaction(_address, BRZO_I2C_SPEED);
|
||||
brzo_i2c_write(command, 2, true);
|
||||
brzo_i2c_end_transaction();
|
||||
}
|
||||
};
|
||||
|
||||
#endif
|
||||
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,150 @@
|
||||
/**
|
||||
* The MIT License (MIT)
|
||||
*
|
||||
* Copyright (c) 2016 by Daniel Eichhorn
|
||||
* Copyright (c) 2016 by Fabrice Weinberg
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in all
|
||||
* copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
* SOFTWARE.
|
||||
*
|
||||
* Credits for parts of this code go to Mike Rankin. Thank you so much for sharing!
|
||||
*/
|
||||
|
||||
#ifndef SSD1306Spi_h
|
||||
#define SSD1306Spi_h
|
||||
|
||||
#include "OLEDDisplay.h"
|
||||
#include <SPI.h>
|
||||
|
||||
#if F_CPU == 160000000L
|
||||
#define BRZO_I2C_SPEED 1000
|
||||
#else
|
||||
#define BRZO_I2C_SPEED 800
|
||||
#endif
|
||||
|
||||
class SSD1306Spi : public OLEDDisplay {
|
||||
private:
|
||||
uint8_t _rst;
|
||||
uint8_t _dc;
|
||||
uint8_t _cs;
|
||||
|
||||
public:
|
||||
SSD1306Spi(uint8_t _rst, uint8_t _dc, uint8_t _cs) {
|
||||
this->_rst = _rst;
|
||||
this->_dc = _dc;
|
||||
this->_cs = _cs;
|
||||
}
|
||||
|
||||
bool connect(){
|
||||
pinMode(_dc, OUTPUT);
|
||||
pinMode(_cs, OUTPUT);
|
||||
pinMode(_rst, OUTPUT);
|
||||
|
||||
SPI.begin ();
|
||||
SPI.setClockDivider (SPI_CLOCK_DIV2);
|
||||
|
||||
// Pulse Reset low for 10ms
|
||||
digitalWrite(_rst, HIGH);
|
||||
delay(1);
|
||||
digitalWrite(_rst, LOW);
|
||||
delay(10);
|
||||
digitalWrite(_rst, HIGH);
|
||||
return true;
|
||||
}
|
||||
|
||||
void display(void) {
|
||||
#ifdef OLEDDISPLAY_DOUBLE_BUFFER
|
||||
uint8_t minBoundY = ~0;
|
||||
uint8_t maxBoundY = 0;
|
||||
|
||||
uint8_t minBoundX = ~0;
|
||||
uint8_t maxBoundX = 0;
|
||||
|
||||
uint8_t x, y;
|
||||
|
||||
// Calculate the Y bounding box of changes
|
||||
// and copy buffer[pos] to buffer_back[pos];
|
||||
for (y = 0; y < (DISPLAY_HEIGHT / 8); y++) {
|
||||
for (x = 0; x < DISPLAY_WIDTH; x++) {
|
||||
uint16_t pos = x + y * DISPLAY_WIDTH;
|
||||
if (buffer[pos] != buffer_back[pos]) {
|
||||
minBoundY = _min(minBoundY, y);
|
||||
maxBoundY = _max(maxBoundY, y);
|
||||
minBoundX = _min(minBoundX, x);
|
||||
maxBoundX = _max(maxBoundX, x);
|
||||
}
|
||||
buffer_back[pos] = buffer[pos];
|
||||
}
|
||||
yield();
|
||||
}
|
||||
|
||||
// If the minBoundY wasn't updated
|
||||
// we can savely assume that buffer_back[pos] == buffer[pos]
|
||||
// holdes true for all values of pos
|
||||
if (minBoundY == ~0) return;
|
||||
|
||||
sendCommand(COLUMNADDR);
|
||||
sendCommand(minBoundX);
|
||||
sendCommand(maxBoundX);
|
||||
|
||||
sendCommand(PAGEADDR);
|
||||
sendCommand(minBoundY);
|
||||
sendCommand(maxBoundY);
|
||||
|
||||
digitalWrite(_cs, HIGH);
|
||||
digitalWrite(_dc, HIGH); // data mode
|
||||
digitalWrite(_cs, LOW);
|
||||
for (y = minBoundY; y <= maxBoundY; y++) {
|
||||
for (x = minBoundX; x <= maxBoundX; x++) {
|
||||
SPI.transfer(buffer[x + y * DISPLAY_WIDTH]);
|
||||
}
|
||||
yield();
|
||||
}
|
||||
digitalWrite(_cs, HIGH);
|
||||
#else
|
||||
// No double buffering
|
||||
sendCommand(COLUMNADDR);
|
||||
sendCommand(0x0);
|
||||
sendCommand(0x7F);
|
||||
|
||||
sendCommand(PAGEADDR);
|
||||
sendCommand(0x0);
|
||||
sendCommand(0x7);
|
||||
|
||||
digitalWrite(_cs, HIGH);
|
||||
digitalWrite(_dc, HIGH); // data mode
|
||||
digitalWrite(_cs, LOW);
|
||||
for (uint16_t i=0; i<DISPLAY_BUFFER_SIZE; i++) {
|
||||
SPI.transfer(buffer[i]);
|
||||
yield();
|
||||
}
|
||||
digitalWrite(_cs, HIGH);
|
||||
#endif
|
||||
}
|
||||
|
||||
private:
|
||||
inline void sendCommand(uint8_t com) __attribute__((always_inline)){
|
||||
digitalWrite(_cs, HIGH);
|
||||
digitalWrite(_dc, LOW);
|
||||
digitalWrite(_cs, LOW);
|
||||
SPI.transfer(com);
|
||||
digitalWrite(_cs, HIGH);
|
||||
}
|
||||
};
|
||||
|
||||
#endif
|
||||
@@ -1,247 +0,0 @@
|
||||
#include "SSD1306Ui.h"
|
||||
|
||||
|
||||
SSD1306Ui::SSD1306Ui(SSD1306 *display) {
|
||||
this->display = display;
|
||||
}
|
||||
|
||||
void SSD1306Ui::init() {
|
||||
this->display->init();
|
||||
}
|
||||
|
||||
void SSD1306Ui::setTargetFPS(byte fps){
|
||||
int oldInterval = this->updateInterval;
|
||||
this->updateInterval = ((float) 1.0 / (float) fps) * 1000;
|
||||
|
||||
// Calculate new ticksPerFrame
|
||||
float changeRatio = oldInterval / this->updateInterval;
|
||||
this->ticksPerFrame *= changeRatio;
|
||||
this->ticksPerTransition *= changeRatio;
|
||||
}
|
||||
|
||||
// -/------ Automatic controll ------\-
|
||||
|
||||
void SSD1306Ui::enableAutoTransition(){
|
||||
this->autoTransition = true;
|
||||
}
|
||||
void SSD1306Ui::disableAutoTransition(){
|
||||
this->autoTransition = false;
|
||||
}
|
||||
void SSD1306Ui::setAutoTransitionForwards(){
|
||||
this->frameTransitionDirection = 1;
|
||||
}
|
||||
void SSD1306Ui::setAutoTransitionBackwards(){
|
||||
this->frameTransitionDirection = 1;
|
||||
}
|
||||
void SSD1306Ui::setTimePerFrame(int time){
|
||||
this->ticksPerFrame = (int) ( (float) time / (float) updateInterval);
|
||||
}
|
||||
void SSD1306Ui::setTimePerTransition(int time){
|
||||
this->ticksPerTransition = (int) ( (float) time / (float) updateInterval);
|
||||
}
|
||||
|
||||
|
||||
// -/------ Customize indicator position and style -------\-
|
||||
void SSD1306Ui::setIndicatorPosition(IndicatorPosition pos) {
|
||||
this->indicatorPosition = pos;
|
||||
this->dirty = true;
|
||||
}
|
||||
void SSD1306Ui::setIndicatorDirection(IndicatorDirection dir) {
|
||||
this->indicatorDirection = dir;
|
||||
}
|
||||
void SSD1306Ui::setActiveSymbole(const char* symbole) {
|
||||
this->activeSymbole = symbole;
|
||||
this->dirty = true;
|
||||
}
|
||||
void SSD1306Ui::setInactiveSymbole(const char* symbole) {
|
||||
this->inactiveSymbole = symbole;
|
||||
this->dirty = true;
|
||||
}
|
||||
|
||||
|
||||
// -/----- Frame settings -----\-
|
||||
void SSD1306Ui::setFrameAnimation(AnimationDirection dir) {
|
||||
this->frameAnimationDirection = dir;
|
||||
}
|
||||
void SSD1306Ui::setFrames(FrameCallback* frameFunctions, int frameCount) {
|
||||
this->frameCount = frameCount;
|
||||
this->frameFunctions = frameFunctions;
|
||||
}
|
||||
|
||||
// -/----- Overlays ------\-
|
||||
void SSD1306Ui::setOverlays(OverlayCallback* overlayFunctions, int overlayCount){
|
||||
this->overlayCount = overlayCount;
|
||||
this->overlayFunctions = overlayFunctions;
|
||||
}
|
||||
|
||||
|
||||
// -/----- Manuel control -----\-
|
||||
void SSD1306Ui::nextFrame() {
|
||||
this->state.frameState = IN_TRANSITION;
|
||||
this->state.ticksSinceLastStateSwitch = 0;
|
||||
this->frameTransitionDirection = 1;
|
||||
}
|
||||
void SSD1306Ui::previousFrame() {
|
||||
this->state.frameState = IN_TRANSITION;
|
||||
this->state.ticksSinceLastStateSwitch = 0;
|
||||
this->frameTransitionDirection = -1;
|
||||
}
|
||||
|
||||
|
||||
// -/----- State information -----\-
|
||||
SSD1306UiState SSD1306Ui::getUiState(){
|
||||
return this->state;
|
||||
}
|
||||
|
||||
|
||||
int SSD1306Ui::update(){
|
||||
int timeBudget = this->updateInterval - (millis() - this->state.lastUpdate);
|
||||
if ( timeBudget <= 0) {
|
||||
// Implement frame skipping to ensure time budget is keept
|
||||
if (this->autoTransition && this->state.lastUpdate != 0) this->state.ticksSinceLastStateSwitch += ceil(-timeBudget / this->updateInterval);
|
||||
|
||||
this->state.lastUpdate = millis();
|
||||
this->tick();
|
||||
}
|
||||
return timeBudget;
|
||||
}
|
||||
|
||||
|
||||
void SSD1306Ui::tick() {
|
||||
this->state.ticksSinceLastStateSwitch++;
|
||||
|
||||
switch (this->state.frameState) {
|
||||
case IN_TRANSITION:
|
||||
this->dirty = true;
|
||||
if (this->state.ticksSinceLastStateSwitch >= this->ticksPerTransition){
|
||||
this->state.frameState = FIXED;
|
||||
this->state.currentFrame = getNextFrameNumber();
|
||||
this->state.ticksSinceLastStateSwitch = 0;
|
||||
}
|
||||
break;
|
||||
case FIXED:
|
||||
if (this->state.ticksSinceLastStateSwitch >= this->ticksPerFrame){
|
||||
if (this->autoTransition){
|
||||
this->state.frameState = IN_TRANSITION;
|
||||
this->dirty = true;
|
||||
}
|
||||
this->state.ticksSinceLastStateSwitch = 0;
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
if (this->dirty) {
|
||||
this->dirty = false;
|
||||
this->display->clear();
|
||||
this->drawIndicator();
|
||||
this->drawFrame();
|
||||
this->drawOverlays();
|
||||
this->display->display();
|
||||
}
|
||||
}
|
||||
|
||||
void SSD1306Ui::drawFrame(){
|
||||
switch (this->state.frameState){
|
||||
case IN_TRANSITION: {
|
||||
float progress = (float) this->state.ticksSinceLastStateSwitch / (float) this->ticksPerTransition;
|
||||
int x, y, x1, y1;
|
||||
switch(this->frameAnimationDirection){
|
||||
case SLIDE_LEFT:
|
||||
x = -128 * progress;
|
||||
y = 0;
|
||||
x1 = x + 128;
|
||||
y1 = 0;
|
||||
break;
|
||||
case SLIDE_RIGHT:
|
||||
x = 128 * progress;
|
||||
y = 0;
|
||||
x1 = x - 128;
|
||||
y1 = 0;
|
||||
break;
|
||||
case SLIDE_UP:
|
||||
x = 0;
|
||||
y = -64 * progress;
|
||||
x1 = 0;
|
||||
y1 = y + 64;
|
||||
break;
|
||||
case SLIDE_DOWN:
|
||||
x = 0;
|
||||
y = 64 * progress;
|
||||
x1 = 0;
|
||||
y1 = y - 64;
|
||||
break;
|
||||
}
|
||||
|
||||
// Invert animation if direction is reversed.
|
||||
int dir = frameTransitionDirection >= 0 ? 1 : -1;
|
||||
x *= dir; y *= dir; x1 *= dir; y1 *= dir;
|
||||
|
||||
this->dirty |= (this->frameFunctions[this->state.currentFrame])(this->display, &this->state, x, y);
|
||||
this->dirty |= (this->frameFunctions[this->getNextFrameNumber()])(this->display, &this->state, x1, y1);
|
||||
break;
|
||||
}
|
||||
case FIXED:
|
||||
this->dirty |= (this->frameFunctions[this->state.currentFrame])(this->display, &this->state, 0, 0);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
void SSD1306Ui::drawIndicator() {
|
||||
byte posOfCurrentFrame;
|
||||
|
||||
switch (this->indicatorDirection){
|
||||
case LEFT_RIGHT:
|
||||
posOfCurrentFrame = this->state.currentFrame;
|
||||
break;
|
||||
case RIGHT_LEFT:
|
||||
posOfCurrentFrame = (this->frameCount - 1) - this->state.currentFrame;
|
||||
break;
|
||||
}
|
||||
|
||||
for (byte i = 0; i < this->frameCount; i++) {
|
||||
|
||||
const char *image;
|
||||
|
||||
if (posOfCurrentFrame == i) {
|
||||
image = this->activeSymbole;
|
||||
} else {
|
||||
image = this->inactiveSymbole;
|
||||
}
|
||||
|
||||
int x,y;
|
||||
switch (this->indicatorPosition){
|
||||
case TOP:
|
||||
y = 0;
|
||||
x = 64 - (12 * frameCount / 2) + 12 * i;
|
||||
break;
|
||||
case BOTTOM:
|
||||
y = 56;
|
||||
x = 64 - (12 * frameCount / 2) + 12 * i;
|
||||
break;
|
||||
case RIGHT:
|
||||
x = 120;
|
||||
y = 32 - (12 * frameCount / 2) + 12 * i;
|
||||
break;
|
||||
case LEFT:
|
||||
x = 0;
|
||||
y = 32 - (12 * frameCount / 2) + 12 * i;
|
||||
break;
|
||||
}
|
||||
|
||||
this->display->drawXbm(x, y, 8, 8, image);
|
||||
}
|
||||
}
|
||||
|
||||
void SSD1306Ui::drawOverlays() {
|
||||
for (int i=0;i<this->overlayCount;i++){
|
||||
this->dirty |= (this->overlayFunctions[i])(this->display, &this->state);
|
||||
}
|
||||
}
|
||||
|
||||
int SSD1306Ui::getNextFrameNumber(){
|
||||
int nextFrame = (this->state.currentFrame + this->frameTransitionDirection) % this->frameCount;
|
||||
if (nextFrame < 0){
|
||||
nextFrame = this->frameCount + nextFrame;
|
||||
}
|
||||
return nextFrame;
|
||||
}
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user