arduino_ci 0.1.3 → 0.1.4

Sign up to get free protection for your applications and to get access to all the features.
Files changed (295) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +77 -1
  3. data/cpp/arduino/Arduino.cpp +17 -7
  4. data/cpp/arduino/Arduino.h +151 -5
  5. data/cpp/arduino/ArduinoDefines.h +90 -0
  6. data/cpp/arduino/AvrMath.h +18 -28
  7. data/cpp/arduino/Godmode.cpp +62 -0
  8. data/cpp/arduino/Godmode.h +74 -0
  9. data/cpp/arduino/HardwareSerial.h +81 -0
  10. data/cpp/arduino/Print.h +67 -0
  11. data/cpp/arduino/Stream.h +210 -0
  12. data/cpp/arduino/WCharacter.h +96 -0
  13. data/cpp/arduino/WString.h +164 -0
  14. data/cpp/arduino/binary.h +518 -0
  15. data/cpp/arduino/include/README.md +3 -0
  16. data/cpp/arduino/include/common.h +333 -0
  17. data/cpp/arduino/include/fuse.h +274 -0
  18. data/cpp/arduino/include/io.h +643 -0
  19. data/cpp/arduino/include/io1200.h +274 -0
  20. data/cpp/arduino/include/io2313.h +385 -0
  21. data/cpp/arduino/include/io2323.h +210 -0
  22. data/cpp/arduino/include/io2333.h +461 -0
  23. data/cpp/arduino/include/io2343.h +214 -0
  24. data/cpp/arduino/include/io43u32x.h +440 -0
  25. data/cpp/arduino/include/io43u35x.h +432 -0
  26. data/cpp/arduino/include/io4414.h +500 -0
  27. data/cpp/arduino/include/io4433.h +489 -0
  28. data/cpp/arduino/include/io4434.h +588 -0
  29. data/cpp/arduino/include/io76c711.h +499 -0
  30. data/cpp/arduino/include/io8515.h +501 -0
  31. data/cpp/arduino/include/io8534.h +217 -0
  32. data/cpp/arduino/include/io8535.h +589 -0
  33. data/cpp/arduino/include/io86r401.h +309 -0
  34. data/cpp/arduino/include/io90pwm1.h +1157 -0
  35. data/cpp/arduino/include/io90pwm161.h +918 -0
  36. data/cpp/arduino/include/io90pwm216.h +1225 -0
  37. data/cpp/arduino/include/io90pwm2b.h +1466 -0
  38. data/cpp/arduino/include/io90pwm316.h +1272 -0
  39. data/cpp/arduino/include/io90pwm3b.h +1466 -0
  40. data/cpp/arduino/include/io90pwm81.h +1036 -0
  41. data/cpp/arduino/include/io90pwmx.h +1415 -0
  42. data/cpp/arduino/include/io90scr100.h +1719 -0
  43. data/cpp/arduino/include/ioa5272.h +803 -0
  44. data/cpp/arduino/include/ioa5505.h +803 -0
  45. data/cpp/arduino/include/ioa5702m322.h +2591 -0
  46. data/cpp/arduino/include/ioa5782.h +1843 -0
  47. data/cpp/arduino/include/ioa5790.h +907 -0
  48. data/cpp/arduino/include/ioa5790n.h +922 -0
  49. data/cpp/arduino/include/ioa5791.h +923 -0
  50. data/cpp/arduino/include/ioa5795.h +756 -0
  51. data/cpp/arduino/include/ioa5831.h +1949 -0
  52. data/cpp/arduino/include/ioa6285.h +740 -0
  53. data/cpp/arduino/include/ioa6286.h +740 -0
  54. data/cpp/arduino/include/ioa6289.h +847 -0
  55. data/cpp/arduino/include/ioa6612c.h +795 -0
  56. data/cpp/arduino/include/ioa6613c.h +795 -0
  57. data/cpp/arduino/include/ioa6614q.h +798 -0
  58. data/cpp/arduino/include/ioa6616c.h +865 -0
  59. data/cpp/arduino/include/ioa6617c.h +865 -0
  60. data/cpp/arduino/include/ioa664251.h +857 -0
  61. data/cpp/arduino/include/ioa8210.h +1843 -0
  62. data/cpp/arduino/include/ioa8510.h +1949 -0
  63. data/cpp/arduino/include/ioat94k.h +565 -0
  64. data/cpp/arduino/include/iocan128.h +100 -0
  65. data/cpp/arduino/include/iocan32.h +100 -0
  66. data/cpp/arduino/include/iocan64.h +100 -0
  67. data/cpp/arduino/include/iocanxx.h +2020 -0
  68. data/cpp/arduino/include/iom103.h +735 -0
  69. data/cpp/arduino/include/iom128.h +1299 -0
  70. data/cpp/arduino/include/iom1280.h +101 -0
  71. data/cpp/arduino/include/iom1281.h +101 -0
  72. data/cpp/arduino/include/iom1284.h +1099 -0
  73. data/cpp/arduino/include/iom1284p.h +1219 -0
  74. data/cpp/arduino/include/iom1284rfr2.h +2690 -0
  75. data/cpp/arduino/include/iom128a.h +1070 -0
  76. data/cpp/arduino/include/iom128rfa1.h +5385 -0
  77. data/cpp/arduino/include/iom128rfr2.h +2706 -0
  78. data/cpp/arduino/include/iom16.h +676 -0
  79. data/cpp/arduino/include/iom161.h +726 -0
  80. data/cpp/arduino/include/iom162.h +1022 -0
  81. data/cpp/arduino/include/iom163.h +686 -0
  82. data/cpp/arduino/include/iom164.h +101 -0
  83. data/cpp/arduino/include/iom164a.h +34 -0
  84. data/cpp/arduino/include/iom164p.h +34 -0
  85. data/cpp/arduino/include/iom164pa.h +1016 -0
  86. data/cpp/arduino/include/iom165.h +887 -0
  87. data/cpp/arduino/include/iom165a.h +832 -0
  88. data/cpp/arduino/include/iom165p.h +889 -0
  89. data/cpp/arduino/include/iom165pa.h +948 -0
  90. data/cpp/arduino/include/iom168.h +97 -0
  91. data/cpp/arduino/include/iom168a.h +35 -0
  92. data/cpp/arduino/include/iom168p.h +942 -0
  93. data/cpp/arduino/include/iom168pa.h +843 -0
  94. data/cpp/arduino/include/iom168pb.h +899 -0
  95. data/cpp/arduino/include/iom169.h +1174 -0
  96. data/cpp/arduino/include/iom169a.h +44 -0
  97. data/cpp/arduino/include/iom169p.h +1097 -0
  98. data/cpp/arduino/include/iom169pa.h +1485 -0
  99. data/cpp/arduino/include/iom16a.h +923 -0
  100. data/cpp/arduino/include/iom16hva.h +80 -0
  101. data/cpp/arduino/include/iom16hva2.h +883 -0
  102. data/cpp/arduino/include/iom16hvb.h +1052 -0
  103. data/cpp/arduino/include/iom16hvbrevb.h +1052 -0
  104. data/cpp/arduino/include/iom16m1.h +1571 -0
  105. data/cpp/arduino/include/iom16u2.h +1000 -0
  106. data/cpp/arduino/include/iom16u4.h +1423 -0
  107. data/cpp/arduino/include/iom2560.h +101 -0
  108. data/cpp/arduino/include/iom2561.h +101 -0
  109. data/cpp/arduino/include/iom2564rfr2.h +2691 -0
  110. data/cpp/arduino/include/iom256rfr2.h +2707 -0
  111. data/cpp/arduino/include/iom3000.h +237 -0
  112. data/cpp/arduino/include/iom32.h +755 -0
  113. data/cpp/arduino/include/iom323.h +744 -0
  114. data/cpp/arduino/include/iom324a.h +1014 -0
  115. data/cpp/arduino/include/iom324p.h +1016 -0
  116. data/cpp/arduino/include/iom324pa.h +1372 -0
  117. data/cpp/arduino/include/iom325.h +886 -0
  118. data/cpp/arduino/include/iom3250.h +982 -0
  119. data/cpp/arduino/include/iom3250a.h +34 -0
  120. data/cpp/arduino/include/iom3250p.h +34 -0
  121. data/cpp/arduino/include/iom3250pa.h +1042 -0
  122. data/cpp/arduino/include/iom325a.h +34 -0
  123. data/cpp/arduino/include/iom325p.h +34 -0
  124. data/cpp/arduino/include/iom325pa.h +937 -0
  125. data/cpp/arduino/include/iom328.h +34 -0
  126. data/cpp/arduino/include/iom328p.h +948 -0
  127. data/cpp/arduino/include/iom329.h +1069 -0
  128. data/cpp/arduino/include/iom3290.h +1227 -0
  129. data/cpp/arduino/include/iom3290a.h +34 -0
  130. data/cpp/arduino/include/iom3290pa.h +1123 -0
  131. data/cpp/arduino/include/iom329a.h +34 -0
  132. data/cpp/arduino/include/iom329p.h +1164 -0
  133. data/cpp/arduino/include/iom329pa.h +34 -0
  134. data/cpp/arduino/include/iom32a.h +686 -0
  135. data/cpp/arduino/include/iom32c1.h +1320 -0
  136. data/cpp/arduino/include/iom32hvb.h +1052 -0
  137. data/cpp/arduino/include/iom32hvbrevb.h +953 -0
  138. data/cpp/arduino/include/iom32m1.h +1625 -0
  139. data/cpp/arduino/include/iom32u2.h +1000 -0
  140. data/cpp/arduino/include/iom32u4.h +1512 -0
  141. data/cpp/arduino/include/iom32u6.h +1431 -0
  142. data/cpp/arduino/include/iom406.h +783 -0
  143. data/cpp/arduino/include/iom48.h +93 -0
  144. data/cpp/arduino/include/iom48a.h +35 -0
  145. data/cpp/arduino/include/iom48p.h +936 -0
  146. data/cpp/arduino/include/iom48pa.h +839 -0
  147. data/cpp/arduino/include/iom48pb.h +890 -0
  148. data/cpp/arduino/include/iom64.h +1311 -0
  149. data/cpp/arduino/include/iom640.h +101 -0
  150. data/cpp/arduino/include/iom644.h +101 -0
  151. data/cpp/arduino/include/iom644a.h +34 -0
  152. data/cpp/arduino/include/iom644p.h +101 -0
  153. data/cpp/arduino/include/iom644pa.h +1387 -0
  154. data/cpp/arduino/include/iom644rfr2.h +2685 -0
  155. data/cpp/arduino/include/iom645.h +881 -0
  156. data/cpp/arduino/include/iom6450.h +978 -0
  157. data/cpp/arduino/include/iom6450a.h +34 -0
  158. data/cpp/arduino/include/iom6450p.h +34 -0
  159. data/cpp/arduino/include/iom645a.h +34 -0
  160. data/cpp/arduino/include/iom645p.h +34 -0
  161. data/cpp/arduino/include/iom649.h +1061 -0
  162. data/cpp/arduino/include/iom6490.h +1182 -0
  163. data/cpp/arduino/include/iom6490a.h +34 -0
  164. data/cpp/arduino/include/iom6490p.h +34 -0
  165. data/cpp/arduino/include/iom649a.h +34 -0
  166. data/cpp/arduino/include/iom649p.h +1490 -0
  167. data/cpp/arduino/include/iom64a.h +1084 -0
  168. data/cpp/arduino/include/iom64c1.h +1321 -0
  169. data/cpp/arduino/include/iom64hve.h +1034 -0
  170. data/cpp/arduino/include/iom64hve2.h +767 -0
  171. data/cpp/arduino/include/iom64m1.h +1572 -0
  172. data/cpp/arduino/include/iom64rfr2.h +2701 -0
  173. data/cpp/arduino/include/iom8.h +665 -0
  174. data/cpp/arduino/include/iom8515.h +687 -0
  175. data/cpp/arduino/include/iom8535.h +772 -0
  176. data/cpp/arduino/include/iom88.h +97 -0
  177. data/cpp/arduino/include/iom88a.h +35 -0
  178. data/cpp/arduino/include/iom88p.h +941 -0
  179. data/cpp/arduino/include/iom88pa.h +1185 -0
  180. data/cpp/arduino/include/iom88pb.h +899 -0
  181. data/cpp/arduino/include/iom8a.h +621 -0
  182. data/cpp/arduino/include/iom8hva.h +76 -0
  183. data/cpp/arduino/include/iom8u2.h +997 -0
  184. data/cpp/arduino/include/iomx8.h +808 -0
  185. data/cpp/arduino/include/iomxx0_1.h +1692 -0
  186. data/cpp/arduino/include/iomxx4.h +954 -0
  187. data/cpp/arduino/include/iomxxhva.h +550 -0
  188. data/cpp/arduino/include/iotn10.h +512 -0
  189. data/cpp/arduino/include/iotn11.h +255 -0
  190. data/cpp/arduino/include/iotn12.h +288 -0
  191. data/cpp/arduino/include/iotn13.h +395 -0
  192. data/cpp/arduino/include/iotn13a.h +394 -0
  193. data/cpp/arduino/include/iotn15.h +363 -0
  194. data/cpp/arduino/include/iotn1634.h +914 -0
  195. data/cpp/arduino/include/iotn167.h +883 -0
  196. data/cpp/arduino/include/iotn20.h +776 -0
  197. data/cpp/arduino/include/iotn22.h +221 -0
  198. data/cpp/arduino/include/iotn2313.h +702 -0
  199. data/cpp/arduino/include/iotn2313a.h +812 -0
  200. data/cpp/arduino/include/iotn24.h +94 -0
  201. data/cpp/arduino/include/iotn24a.h +846 -0
  202. data/cpp/arduino/include/iotn25.h +93 -0
  203. data/cpp/arduino/include/iotn26.h +422 -0
  204. data/cpp/arduino/include/iotn261.h +93 -0
  205. data/cpp/arduino/include/iotn261a.h +987 -0
  206. data/cpp/arduino/include/iotn28.h +297 -0
  207. data/cpp/arduino/include/iotn4.h +477 -0
  208. data/cpp/arduino/include/iotn40.h +767 -0
  209. data/cpp/arduino/include/iotn4313.h +813 -0
  210. data/cpp/arduino/include/iotn43u.h +604 -0
  211. data/cpp/arduino/include/iotn44.h +94 -0
  212. data/cpp/arduino/include/iotn441.h +903 -0
  213. data/cpp/arduino/include/iotn44a.h +844 -0
  214. data/cpp/arduino/include/iotn45.h +93 -0
  215. data/cpp/arduino/include/iotn461.h +94 -0
  216. data/cpp/arduino/include/iotn461a.h +987 -0
  217. data/cpp/arduino/include/iotn48.h +806 -0
  218. data/cpp/arduino/include/iotn5.h +512 -0
  219. data/cpp/arduino/include/iotn828.h +911 -0
  220. data/cpp/arduino/include/iotn84.h +94 -0
  221. data/cpp/arduino/include/iotn841.h +903 -0
  222. data/cpp/arduino/include/iotn84a.h +844 -0
  223. data/cpp/arduino/include/iotn85.h +93 -0
  224. data/cpp/arduino/include/iotn861.h +94 -0
  225. data/cpp/arduino/include/iotn861a.h +988 -0
  226. data/cpp/arduino/include/iotn87.h +859 -0
  227. data/cpp/arduino/include/iotn88.h +806 -0
  228. data/cpp/arduino/include/iotn9.h +477 -0
  229. data/cpp/arduino/include/iotnx4.h +482 -0
  230. data/cpp/arduino/include/iotnx5.h +442 -0
  231. data/cpp/arduino/include/iotnx61.h +541 -0
  232. data/cpp/arduino/include/iousb1286.h +101 -0
  233. data/cpp/arduino/include/iousb1287.h +101 -0
  234. data/cpp/arduino/include/iousb162.h +101 -0
  235. data/cpp/arduino/include/iousb646.h +102 -0
  236. data/cpp/arduino/include/iousb647.h +102 -0
  237. data/cpp/arduino/include/iousb82.h +95 -0
  238. data/cpp/arduino/include/iousbxx2.h +807 -0
  239. data/cpp/arduino/include/iousbxx6_7.h +1336 -0
  240. data/cpp/arduino/include/iox128a1.h +7236 -0
  241. data/cpp/arduino/include/iox128a1u.h +8305 -0
  242. data/cpp/arduino/include/iox128a3.h +6987 -0
  243. data/cpp/arduino/include/iox128a3u.h +7697 -0
  244. data/cpp/arduino/include/iox128a4u.h +7309 -0
  245. data/cpp/arduino/include/iox128b1.h +6872 -0
  246. data/cpp/arduino/include/iox128b3.h +6288 -0
  247. data/cpp/arduino/include/iox128c3.h +6264 -0
  248. data/cpp/arduino/include/iox128d3.h +5749 -0
  249. data/cpp/arduino/include/iox128d4.h +5562 -0
  250. data/cpp/arduino/include/iox16a4.h +6748 -0
  251. data/cpp/arduino/include/iox16a4u.h +7309 -0
  252. data/cpp/arduino/include/iox16c4.h +6078 -0
  253. data/cpp/arduino/include/iox16d4.h +5717 -0
  254. data/cpp/arduino/include/iox16e5.h +7699 -0
  255. data/cpp/arduino/include/iox192a3.h +6987 -0
  256. data/cpp/arduino/include/iox192a3u.h +7697 -0
  257. data/cpp/arduino/include/iox192c3.h +6264 -0
  258. data/cpp/arduino/include/iox192d3.h +5749 -0
  259. data/cpp/arduino/include/iox256a3.h +6987 -0
  260. data/cpp/arduino/include/iox256a3b.h +6983 -0
  261. data/cpp/arduino/include/iox256a3bu.h +7706 -0
  262. data/cpp/arduino/include/iox256a3u.h +7697 -0
  263. data/cpp/arduino/include/iox256c3.h +6264 -0
  264. data/cpp/arduino/include/iox256d3.h +5709 -0
  265. data/cpp/arduino/include/iox32a4.h +6747 -0
  266. data/cpp/arduino/include/iox32a4u.h +7309 -0
  267. data/cpp/arduino/include/iox32c3.h +6264 -0
  268. data/cpp/arduino/include/iox32c4.h +6078 -0
  269. data/cpp/arduino/include/iox32d3.h +5105 -0
  270. data/cpp/arduino/include/iox32d4.h +5685 -0
  271. data/cpp/arduino/include/iox32e5.h +7699 -0
  272. data/cpp/arduino/include/iox384c3.h +6849 -0
  273. data/cpp/arduino/include/iox384d3.h +5833 -0
  274. data/cpp/arduino/include/iox64a1.h +7236 -0
  275. data/cpp/arduino/include/iox64a1u.h +8305 -0
  276. data/cpp/arduino/include/iox64a3.h +6987 -0
  277. data/cpp/arduino/include/iox64a3u.h +7697 -0
  278. data/cpp/arduino/include/iox64a4u.h +7309 -0
  279. data/cpp/arduino/include/iox64b1.h +6454 -0
  280. data/cpp/arduino/include/iox64b3.h +6288 -0
  281. data/cpp/arduino/include/iox64c3.h +6264 -0
  282. data/cpp/arduino/include/iox64d3.h +5764 -0
  283. data/cpp/arduino/include/iox64d4.h +5555 -0
  284. data/cpp/arduino/include/iox8e5.h +7699 -0
  285. data/cpp/arduino/include/lock.h +239 -0
  286. data/cpp/arduino/include/portpins.h +549 -0
  287. data/cpp/arduino/include/version.h +90 -0
  288. data/cpp/arduino/include/xmega.h +71 -0
  289. data/cpp/unittest/Assertion.h +9 -4
  290. data/cpp/unittest/Compare.h +93 -0
  291. data/lib/arduino_ci/arduino_installation.rb +1 -1
  292. data/lib/arduino_ci/cpp_library.rb +4 -1
  293. data/lib/arduino_ci/version.rb +1 -1
  294. data/misc/default.yaml +7 -0
  295. metadata +285 -2
@@ -0,0 +1,62 @@
1
+ #include "Godmode.h"
2
+ #include "HardwareSerial.h"
3
+
4
+ GodmodeState godmode = GodmodeState();
5
+
6
+ GodmodeState* GODMODE() {
7
+ return &godmode;
8
+ }
9
+
10
+ unsigned long millis() {
11
+ GodmodeState* godmode = GODMODE();
12
+ return godmode->micros / 1000;
13
+ }
14
+
15
+ unsigned long micros() {
16
+ GodmodeState* godmode = GODMODE();
17
+ return godmode->micros;
18
+ }
19
+
20
+ void delay(unsigned long millis) {
21
+ GodmodeState* godmode = GODMODE();
22
+ godmode->micros += millis * 1000;
23
+ }
24
+
25
+ void delayMicroseconds(unsigned long micros) {
26
+ GodmodeState* godmode = GODMODE();
27
+ godmode->micros += micros;
28
+ }
29
+
30
+
31
+ void randomSeed(unsigned long seed)
32
+ {
33
+ GodmodeState* godmode = GODMODE();
34
+ godmode->seed = seed;
35
+ }
36
+
37
+ long random(long vmax)
38
+ {
39
+ GodmodeState* godmode = GODMODE();
40
+ godmode->seed += 4294967291; // it's a prime that fits in 32 bits
41
+ return godmode->seed % vmax;
42
+ }
43
+
44
+ long random(long vmin, long vmax)
45
+ {
46
+ return vmin < vmax ? (random(vmax - vmin) + vmin) : vmin;
47
+ }
48
+
49
+ // Serial ports
50
+ #if defined(HAVE_HWSERIAL0)
51
+ HardwareSerial Serial(&godmode.serialPort[0].dataIn, &godmode.serialPort[0].dataOut, &godmode.serialPort[0].readDelayMicros);
52
+ #endif
53
+ #if defined(HAVE_HWSERIAL1)
54
+ HardwareSerial Serial1(&godmode.serialPort[1].dataIn, &godmode.serialPort[1].dataOut, &godmode.serialPort[1].readDelayMicros);
55
+ #endif
56
+ #if defined(HAVE_HWSERIAL2)
57
+ HardwareSerial Serial2(&godmode.serialPort[2].dataIn, &godmode.serialPort[2].dataOut, &godmode.serialPort[2].readDelayMicros);
58
+ #endif
59
+ #if defined(HAVE_HWSERIAL3)
60
+ HardwareSerial Serial3(&godmode.serialPort[3].dataIn, &godmode.serialPort[3].dataOut, &godmode.serialPort[3].readDelayMicros);
61
+ #endif
62
+
@@ -0,0 +1,74 @@
1
+ #pragma once
2
+ #include "ArduinoDefines.h"
3
+ #include "WString.h"
4
+
5
+ #define MOCK_PINS_COUNT 256
6
+
7
+ #if defined(UBRR3H)
8
+ #define NUM_SERIAL_PORTS 4
9
+ #elif defined(UBRR2H)
10
+ #define NUM_SERIAL_PORTS 3
11
+ #elif defined(UBRR1H)
12
+ #define NUM_SERIAL_PORTS 2
13
+ #elif defined(UBRRH) || defined(UBRR0H)
14
+ #define NUM_SERIAL_PORTS 1
15
+ #else
16
+ #define NUM_SERIAL_PORTS 0
17
+ #endif
18
+
19
+
20
+ class GodmodeState {
21
+ struct PortDef {
22
+ String dataIn;
23
+ String dataOut;
24
+ unsigned long readDelayMicros;
25
+ };
26
+
27
+ public:
28
+ unsigned long micros;
29
+ unsigned long seed;
30
+ // not going to put pinmode here unless its really needed. can't think of why it would be
31
+ bool digitalPin[MOCK_PINS_COUNT];
32
+ int analogPin[MOCK_PINS_COUNT];
33
+ struct PortDef serialPort[NUM_SERIAL_PORTS];
34
+
35
+ void resetPins() {
36
+ for (int i = 0; i < MOCK_PINS_COUNT; ++i) {
37
+ digitalPin[i] = LOW;
38
+ analogPin[i] = 0;
39
+ }
40
+ }
41
+
42
+ void resetClock() {
43
+ micros = 0;
44
+ }
45
+
46
+ void reset() {
47
+ resetClock();
48
+ resetPins();
49
+ seed = 1;
50
+ }
51
+
52
+ GodmodeState() {
53
+ reset();
54
+ for (int i = 0; i < NUM_SERIAL_PORTS; ++i) {
55
+ serialPort[i] = {"", "", 0};
56
+ }
57
+ }
58
+
59
+ };
60
+
61
+ GodmodeState* GODMODE();
62
+
63
+ // random
64
+ void randomSeed(unsigned long seed);
65
+ long random(long vmax);
66
+ long random(long vmin, long vmax);
67
+
68
+
69
+ // Time
70
+ void delay(unsigned long millis);
71
+ void delayMicroseconds(unsigned long micros);
72
+ unsigned long millis();
73
+ unsigned long micros();
74
+
@@ -0,0 +1,81 @@
1
+ #pragma once
2
+
3
+ //#include <inttypes.h>
4
+ #include "Stream.h"
5
+
6
+ // definitions neeeded for Serial.begin's config arg
7
+ #define SERIAL_5N1 0x00
8
+ #define SERIAL_6N1 0x02
9
+ #define SERIAL_7N1 0x04
10
+ #define SERIAL_8N1 0x06
11
+ #define SERIAL_5N2 0x08
12
+ #define SERIAL_6N2 0x0A
13
+ #define SERIAL_7N2 0x0C
14
+ #define SERIAL_8N2 0x0E
15
+ #define SERIAL_5E1 0x20
16
+ #define SERIAL_6E1 0x22
17
+ #define SERIAL_7E1 0x24
18
+ #define SERIAL_8E1 0x26
19
+ #define SERIAL_5E2 0x28
20
+ #define SERIAL_6E2 0x2A
21
+ #define SERIAL_7E2 0x2C
22
+ #define SERIAL_8E2 0x2E
23
+ #define SERIAL_5O1 0x30
24
+ #define SERIAL_6O1 0x32
25
+ #define SERIAL_7O1 0x34
26
+ #define SERIAL_8O1 0x36
27
+ #define SERIAL_5O2 0x38
28
+ #define SERIAL_6O2 0x3A
29
+ #define SERIAL_7O2 0x3C
30
+ #define SERIAL_8O2 0x3E
31
+
32
+ class HardwareSerial : public Stream
33
+ {
34
+ protected:
35
+ String* mGodmodeDataOut;
36
+
37
+ public:
38
+ HardwareSerial(String* dataIn, String* dataOut, unsigned long* delay): Stream() {
39
+ mGodmodeDataIn = dataIn;
40
+ mGodmodeDataOut = dataOut;
41
+ mGodmodeMicrosDelay = delay;
42
+ }
43
+ void begin(unsigned long baud) { begin(baud, SERIAL_8N1); }
44
+ void begin(unsigned long baud, uint8_t config) {
45
+ *mGodmodeMicrosDelay = 1000000 / baud;
46
+ }
47
+ void end() {}
48
+
49
+ // virtual int available(void);
50
+ // virtual int peek(void);
51
+ // virtual int read(void);
52
+ // virtual int availableForWrite(void);
53
+ // virtual void flush(void);
54
+ virtual size_t write(uint8_t aChar) { mGodmodeDataOut->append(String((char)aChar)); return 1; }
55
+
56
+ inline size_t write(unsigned long n) { return write((uint8_t)n); }
57
+ inline size_t write(long n) { return write((uint8_t)n); }
58
+ inline size_t write(unsigned int n) { return write((uint8_t)n); }
59
+ inline size_t write(int n) { return write((uint8_t)n); }
60
+ // using Print::write; // pull in write(str) and write(buf, size) from Print
61
+ operator bool() { return true; }
62
+
63
+ };
64
+
65
+ #if defined(UBRRH) || defined(UBRR0H)
66
+ extern HardwareSerial Serial;
67
+ #define HAVE_HWSERIAL0
68
+ #endif
69
+ #if defined(UBRR1H)
70
+ extern HardwareSerial Serial1;
71
+ #define HAVE_HWSERIAL1
72
+ #endif
73
+ #if defined(UBRR2H)
74
+ extern HardwareSerial Serial2;
75
+ #define HAVE_HWSERIAL2
76
+ #endif
77
+ #if defined(UBRR3H)
78
+ extern HardwareSerial Serial3;
79
+ #define HAVE_HWSERIAL3
80
+ #endif
81
+
@@ -0,0 +1,67 @@
1
+ #pragma once
2
+
3
+ #include <stdio.h>
4
+ #include "WString.h"
5
+
6
+ #define DEC 10
7
+ #define HEX 16
8
+ #define OCT 8
9
+ #ifdef BIN
10
+ #undef BIN
11
+ #endif
12
+ #define BIN 2
13
+
14
+ class Print;
15
+
16
+ class Printable
17
+ {
18
+ public:
19
+ virtual size_t printTo(Print& p) const = 0;
20
+ };
21
+
22
+ class Print
23
+ {
24
+ public:
25
+ Print() {}
26
+
27
+ // Arduino's version of this is richer but until I see an actual error case I'm not sure how to mock
28
+ int getWriteError() { return 0; }
29
+ void clearWriteError() { }
30
+ virtual int availableForWrite() { return 0; }
31
+
32
+ virtual size_t write(uint8_t) = 0;
33
+ size_t write(const char *str) { return str == NULL ? 0 : write((const uint8_t *)str, String(str).length()); }
34
+ virtual size_t write(const uint8_t *buffer, size_t size)
35
+ {
36
+ size_t n;
37
+ for (n = 0; size && write(*buffer++) && ++n; --size);
38
+ return n;
39
+ }
40
+ size_t write(const char *buffer, size_t size) { return write((const uint8_t *)buffer, size); }
41
+
42
+ size_t print(const String &s) { return write(s.c_str(), s.length()); }
43
+ size_t print(const char* str) { return print(String(str)); }
44
+ size_t print(char c) { return print(String(c)); }
45
+ size_t print(unsigned char b, int base) { return print(String(b, base)); }
46
+ size_t print(int n, int base) { return print(String(n, base)); }
47
+ size_t print(unsigned int n, int base) { return print(String(n, base)); }
48
+ size_t print(long n, int base) { return print(String(n, base)); }
49
+ size_t print(unsigned long n, int base) { return print(String(n, base)); }
50
+ size_t print(double n, int digits) { return print(String(n, digits)); }
51
+ size_t print(const Printable& x) { return x.printTo(*this); }
52
+
53
+ size_t println(void) { return print("\r\n"); }
54
+ size_t println(const String &s) { return print(s) + println(); }
55
+ size_t println(const char* c) { return println(String(c)); }
56
+ size_t println(char c) { return println(String(c)); }
57
+ size_t println(unsigned char b, int base) { return println(String(b, base)); }
58
+ size_t println(int num, int base) { return println(String(num, base)); }
59
+ size_t println(unsigned int num, int base) { return println(String(num, base)); }
60
+ size_t println(long num, int base) { return println(String(num, base)); }
61
+ size_t println(unsigned long num, int base) { return println(String(num, base)); }
62
+ size_t println(double num, int digits) { return println(String(num, digits)); }
63
+ size_t println(const Printable& x) { return print(x) + println(); }
64
+
65
+ virtual void flush() { }
66
+
67
+ };
@@ -0,0 +1,210 @@
1
+ #pragma once
2
+ #include "Godmode.h"
3
+ #include "WString.h"
4
+ #include "Print.h"
5
+
6
+
7
+ // This enumeration provides the lookahead options for parseInt(), parseFloat()
8
+ // The rules set out here are used until either the first valid character is found
9
+ // or a time out occurs due to lack of input.
10
+ enum LookaheadMode{
11
+ SKIP_ALL, // All invalid characters are ignored.
12
+ SKIP_NONE, // Nothing is skipped, and the stream is not touched unless the first waiting character is valid.
13
+ SKIP_WHITESPACE // Only tabs, spaces, line feeds & carriage returns are skipped.
14
+ };
15
+
16
+ #define NO_IGNORE_CHAR '\x01' // a char not found in a valid ASCII numeric field
17
+
18
+ class Stream : public Print
19
+ {
20
+ public:
21
+ String* mGodmodeDataIn;
22
+ unsigned long* mGodmodeMicrosDelay;
23
+
24
+ protected:
25
+ unsigned long mTimeoutMillis;
26
+
27
+ void fastforward(int pos) {
28
+ mGodmodeDataIn->assign(mGodmodeDataIn->substring(pos));
29
+ }
30
+
31
+ char fastforwardToAnyChar(LookaheadMode lookahead, String chars) {
32
+ char c;
33
+ while ((c = peek()) != -1) {
34
+ if (chars.find(c) != String::npos) return c;
35
+ if (lookahead == SKIP_NONE) return -1;
36
+ if (lookahead == SKIP_WHITESPACE && !isWhitespace(c)) return -1;
37
+ read();
38
+ }
39
+ return -1;
40
+ }
41
+
42
+ // int timedRead(); // read stream with timeout
43
+ // int timedPeek(); // peek stream with timeout
44
+ // int peekNextDigit(LookaheadMode lookahead, bool detectDecimal); // returns the next numeric digit in the stream or -1 if timeout
45
+
46
+ public:
47
+ virtual int available() { return mGodmodeDataIn->length(); }
48
+ virtual int peek() { return available() ? (int)((*mGodmodeDataIn)[0]) : -1; }
49
+ virtual int read() {
50
+ int ret = peek();
51
+ if (ret != -1) {
52
+ fastforward(1);
53
+ if (mGodmodeMicrosDelay) delayMicroseconds(*mGodmodeMicrosDelay);
54
+ }
55
+ return ret;
56
+ }
57
+
58
+ virtual size_t write(uint8_t aChar) { mGodmodeDataIn->append(String((char)aChar)); return 1; }
59
+
60
+
61
+ Stream() {
62
+ mTimeoutMillis = 1000;
63
+ mGodmodeMicrosDelay = NULL;
64
+ mGodmodeDataIn = NULL;
65
+ }
66
+
67
+
68
+ void setTimeout(unsigned long timeoutMillis) { mTimeoutMillis = timeoutMillis; };
69
+ unsigned long getTimeout(void) { return mTimeoutMillis; }
70
+
71
+ bool find(const String &s) {
72
+ long idx;
73
+ if ((idx = mGodmodeDataIn->find(s)) != String::npos) {
74
+ fastforward(idx);
75
+ return true;
76
+ }
77
+ return false;
78
+ }
79
+
80
+ bool find(char *target) { return find(String(target)); }
81
+ bool find(uint8_t *target) { return find(String((char*)target)); }
82
+ bool find(char *target, size_t length) { return find(String(string(target, length))); }
83
+ bool find(uint8_t *target, size_t length) { return find(String(string((char*)target, length))); }
84
+ bool find(char target) { return find(String(string(&target, 1))); }
85
+
86
+ bool findUntil(const String &target, const String &terminator) {
87
+ long idxTgt = mGodmodeDataIn->find(target);
88
+ long idxTrm = mGodmodeDataIn->find(terminator);
89
+ if (idxTgt == String::npos) {
90
+ mGodmodeDataIn->clear();
91
+ return false; // didn't find it
92
+ }
93
+ if (idxTrm != String::npos || idxTrm < idxTgt) {
94
+ fastforward(idxTrm);
95
+ return false; // target found after term
96
+ }
97
+ return find(target);
98
+ }
99
+
100
+ bool findUntil(char *target, char *terminator) { return findUntil(String(target), String(terminator)); }
101
+ bool findUntil(uint8_t *target, char *terminator) { return findUntil(String((char *)target), String(terminator)); }
102
+ bool findUntil(char *target, size_t targetLen, char *terminate, size_t termLen) {
103
+ return findUntil(String(string(target, targetLen)), String(string(terminate, termLen)));
104
+ }
105
+ bool findUntil(uint8_t *target, size_t targetLen, char *terminate, size_t termLen) {
106
+ return findUntil(String(string((char *)target, targetLen)), String(string(terminate, termLen)));
107
+ }
108
+
109
+ // returns the first valid (long) integer value from the current position.
110
+ // lookahead determines how parseInt looks ahead in the stream.
111
+ // See LookaheadMode enumeration at the top of the file.
112
+ // Lookahead is terminated by the first character that is not a valid part of an integer.
113
+ // Once parsing commences, 'ignore' will be skipped in the stream.
114
+ long parseInt(LookaheadMode lookahead = SKIP_ALL, char ignore = NO_IGNORE_CHAR) {
115
+ String digits = "1234567890";
116
+ if (fastforwardToAnyChar(lookahead, digits + "-") == -1) return 0;
117
+ String out = String((char)read()); // read unconditionally -- might be a minus
118
+ char c;
119
+ bool keepGoing = true;
120
+ do {
121
+ c = peek();
122
+ if (c == -1) break;
123
+ if (c != ignore || ignore == NO_IGNORE_CHAR) out += c;
124
+ keepGoing = digits.find(c) != String::npos;
125
+ if (!keepGoing) break;
126
+ read();
127
+ } while (true);
128
+ return out.toInt();
129
+ }
130
+
131
+ float parseFloat(LookaheadMode lookahead = SKIP_ALL, char ignore = NO_IGNORE_CHAR) {
132
+ String digits = "1234567890";
133
+ if (fastforwardToAnyChar(lookahead, digits + "-") == -1) return 0;
134
+ String out = String((char)read()); // read unconditionally -- might be a minus
135
+ String bank = digits + ".";
136
+ bool gotDot = false;
137
+ bool keepGoing = true;
138
+ char c;
139
+ do {
140
+ c = peek();
141
+ if (c == -1) break;
142
+ if (c == '.') { // waiting for gotDot
143
+ if (gotDot) break;
144
+ gotDot = true;
145
+ }
146
+ if (c != ignore || ignore == NO_IGNORE_CHAR) out += c;
147
+ keepGoing = bank.find(c) != String::npos;
148
+ if (!keepGoing) break;
149
+ read();
150
+ } while (true);
151
+ return out.toFloat();
152
+ }
153
+
154
+ // read chars from stream into buffer
155
+ // returns the number of characters placed in the buffer (0 means no valid data found)
156
+ size_t readBytes(char *buffer, size_t length) {
157
+ size_t ret = mGodmodeDataIn->copy(buffer, length);
158
+ if (mGodmodeMicrosDelay) delayMicroseconds(*mGodmodeMicrosDelay * ret);
159
+ fastforward(ret);
160
+ return ret;
161
+ }
162
+
163
+ // read chars from stream into buffer
164
+ // returns the number of characters placed in the buffer (0 means no valid data found)
165
+ size_t readBytes(uint8_t *buffer, size_t length) { return readBytes((char *)buffer, length); }
166
+
167
+ // read chars from stream into buffer
168
+ // returns the number of characters placed in the buffer (0 means no valid data found)
169
+ size_t readBytesUntil(char terminator, char *buffer, size_t length) {
170
+ size_t idx = mGodmodeDataIn->find(terminator);
171
+ size_t howMuch = idx == String::npos ? length : min(length, idx);
172
+ return readBytes(buffer, howMuch);
173
+ }
174
+
175
+ // read chars from stream into buffer
176
+ // returns the number of characters placed in the buffer (0 means no valid data found)
177
+ size_t readBytesUntil(char terminator, uint8_t *buffer, size_t length) { return readBytesUntil(terminator, (char *)buffer, length); }
178
+
179
+ String readStringUntil(char terminator) {
180
+ long idxTrm = mGodmodeDataIn->find(terminator);
181
+ String ret;
182
+ if (idxTrm == String::npos) {
183
+ ret = String(*mGodmodeDataIn);
184
+ mGodmodeDataIn->clear();
185
+ } else {
186
+ ret = mGodmodeDataIn->substring(0, idxTrm + 1);
187
+ fastforward(idxTrm + 1);
188
+ }
189
+ return ret;
190
+ }
191
+
192
+ String readString() {
193
+ String ret(*mGodmodeDataIn);
194
+ mGodmodeDataIn->clear();
195
+ return ret;
196
+ }
197
+
198
+
199
+ protected:
200
+ long parseInt(char ignore) { return parseInt(SKIP_ALL, ignore); }
201
+ float parseFloat(char ignore) { return parseFloat(SKIP_ALL, ignore); }
202
+ // These overload exists for compatibility with any class that has derived
203
+ // Stream and used parseFloat/Int with a custom ignore character. To keep
204
+ // the public API simple, these overload remains protected.
205
+
206
+ };
207
+
208
+ #undef NO_IGNORE_CHAR
209
+
210
+