Skip to content

Commit

Permalink
i-90: Fix duplication of board platforms
Browse files Browse the repository at this point in the history
Issue #90
  • Loading branch information
robgonnella committed Mar 6, 2022
1 parent e024075 commit 2894b21
Show file tree
Hide file tree
Showing 12 changed files with 98 additions and 38 deletions.
2 changes: 1 addition & 1 deletion v2/cli-wrapper/arduino-cli_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ func TestArduinoCli(t *testing.T) {

req := &rpc.PlatformSearchRequest{
Instance: rpcInst,
AllVersions: true,
AllVersions: false,
SearchArgs: "arduino:avr",
}

Expand Down
2 changes: 1 addition & 1 deletion v2/cli-wrapper/cli-wrapper.go
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,7 @@ func (w *Wrapper) SearchPlatforms() ([]*rpc.Platform, error) {

req := &rpc.PlatformSearchRequest{
Instance: inst,
AllVersions: true,
AllVersions: false,
}

resp, err := w.cli.PlatformSearch(req)
Expand Down
2 changes: 1 addition & 1 deletion v2/cli-wrapper/cli-wrapper_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,7 @@ func TestCliWrapperTest(t *testing.T) {

searchReq := &rpc.PlatformSearchRequest{
Instance: inst,
AllVersions: true,
AllVersions: false,
}

expectedResp := &rpc.PlatformSearchResponse{
Expand Down
6 changes: 6 additions & 0 deletions v2/commands/attach_and_watch_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -181,4 +181,10 @@ func TestAttachAndWatchCommand(t *testing.T) {
err := env.Execute(args)
assert.Error(env.T, err)
})

testutil.RunMockIntegrationTest("errors if project not initialized", t, func(env *testutil.MockIntegrationTestEnv) {
args := []string{"attach-and-watch"}
err := env.Execute(args)
assert.Error(env.T, err)
})
}
2 changes: 1 addition & 1 deletion v2/commands/list_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ func TestListBoardInfoCommands(t *testing.T) {

platformReq := &rpc.PlatformSearchRequest{
Instance: instance,
AllVersions: true,
AllVersions: false,
}

board := &rpc.Board{
Expand Down
4 changes: 2 additions & 2 deletions v2/commands/search_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ func TestSearchPlatformCommand(t *testing.T) {

searchReq := &rpc.PlatformSearchRequest{
Instance: instance,
AllVersions: true,
AllVersions: false,
}

searchResp := &rpc.PlatformSearchResponse{
Expand All @@ -150,7 +150,7 @@ func TestSearchPlatformCommand(t *testing.T) {
env.RunProjectInit()
searchReq := &rpc.PlatformSearchRequest{
Instance: instance,
AllVersions: true,
AllVersions: false,
}

dummyErr := errors.New("dummy error")
Expand Down
6 changes: 6 additions & 0 deletions v2/commands/upload_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -208,4 +208,10 @@ func TestUploadCommand(t *testing.T) {
err := env.Execute(args)
assert.Error(env.T, err)
})

testutil.RunMockIntegrationTest("errors if project not initialized", t, func(env *testutil.MockIntegrationTestEnv) {
args := []string{"upload", buildName, "--attach"}
err := env.Execute(args)
assert.Error(env.T, err)
})
}
8 changes: 4 additions & 4 deletions v2/core/board_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -276,7 +276,7 @@ func TestBoardCore(t *testing.T) {
instance := &rpc.Instance{Id: int32(1)}
req := &rpc.PlatformSearchRequest{
Instance: instance,
AllVersions: true,
AllVersions: false,
}
resp := &rpc.PlatformSearchResponse{SearchOutput: platforms}

Expand All @@ -298,7 +298,7 @@ func TestBoardCore(t *testing.T) {
instance := &rpc.Instance{Id: int32(1)}
req := &rpc.PlatformSearchRequest{
Instance: instance,
AllVersions: true,
AllVersions: false,
}
var resp *rpc.PlatformSearchResponse

Expand All @@ -319,7 +319,7 @@ func TestBoardCore(t *testing.T) {
instance := &rpc.Instance{Id: int32(1)}
req := &rpc.PlatformSearchRequest{
Instance: instance,
AllVersions: true,
AllVersions: false,
}
resp := &rpc.PlatformSearchResponse{SearchOutput: platforms}

Expand All @@ -341,7 +341,7 @@ func TestBoardCore(t *testing.T) {
instance := &rpc.Instance{Id: int32(1)}
req := &rpc.PlatformSearchRequest{
Instance: instance,
AllVersions: true,
AllVersions: false,
}
var resp *rpc.PlatformSearchResponse

Expand Down
13 changes: 7 additions & 6 deletions v2/core/file_watcher.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,9 @@ func NewFileWatcher(file string, logger *log.Logger) (*FileWatcher, error) {
return &FileWatcher{
file: file,
watcher: watcher,
stop: make(chan bool, 1),
close: make(chan bool, 1),
restart: make(chan bool, 1),
stop: make(chan bool),
close: make(chan bool),
restart: make(chan bool),
listeners: []Listener{},
logger: logger,
}, nil
Expand Down Expand Up @@ -85,7 +85,7 @@ func (f *FileWatcher) Watch() error {
if removeEvt {
if err := f.watcher.Add(f.file); err != nil {
f.logger.WithError(err).Error("file watcher error")
f.close <- true
f.Close()
return
}
}
Expand All @@ -95,13 +95,13 @@ func (f *FileWatcher) Watch() error {
}
case err := <-f.watcher.Errors:
f.logger.WithError(err).Error("Watch error")
f.close <- true
f.Close()
return
}
}
}()

// Block and wait for requests
// Block and wait for signals
for {
select {
case <-f.stop:
Expand All @@ -120,6 +120,7 @@ func (f *FileWatcher) Watch() error {
f.watcher.Close()
f.watcher = nil
}
f.close <- true
return nil
}
}
Expand Down
2 changes: 1 addition & 1 deletion v2/core/platform_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ func TestPlatformCore(t *testing.T) {
instance := &rpc.Instance{Id: int32(1)}
req := &rpc.PlatformSearchRequest{
Instance: instance,
AllVersions: true,
AllVersions: false,
}
resp := &rpc.PlatformSearchResponse{
SearchOutput: platforms,
Expand Down
38 changes: 38 additions & 0 deletions v2/core/serial_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,4 +64,42 @@ func TestSerialPort(t *testing.T) {
port.Close()
assert.False(st, port.Streaming())
})

t.Run("errors if device isn't set", func(st *testing.T) {
device := ""
baud := 9600
logger := logrus.New()
b := new(bytes.Buffer)

logger.SetOutput(b)
port := core.NewArdiSerialPort(logger)
port.SetTargets(device, baud)

st.Cleanup(func() {
port.Close()
port = nil
})

err := port.Watch()
assert.Error(st, err)
})

t.Run("errors if baud isn't set", func(st *testing.T) {
device := getPort()
baud := 0
logger := logrus.New()
b := new(bytes.Buffer)

logger.SetOutput(b)
port := core.NewArdiSerialPort(logger)
port.SetTargets(device, baud)

st.Cleanup(func() {
port.Close()
port = nil
})

err := port.Watch()
assert.Error(st, err)
})
}
51 changes: 30 additions & 21 deletions v2/test_projects/pixie/pixie.ino
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,16 @@
#include "Adafruit_Pixie.h"

#define NUMPIXELS 3 // Number of Pixies in the strip
#define PIXIEPIN 6 // Pin number for SoftwareSerial output
#define PIXIEPIN 6 // Pin number for SoftwareSerial output

SoftwareSerial pixieSerial(-1, PIXIEPIN);

Adafruit_Pixie strip = Adafruit_Pixie(NUMPIXELS, &pixieSerial);
// Alternately, can use a hardware serial port for output, e.g.:
// Adafruit_Pixie strip = Adafruit_Pixie(NUMPIXELS, &Serial1);

void setup() {
void setup()
{
int i;

Serial.begin(9600);
Expand All @@ -28,57 +29,65 @@ void setup() {
pixieSerial.begin(115200); // Pixie REQUIRES this baud rate
// Serial1.begin(115200); // <- Alt. if using hardware serial port

strip.setBrightness(200); // Adjust as necessary to avoid blinding
strip.setBrightness(200); // Adjust as necessary to avoid blinding

Serial.println("Red");
for(i=0; i< NUMPIXELS; i++)
for (i = 0; i < NUMPIXELS; i++)
strip.setPixelColor(i, 255, 0, 0);
strip.show();
delay(300);

Serial.println("Green");
for(i=0; i< NUMPIXELS; i++)
for (i = 0; i < NUMPIXELS; i++)
strip.setPixelColor(i, 0, 255, 0);
strip.show();
delay(300);

Serial.println("Blue");
for(i=0; i< NUMPIXELS; i++)
for (i = 0; i < NUMPIXELS; i++)
strip.setPixelColor(i, 0, 0, 255);
strip.show();
delay(300);
}

void loop() {
void loop()
{
Serial.println("Rainbow");
rainbowCycle(10);
}


// Slightly different, this makes the rainbow equally distributed throughout
void rainbowCycle(uint8_t wait) {
void rainbowCycle(uint8_t wait)
{
uint16_t i, j;

for(j=0; j<256*5; j++) { // 5 cycles of all colors on wheel
for(i=0; i< NUMPIXELS; i++) {
for (j = 0; j < 256 * 5; j++)
{ // 5 cycles of all colors on wheel
for (i = 0; i < NUMPIXELS; i++)
{
strip.setPixelColor(i, Wheel(((i * 256 / strip.numPixels()) + j) & 255));
}
strip.show();
delay(wait);
}
}


// Input a value 0 to 255 to get a color value.
// The colours are a transition r - g - b - back to r.
uint32_t Wheel(byte WheelPos) {
if(WheelPos < 85) {
return strip.Color(WheelPos * 3, 255 - WheelPos * 3, 0);
} else if(WheelPos < 170) {
WheelPos -= 85;
return strip.Color(255 - WheelPos * 3, 0, WheelPos * 3);
} else {
WheelPos -= 170;
return strip.Color(0, WheelPos * 3, 255 - WheelPos * 3);
uint32_t Wheel(byte WheelPos)
{
if (WheelPos < 85)
{
return strip.Color(WheelPos * 3, 255 - WheelPos * 3, 0);
}
else if (WheelPos < 170)
{
WheelPos -= 85;
return strip.Color(255 - WheelPos * 3, 0, WheelPos * 3);
}
else
{
WheelPos -= 170;
return strip.Color(0, WheelPos * 3, 255 - WheelPos * 3);
}
}

0 comments on commit 2894b21

Please sign in to comment.