arduino_ci 0.2.0 → 0.2.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: ec22bfa6969f75cdb38ffa4365c3d8f2f83f2185
4
- data.tar.gz: 2380ce41fe0779e258471b28e9e94eee3c238369
3
+ metadata.gz: a109dd9f9d784f5cc6b9e471366323b649cd46b6
4
+ data.tar.gz: 2b3e1296eff822fc0df13e9197c9f13b6b0a048d
5
5
  SHA512:
6
- metadata.gz: 2c464279ef51852b51b22287960474da51a2818c9d41b8aadc181287636fa095effa8644f08320a62af7316a8540e9279ccf904c4936da619e82b7fb0011b21c
7
- data.tar.gz: 7dfecd48948dfa8588e150841ee24c472480a20f10892c6098905fa35220bca26690708f827ec5b290d1564006f5a3c3019c7638eac27b9669311f6203f3973c
6
+ metadata.gz: 3a6a744be45d9b53740dfe5f9b1ed2850275bd397003adef61d63cc654f2baed573dbc3fe9ca00cbe7e89dd9dd07514bfd56460eb605e1d69a32638125012e19
7
+ data.tar.gz: feb7bdf3f740f15eb53dca481e4d9401e99243478711ccddb0ee0a342f7b1d5b98b277a54095ad17af3963ee0af0f4c506c04353d780d9c822e1b0a9458fd3db
data/README.md CHANGED
@@ -1,5 +1,5 @@
1
1
 
2
- # ArduinoCI Ruby gem (`arduino_ci`) [![Gem Version](https://badge.fury.io/rb/arduino_ci.svg)](https://rubygems.org/gems/arduino_ci) [![Documentation](http://img.shields.io/badge/docs-rdoc.info-blue.svg)](http://www.rubydoc.info/gems/arduino_ci/0.2.0)
2
+ # ArduinoCI Ruby gem (`arduino_ci`) [![Gem Version](https://badge.fury.io/rb/arduino_ci.svg)](https://rubygems.org/gems/arduino_ci) [![Documentation](http://img.shields.io/badge/docs-rdoc.info-blue.svg)](http://www.rubydoc.info/gems/arduino_ci/0.2.1)
3
3
 
4
4
  You want to run tests on your Arduino library (bonus: without hardware present), but the IDE doesn't support that. Arduino CI provides that ability.
5
5
 
@@ -15,6 +15,7 @@ Where possible, variable names from the Arduino library are used to avoid confli
15
15
  #include "Stream.h"
16
16
  #include "HardwareSerial.h"
17
17
  #include "SPI.h"
18
+ #include "Wire.h"
18
19
 
19
20
  typedef bool boolean;
20
21
  typedef uint8_t byte;
@@ -1,6 +1,7 @@
1
1
  #include "Godmode.h"
2
2
  #include "HardwareSerial.h"
3
3
  #include "SPI.h"
4
+ #include "Wire.h"
4
5
 
5
6
  GodmodeState* GODMODE() {
6
7
  return GodmodeState::getInstance();
@@ -109,3 +110,6 @@ inline std::ostream& operator << ( std::ostream& out, const PinHistory<T>& ph )
109
110
 
110
111
  // defined in SPI.h
111
112
  SPIClass SPI = SPIClass(&GODMODE()->spi.dataIn, &GODMODE()->spi.dataOut);
113
+
114
+ // defined in Wire.h
115
+ TwoWire Wire = TwoWire();
@@ -1,7 +1,7 @@
1
1
  #pragma once
2
2
 
3
3
  //#include <inttypes.h>
4
- #include "Stream.h"
4
+ #include "ci/StreamTape.h"
5
5
 
6
6
  // definitions neeeded for Serial.begin's config arg
7
7
  #define SERIAL_5N1 0x00
@@ -29,38 +29,19 @@
29
29
  #define SERIAL_7O2 0x3C
30
30
  #define SERIAL_8O2 0x3E
31
31
 
32
- class HardwareSerial : public Stream, public ObservableDataStream
32
+ class HardwareSerial : public StreamTape
33
33
  {
34
- protected:
35
- String* mGodmodeDataOut;
36
-
37
34
  public:
38
- HardwareSerial(String* dataIn, String* dataOut, unsigned long* delay): Stream(), ObservableDataStream() {
39
- mGodmodeDataIn = dataIn;
40
- mGodmodeDataOut = dataOut;
41
- mGodmodeMicrosDelay = delay;
42
- }
35
+ HardwareSerial(String* dataIn, String* dataOut, unsigned long* delay): StreamTape(dataIn, dataOut, delay) {}
36
+
43
37
  void begin(unsigned long baud) { begin(baud, SERIAL_8N1); }
44
38
  void begin(unsigned long baud, uint8_t config) {
45
39
  *mGodmodeMicrosDelay = 1000000 / baud;
46
40
  }
47
41
  void end() {}
48
42
 
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) {
55
- mGodmodeDataOut->append(String((char)aChar));
56
- advertiseByte((unsigned char)aChar);
57
- return 1;
58
- }
59
-
60
- // https://stackoverflow.com/a/4271276
61
- using Print::write; // pull in write(str) and write(buf, size) from Print
43
+ // support "if (Serial1) {}" sorts of things
62
44
  operator bool() { return true; }
63
-
64
45
  };
65
46
 
66
47
  #if defined(UBRRH) || defined(UBRR0H)
@@ -0,0 +1,138 @@
1
+
2
+ #pragma once
3
+
4
+ #include <inttypes.h>
5
+ #include "Stream.h"
6
+
7
+ class TwoWire : public ObservableDataStream
8
+ {
9
+ public:
10
+ TwoWire() {
11
+ }
12
+
13
+ // https://www.arduino.cc/en/Reference/WireBegin
14
+ // Initiate the Wire library and join the I2C bus as a master or slave. This should normally be called only once.
15
+ void begin() {
16
+ isMaster = true;
17
+ }
18
+ void begin(int address) {
19
+ i2cAddress = address;
20
+ isMaster = false;
21
+ }
22
+ void begin(uint8_t address) {
23
+ begin((int)address);
24
+ }
25
+ void end() {
26
+ // TODO: implement
27
+ }
28
+
29
+ // https://www.arduino.cc/en/Reference/WireSetClock
30
+ // This function modifies the clock frequency for I2C communication. I2C slave devices have no minimum working
31
+ // clock frequency, however 100KHz is usually the baseline.
32
+ void setClock(uint32_t) {
33
+ // TODO: implement?
34
+ }
35
+
36
+ // https://www.arduino.cc/en/Reference/WireBeginTransmission
37
+ // Begin a transmission to the I2C slave device with the given address. Subsequently, queue bytes for
38
+ // transmission with the write() function and transmit them by calling endTransmission().
39
+ void beginTransmission(int address) {
40
+ // TODO: implement
41
+ }
42
+ void beginTransmission(uint8_t address) {
43
+ beginTransmission((int)address);
44
+ }
45
+
46
+ // https://www.arduino.cc/en/Reference/WireEndTransmission
47
+ // Ends a transmission to a slave device that was begun by beginTransmission() and transmits the bytes that were
48
+ // queued by write().
49
+ uint8_t endTransmission(uint8_t sendStop) {
50
+ // TODO: implement
51
+ return 0; // success
52
+ }
53
+ uint8_t endTransmission(void) {
54
+ return endTransmission((uint8_t)true);
55
+ }
56
+
57
+ // https://www.arduino.cc/en/Reference/WireRequestFrom
58
+ // Used by the master to request bytes from a slave device. The bytes may then be retrieved with the
59
+ // available() and read() functions.
60
+ uint8_t requestFrom(int address, int quantity, int stop) {
61
+ // TODO: implement
62
+ return 0; // number of bytes returned from the slave device
63
+ }
64
+ uint8_t requestFrom(int address, int quantity) {
65
+ int stop = true;
66
+ return requestFrom(address, quantity, stop);
67
+ }
68
+ uint8_t requestFrom(uint8_t address, uint8_t quantity) {
69
+ return requestFrom((int)address, (int)quantity);
70
+ }
71
+ uint8_t requestFrom(uint8_t address, uint8_t quantity, uint8_t stop) {
72
+ return requestFrom((int)address, (int)quantity, (int)stop);
73
+ }
74
+ uint8_t requestFrom(uint8_t, uint8_t, uint32_t, uint8_t, uint8_t) {
75
+ // TODO: implement
76
+ return 0;
77
+ }
78
+
79
+ // https://www.arduino.cc/en/Reference/WireWrite
80
+ // Writes data from a slave device in response to a request from a master, or queues bytes for transmission from a
81
+ // master to slave device (in-between calls to beginTransmission() and endTransmission()).
82
+ size_t write(uint8_t value) {
83
+ // TODO: implement
84
+ return 0; // number of bytes written
85
+ }
86
+ size_t write(const char *str) { return str == NULL ? 0 : write((const uint8_t *)str, String(str).length()); }
87
+ size_t write(const uint8_t *buffer, size_t size) {
88
+ size_t n;
89
+ for (n = 0; size && write(*buffer++) && ++n; --size);
90
+ return n;
91
+ }
92
+ size_t write(const char *buffer, size_t size) { return write((const uint8_t *)buffer, size); }
93
+ size_t write(unsigned long n) { return write((uint8_t)n); }
94
+ size_t write(long n) { return write((uint8_t)n); }
95
+ size_t write(unsigned int n) { return write((uint8_t)n); }
96
+ size_t write(int n) { return write((uint8_t)n); }
97
+
98
+ // https://www.arduino.cc/en/Reference/WireAvailable
99
+ // Returns the number of bytes available for retrieval with read(). This should be called on a master device after a
100
+ // call to requestFrom() or on a slave inside the onReceive() handler.
101
+ int available(void) {
102
+ // TODO: implement
103
+ return 0; // number of bytes available for reading
104
+ }
105
+
106
+ // https://www.arduino.cc/en/Reference/WireRead
107
+ // Reads a byte that was transmitted from a slave device to a master after a call to requestFrom() or was transmitted
108
+ // from a master to a slave. read() inherits from the Stream utility class.
109
+ int read(void) {
110
+ // TODO: implement
111
+ return '\0'; // The next byte received
112
+ }
113
+ int peek(void) {
114
+ // TODO: implement
115
+ return 0;
116
+ }
117
+ void flush(void) {
118
+ // TODO: implement
119
+ }
120
+
121
+ // https://www.arduino.cc/en/Reference/WireOnReceive
122
+ // Registers a function to be called when a slave device receives a transmission from a master.
123
+ void onReceive( void (*callback)(int) ) {
124
+ // TODO: implement
125
+ }
126
+
127
+ // https://www.arduino.cc/en/Reference/WireOnRequest
128
+ // Register a function to be called when a master requests data from this slave device.
129
+ void onRequest( void (*callback)(void) ) {
130
+ // TODO: implement
131
+ }
132
+
133
+ private:
134
+ int i2cAddress;
135
+ bool isMaster = false;
136
+ };
137
+
138
+ extern TwoWire Wire;
@@ -0,0 +1,36 @@
1
+ #pragma once
2
+
3
+ #include "../Stream.h"
4
+
5
+ /**
6
+ * Stream with godmode-controlled input and godmode-persisted output
7
+ */
8
+ class StreamTape : public Stream, public ObservableDataStream
9
+ {
10
+ protected:
11
+ String* mGodmodeDataOut;
12
+ // mGodmodeDataIn is provided by Stream
13
+
14
+ public:
15
+ StreamTape(String* dataIn, String* dataOut, unsigned long* delay): Stream(), ObservableDataStream() {
16
+ mGodmodeDataIn = dataIn;
17
+ mGodmodeDataOut = dataOut;
18
+ mGodmodeMicrosDelay = delay;
19
+ }
20
+
21
+ // virtual int available(void);
22
+ // virtual int peek(void);
23
+ // virtual int read(void);
24
+ // virtual int availableForWrite(void);
25
+ // virtual void flush(void);
26
+ virtual size_t write(uint8_t aChar) {
27
+ mGodmodeDataOut->append(String((char)aChar));
28
+ advertiseByte((unsigned char)aChar);
29
+ return 1;
30
+ }
31
+
32
+ // https://stackoverflow.com/a/4271276
33
+ using Print::write; // pull in write(str) and write(buf, size) from Print
34
+
35
+ };
36
+
@@ -167,6 +167,16 @@ def display_files(pathname)
167
167
  non_hidden.each { |p| puts "#{margin}#{p}" }
168
168
  end
169
169
 
170
+ def install_arduino_library_dependencies(aux_libraries)
171
+ aux_libraries.each do |l|
172
+ if @arduino_cmd.library_present?(l)
173
+ inform("Using pre-existing library") { l.to_s }
174
+ else
175
+ assure("Installing aux library '#{l}'") { @arduino_cmd.install_library(l) }
176
+ end
177
+ end
178
+ end
179
+
170
180
  def perform_unit_tests(file_config)
171
181
  if @cli_options[:skip_unittests]
172
182
  inform("Skipping unit tests") { "as requested via command line" }
@@ -209,6 +219,8 @@ def perform_unit_tests(file_config)
209
219
  elsif config.platforms_to_unittest.empty?
210
220
  inform("Skipping unit tests") { "no platforms were requested" }
211
221
  else
222
+ install_arduino_library_dependencies(config.aux_libraries_for_unittest)
223
+
212
224
  config.platforms_to_unittest.each do |p|
213
225
  config.allowable_unittest_files(cpp_library.test_files).each do |unittest_path|
214
226
  unittest_name = unittest_path.basename.to_s
@@ -273,7 +285,7 @@ def perform_compilation_tests(config)
273
285
  # while we're doing that, get the aux libraries as well
274
286
  example_platform_info = {}
275
287
  board_package_url = {}
276
- aux_libraries = Set.new(config.aux_libraries_for_unittest + config.aux_libraries_for_build)
288
+ aux_libraries = Set.new(config.aux_libraries_for_build)
277
289
  # while collecting the platforms, ensure they're defined
278
290
 
279
291
  library_examples.each do |path|
@@ -322,13 +334,7 @@ def perform_compilation_tests(config)
322
334
  end
323
335
  end
324
336
 
325
- aux_libraries.each do |l|
326
- if @arduino_cmd.library_present?(l)
327
- inform("Using pre-existing library") { l.to_s }
328
- else
329
- assure("Installing aux library '#{l}'") { @arduino_cmd.install_library(l) }
330
- end
331
- end
337
+ install_arduino_library_dependencies(aux_libraries)
332
338
 
333
339
  last_board = nil
334
340
  if config.platforms_to_build.empty?
@@ -6,6 +6,9 @@ WORKAROUND_LIB = "USBHost".freeze
6
6
 
7
7
  module ArduinoCI
8
8
 
9
+ # To report errors that we can't resolve or possibly even explain
10
+ class ArduinoExecutionError < StandardError; end
11
+
9
12
  # Wrap the Arduino executable. This requires, in some cases, a faked display.
10
13
  class ArduinoCmd
11
14
 
@@ -42,14 +45,14 @@ module ArduinoCI
42
45
  attr_reader :last_msg
43
46
 
44
47
  # set the command line flags (undefined for now).
45
- # These vary between gui/cli
46
- flag :get_pref
47
- flag :set_pref
48
- flag :save_prefs
49
- flag :use_board
50
- flag :install_boards
51
- flag :install_library
52
- flag :verify
48
+ # These vary between gui/cli. Inline comments added for greppability
49
+ flag :get_pref # flag_get_pref
50
+ flag :set_pref # flag_set_pref
51
+ flag :save_prefs # flag_save_prefs
52
+ flag :use_board # flag_use_board
53
+ flag :install_boards # flag_install_boards
54
+ flag :install_library # flag_install_library
55
+ flag :verify # flag_verify
53
56
 
54
57
  def initialize
55
58
  @prefs_cache = {}
@@ -82,7 +85,8 @@ module ArduinoCI
82
85
  # @return [String] Preferences as a set of lines
83
86
  def _prefs_raw
84
87
  resp = run_and_capture(flag_get_pref)
85
- return nil unless resp[:success]
88
+ fail_msg = "Arduino binary failed to operate as expected; you will have to troubleshoot it manually"
89
+ raise ArduinoExecutionError, "#{fail_msg}. The command was #{@last_msg}" unless resp[:success]
86
90
 
87
91
  @prefs_fetched = true
88
92
  resp[:out]
@@ -293,9 +293,12 @@ module ArduinoCI
293
293
  return paths if @unittest_info[:testfiles].nil?
294
294
 
295
295
  ret = paths
296
+ # Check for array emptiness, otherwise nothing will be selected!
296
297
  unless @unittest_info[:testfiles][:select].nil? || @unittest_info[:testfiles][:select].empty?
297
298
  ret.select! { |p| unittest_info[:testfiles][:select].any? { |glob| p.basename.fnmatch(glob) } }
298
299
  end
300
+
301
+ # It's OK for the :reject array to be empty, that means nothing will be rejected by default
299
302
  unless @unittest_info[:testfiles][:reject].nil?
300
303
  ret.reject! { |p| unittest_info[:testfiles][:reject].any? { |glob| p.basename.fnmatch(glob) } }
301
304
  end
@@ -220,7 +220,10 @@ module ArduinoCI
220
220
  # TODO: be smart and implement library spec (library.properties, etc)?
221
221
  subdirs = ["", "src", "utility"]
222
222
  all_aux_include_dirs_nested = aux_libraries.map do |libdir|
223
- subdirs.map { |subdir| Pathname.new(@arduino_lib_dir) + libdir + subdir }
223
+ # library manager coerces spaces in package names to underscores
224
+ # see https://github.com/ianfixes/arduino_ci/issues/132#issuecomment-518857059
225
+ legal_libdir = libdir.tr(" ", "_")
226
+ subdirs.map { |subdir| Pathname.new(@arduino_lib_dir) + legal_libdir + subdir }
224
227
  end
225
228
  all_aux_include_dirs_nested.flatten.select(&:exist?).select(&:directory?)
226
229
  end
@@ -1,3 +1,3 @@
1
1
  module ArduinoCI
2
- VERSION = "0.2.0".freeze
2
+ VERSION = "0.2.1".freeze
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: arduino_ci
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.2.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ian Katz
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2019-02-20 00:00:00.000000000 Z
11
+ date: 2019-08-12 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: os
@@ -137,6 +137,7 @@ files:
137
137
  - cpp/arduino/Stream.h
138
138
  - cpp/arduino/WCharacter.h
139
139
  - cpp/arduino/WString.h
140
+ - cpp/arduino/Wire.h
140
141
  - cpp/arduino/avr/README.md
141
142
  - cpp/arduino/avr/common.h
142
143
  - cpp/arduino/avr/fuse.h
@@ -416,6 +417,7 @@ files:
416
417
  - cpp/arduino/ci/DeviceUsingBytes.h
417
418
  - cpp/arduino/ci/ObservableDataStream.h
418
419
  - cpp/arduino/ci/README.md
420
+ - cpp/arduino/ci/StreamTape.h
419
421
  - cpp/arduino/ci/Table.h
420
422
  - cpp/arduino/stdlib.cpp
421
423
  - cpp/arduino/stdlib.h