Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Travis CI and basic unit tests to this library #1

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 39 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
sudo: false
language: ruby

# skip install step since we do it ourselves
install: true

# config for OSX, if desired
# os:
# - osx
# # (osx lib dir needs to be created at
# # /Users/travis/Documents/Arduino/libraries )

# Explicit config for linux, which is the default
# os:
# - linux
# # (linux lib dir needs to be created at
# # /home/travis/Arduino/libraries )


os:
- osx

script:
# switch to directory of Arduino library
- cd lib/AcceleratedLED328
- bundle install

# use the script to install Arduino executable
- bundle exec ensure_arduino_installation.rb

# manually download some Arduino libraries to get specific versions
- mkdir -p /Users/travis/Documents/Arduino/libraries
- pushd /Users/travis/Documents/Arduino/libraries
- git clone https://github.com/adafruit/Adafruit-WS2801-Library.git Adafruit_WS2801
- git clone https://github.com/annem/ADXL362.git
- popd

# run the CI script using the custom 3rd party libs
- bundle exec arduino_ci_remote.rb
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# AcceleratedLED
Controlls LEDs using input from Accelerometer
Controls LEDs using input from Accelerometer

# Setup

Expand Down
29 changes: 29 additions & 0 deletions lib/AcceleratedLED328/.arduino-ci.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
platforms:
pro:
board: arduino:avr:pro:cpu=16MHzatmega328
package: ~
gcc:
features:
defines:
- __AVR_ATmega328P__
warnings:
flags:

compile:
libraries:
- Bounce2
- Adafruit_WS2801
- ADXL362
platforms:
- pro

unittest:
libraries:
- Bounce2
- Adafruit_WS2801
- ADXL362
platforms:
- pro

compilers:
- g++
3 changes: 3 additions & 0 deletions lib/AcceleratedLED328/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# ignore unit test artifacts
*.cpp.bin
*.cpp.bin.dSYM
2 changes: 2 additions & 0 deletions lib/AcceleratedLED328/Gemfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
source 'https://rubygems.org'
gem 'arduino_ci'
21 changes: 21 additions & 0 deletions lib/AcceleratedLED328/Gemfile.lock
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
PATH
remote: /Users/ikatz/Development/non-wayfair/arduino_ci
specs:
arduino_ci (0.1.12)
os (~> 1.0)
rubyzip (~> 1.2)

GEM
remote: https://rubygems.org/
specs:
os (1.0.0)
rubyzip (1.2.2)

PLATFORMS
ruby

DEPENDENCIES
arduino_ci!

BUNDLED WITH
1.16.0
10 changes: 10 additions & 0 deletions lib/AcceleratedLED328/library.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
name=AcceleratedLED328
version=0.1.0
author=Ben Guest <benguest@gmail.com>
maintainer=Ben Guest <benguest@gmail.com>
sentence=Controls LEDs using input from Accelerometer
paragraph=Controls LEDs using input from Accelerometer, with several possible effects
category=Other
url=https://github.com/bguest/AcceleratedLED
architectures=avr
includes=AcceleratedLED328.h
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
16 changes: 16 additions & 0 deletions lib/AcceleratedLED328/test/pixel.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
#include <ArduinoUnitTests.h>
#include "../src/Pixel.h"

unittest(set_pixel_values)
{
Pixel p = Pixel();
assertEqual(255, p.color());
p.set(1, 10, 100);
assertEqual(6250596, p.color());
p.set(0, 0, 0);
assertEqual(0, p.color());
p.set(100, 10, 1);
assertEqual(1, p.color());
}

unittest_main()
43 changes: 43 additions & 0 deletions lib/AcceleratedLED328/test/strip.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
#include <ArduinoUnitTests.h>
#include "../src/Strip.h"

unittest(set_strip_values)
{
GodmodeState* state = GODMODE();
state->reset();

Strip s = Strip();
s.init(3, 2);

Pixel p = Pixel();
p.set(50, 50, 50);

s.setColor(p.hsv);
assertEqual(30, state->digitalPin[3].toAscii(1, true).length());

s.update();
assertEqual(60, state->digitalPin[3].toAscii(1, true).length());

// this is really a test of the underlying library, but whatever

// pin 2 is the clock pin, we expect 0xAA, which is 0b10101010
assertEqual(0xAA, (unsigned char)(state->digitalPin[2].toAscii(1, true)[0]));
assertEqual(0xAA, (unsigned char)(state->digitalPin[2].toAscii(1, true)[1]));
assertEqual(0xAA, (unsigned char)(state->digitalPin[2].toAscii(1, true)[2]));

// pin 3 is the data, we expect 3 byte groups, all zeroes
assertEqual(0, (unsigned int)(state->digitalPin[3].toAscii(1, true)[0]));
assertEqual(0, (unsigned int)(state->digitalPin[3].toAscii(1, true)[1]));
assertEqual(0, (unsigned int)(state->digitalPin[3].toAscii(1, true)[2]));

// the second 30 bytes will be our pixel color. not sure what to expect
// but I _do_ expect it to repeat
assertEqual(40, (unsigned int)(state->digitalPin[3].toAscii(1, true)[30]));
assertEqual(40, (unsigned int)(state->digitalPin[3].toAscii(1, true)[31]));
assertEqual(50, (unsigned int)(state->digitalPin[3].toAscii(1, true)[32]));
assertEqual(40, (unsigned int)(state->digitalPin[3].toAscii(1, true)[33]));
assertEqual(40, (unsigned int)(state->digitalPin[3].toAscii(1, true)[34]));
assertEqual(50, (unsigned int)(state->digitalPin[3].toAscii(1, true)[35]));
}

unittest_main()