Skip to content

Commit 8e4870d

Browse files
author
James Foster
authored
Merge branch 'cptr450' into tdd
2 parents 481ffaf + 736bf20 commit 8e4870d

File tree

12 files changed

+560
-425
lines changed

12 files changed

+560
-425
lines changed

.github/workflows/Arduino-CI.yaml

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
# This is the name of the workflow, visible on GitHub UI
2+
name: Arduino CI
3+
4+
# Run on a Push or a Pull Request
5+
on: [push, pull_request]
6+
7+
jobs:
8+
runTest:
9+
runs-on: ubuntu-latest
10+
steps:
11+
# Clone the repo using the `checkout` action
12+
- uses: actions/checkout@v2
13+
14+
# Get Ruby
15+
- uses: ruby/setup-ruby@v1
16+
with:
17+
ruby-version: 2.6
18+
19+
# Install and run Arduino CI tests
20+
- name: Build and Execute
21+
run: |
22+
g++ -v
23+
bundle install
24+
bundle exec rubocop --version
25+
bundle exec rubocop -D .
26+
bundle exec rspec --backtrace
27+
cd SampleProjects/TestSomething
28+
bundle install
29+
bundle exec arduino_ci_remote.rb

.travis.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,4 +26,4 @@ script:
2626
- bundle exec rspec --backtrace
2727
- cd SampleProjects/TestSomething
2828
- bundle install
29-
- bundle exec arduino_ci_remote.rb
29+
- bundle exec arduino_ci.rb

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,10 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
1212

1313
### Changed
1414
- Move repository from https://github.com/ianfixes/arduino_ci to https://github.com/Arduino-CI/arduino_ci
15+
- Revise math macros to avoid name clashes
1516

1617
### Deprecated
18+
- Deprecated `arduino_ci_remote.rb` in favor of `arduino_ci.rb`
1719

1820
### Removed
1921

README.md

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -94,15 +94,15 @@ $ bundle install --path vendor/bundle # adds packages to local library
9494
With that installed, just the following shell command each time you want the tests to execute:
9595

9696
```
97-
$ bundle exec arduino_ci_remote.rb
97+
$ bundle exec arduino_ci.rb
9898
```
9999

100-
`arduino_ci_remote.rb` is the main entry point for this library. This command will iterate over all the library's `examples/` and attempt to compile them. If you set up unit tests, it will run those as well.
100+
`arduino_ci.rb` is the main entry point for this library. This command will iterate over all the library's `examples/` and attempt to compile them. If you set up unit tests, it will run those as well.
101101

102102

103103
### Reference
104104

105-
For more information on the usage of `arduino_ci_remote.rb`, see [REFERENCE.md](REFERENCE.md). It contains information such as:
105+
For more information on the usage of `arduino_ci.rb`, see [REFERENCE.md](REFERENCE.md). It contains information such as:
106106

107107
* How to configure build options (platforms to test, Arduino library dependencies to install) with an `.arduino-ci.yml` file
108108
* Where to put unit test files
@@ -121,7 +121,7 @@ The following prerequisites must be fulfilled:
121121

122122
### Testing with remote CI
123123

124-
> **Note:** `arduino_ci_remote.rb` expects to be run from the root directory of your Arduino project library.
124+
> **Note:** `arduino_ci.rb` expects to be run from the root directory of your Arduino project library.
125125
126126

127127
#### Travis CI
@@ -135,7 +135,7 @@ sudo: false
135135
language: ruby
136136
script:
137137
- bundle install
138-
- bundle exec arduino_ci_remote.rb
138+
- bundle exec arduino_ci.rb
139139
```
140140
141141
@@ -149,7 +149,7 @@ Next, you'll need this in `appveyor.yml` in your repo.
149149
build: off
150150
test_script:
151151
- bundle install
152-
- bundle exec arduino_ci_remote.rb
152+
- bundle exec arduino_ci.rb
153153
```
154154

155155
## Known Problems

REFERENCE.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# Build / Test Behavior of Arduino CI
22

3-
All tests are run via the same command: `bundle exec arduino_ci_remote.rb`.
3+
All tests are run via the same command: `bundle exec arduino_ci.rb`.
44

55
This script is responsible for detecting and runing all unit tests, on every combination of Arduino platform and C++ compiler. This is followed by attempting to detect and build every example on every "default" Arduino platform.
66

@@ -11,7 +11,7 @@ These defaults are specified in [misc/default.yml](misc/default.yml). You are f
1111

1212
## Directly Overriding Build Behavior (short term use)
1313

14-
When testing locally, it's often advantageous to limit the number of tests that are performed to only those tests that relate to the work you're doing; you'll get a faster turnaround time in seeing the results. For a full listing, see `bundle exec arduino_ci_remote.rb --help`.
14+
When testing locally, it's often advantageous to limit the number of tests that are performed to only those tests that relate to the work you're doing; you'll get a faster turnaround time in seeing the results. For a full listing, see `bundle exec arduino_ci.rb --help`.
1515

1616

1717
### `--skip-unittests` option
@@ -233,14 +233,14 @@ For most build environments, the only script that need be executed by the CI sys
233233
```shell
234234
# simplest build script
235235
bundle install
236-
bundle exec arduino_ci_remote.rb
236+
bundle exec arduino_ci.rb
237237
```
238238

239239
However, more flexible usage is available:
240240

241241
### Custom Versions of external Arduino Libraries
242242

243-
Sometimes you need a fork of an Arduino library instead of the version that will be installed via their GUI. `arduino_ci_remote.rb` won't overwrite existing downloaded libraries with fresh downloads, but it won't fetch the custom versions for you either.
243+
Sometimes you need a fork of an Arduino library instead of the version that will be installed via their GUI. `arduino_ci.rb` won't overwrite existing downloaded libraries with fresh downloads, but it won't fetch the custom versions for you either.
244244

245245
If this is the behavior you need, `ensure_arduino_installation.rb` is for you. It ensures that an Arduino binary is available on the system.
246246

@@ -261,7 +261,7 @@ git clone https://repository.com/custom_library_repo.git
261261
mv custom_library_repo $(bundle exec arduino_library_location.rb)
262262
263263
# now run CI
264-
bundle exec arduino_ci_remote.rb
264+
bundle exec arduino_ci.rb
265265
```
266266

267267
Note the use of subshell to execute `bundle exec arduino_library_location.rb`. This command simply returns the directory in which Arduino Libraries are (or should be) installed.

SampleProjects/DoSomething/.travis.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,4 @@ sudo: false
22
language: ruby
33
script:
44
- bundle install
5-
- bundle exec arduino_ci_remote.rb
5+
- bundle exec arduino_ci.rb

SampleProjects/DoSomething/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ At a minimum, you will need the following lines in your file:
3434
language: ruby
3535
script:
3636
- bundle install
37-
- bundle exec arduino_ci_remote.rb
37+
- bundle exec arduino_ci.rb
3838
```
3939
4040
This will install the necessary ruby gem, and run it. There are no command line arguments as of this writing, because all configuration is provided by...

appveyor.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,4 +24,4 @@ test_script:
2424
- bundle exec rspec --backtrace
2525
- cd SampleProjects\TestSomething
2626
- bundle install
27-
- bundle exec arduino_ci_remote.rb
27+
- bundle exec arduino_ci.rb

cpp/arduino/AvrMath.h

Lines changed: 117 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,126 @@
11
#pragma once
2+
#include "ArduinoDefines.h"
23
#include <math.h>
34

4-
#define constrain(x,l,h) ((x)<(l)?(l):((x)>(h)?(h):(x)))
5-
#define map(x,inMin,inMax,outMin,outMax) (((x)-(inMin))*((outMax)-(outMin))/((inMax)-(inMin))+outMin)
5+
#ifdef __cplusplus
66

7-
#define sq(x) ((x)*(x))
7+
template <class Amt, class Low, class High>
8+
auto constrain(const Amt &amt, const Low &low, const High &high)
9+
-> decltype(amt < low ? low : (amt > high ? high : amt)) {
10+
return (amt < low ? low : (amt > high ? high : amt));
11+
}
812

9-
#define radians(deg) ((deg)*DEG_TO_RAD)
10-
#define degrees(rad) ((rad)*RAD_TO_DEG)
13+
template <class X, class InMin, class InMax, class OutMin, class OutMax>
14+
auto map(const X &x, const InMin &inMin, const InMax &inMax,
15+
const OutMin &outMin, const OutMax &outMax)
16+
-> decltype((x - inMin) * (outMax - outMin) / (inMax - inMin) + outMin) {
17+
return (x - inMin) * (outMax - outMin) / (inMax - inMin) + outMin;
18+
}
1119

12-
#ifdef abs
13-
#undef abs
14-
#endif
15-
#define abs(x) ((x)>0?(x):-(x))
20+
template <class T> auto radians(const T &deg) -> decltype(deg * DEG_TO_RAD) {
21+
return deg * DEG_TO_RAD;
22+
}
1623

17-
#ifdef max
18-
#undef max
19-
#endif
20-
#define max(a,b) ((a)>(b)?(a):(b))
24+
template <class T> auto degrees(const T &rad) -> decltype(rad * RAD_TO_DEG) {
25+
return rad * RAD_TO_DEG;
26+
}
2127

22-
#ifdef min
23-
#undef min
24-
#endif
25-
#define min(a,b) ((a)<(b)?(a):(b))
28+
template <class T> auto sq(const T &x) -> decltype(x * x) { return x * x; }
29+
30+
template <class T> auto abs(const T &x) -> decltype(x > 0 ? x : -x) {
31+
return x > 0 ? x : -x;
32+
}
33+
34+
template <class T, class L>
35+
auto min(const T &a, const L &b) -> decltype((b < a) ? b : a) {
36+
return (b < a) ? b : a;
37+
}
38+
39+
template <class T, class L>
40+
auto max(const T &a, const L &b) -> decltype((b < a) ? b : a) {
41+
return (a < b) ? b : a;
42+
}
43+
44+
#else // __cplusplus
45+
46+
#ifdef constrain
47+
#undef constrain
48+
#endif
49+
#define constrain(amt, low, high) \
50+
({ \
51+
__typeof__(amt) _amt = (amt); \
52+
__typeof__(low) _low = (low); \
53+
__typeof__(high) _high = (high); \
54+
(amt < low ? low : (amt > high ? high : amt)); \
55+
})
2656

57+
#ifdef map
58+
#undef map
59+
#endif
60+
#define map(x, inMin, inMax, outMin, outMax) \
61+
({ \
62+
__typeof__(x) _x = (x); \
63+
__typeof__(inMin) _inMin = (inMin); \
64+
__typeof__(inMax) _inMax = (inMax); \
65+
__typeof__(outMin) _outMin = (outMin); \
66+
__typeof__(outMax) _outMax = (outMax); \
67+
(_x - _inMin) * (_outMax - _outMin) / (_inMax - _inMin) + _outMin; \
68+
})
69+
70+
#ifdef radians
71+
#undef radians
72+
#endif
73+
#define radians(deg) \
74+
({ \
75+
__typeof__(deg) _deg = (deg); \
76+
_deg *DEG_TO_RAD; \
77+
})
78+
79+
#ifdef degrees
80+
#undef degrees
81+
#endif
82+
#define degrees(rad) \
83+
({ \
84+
__typeof__(rad) _rad = (rad); \
85+
_rad *RAD_TO_DEG; \
86+
})
87+
88+
#ifdef sq
89+
#undef sq
90+
#endif
91+
#define sq(x) \
92+
({ \
93+
__typeof__(x) _x = (x); \
94+
_x *_x; \
95+
})
96+
97+
#ifdef abs
98+
#undef abs
99+
#endif
100+
#define abs(x) \
101+
({ \
102+
__typeof__(x) _x = (x); \
103+
_x > 0 ? _x : -_x; \
104+
})
105+
106+
#ifdef min
107+
#undef min
108+
#endif
109+
#define min(a, b) \
110+
({ \
111+
__typeof__(a) _a = (a); \
112+
__typeof__(b) _b = (b); \
113+
_a < _b ? _a : _b; \
114+
})
115+
116+
#ifdef max
117+
#undef max
118+
#endif
119+
#define max(a, b) \
120+
({ \
121+
__typeof__(a) _a = (a); \
122+
__typeof__(b) _b = (b); \
123+
_a > _b ? _a : _b; \
124+
})
125+
126+
#endif

cpp/arduino/Godmode.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
#include <avr/io.h>
44
#include "WString.h"
55
#include "PinHistory.h"
6+
#include "EEPROM.h"
67

78
// random
89
void randomSeed(unsigned long seed);

0 commit comments

Comments
 (0)