This repository was archived by the owner on Mar 25, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 12
Added Class and Tests for Serial #10
Merged
Merged
Changes from 3 commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
ee0fd13
Added Class and Tests for Serial
khalilxlj 5f7fe24
Update formatting
khalilxlj 26f8111
Updated tests for Serial println
khalilxlj 0b0e8c4
Updated tests and comments
khalilxlj 254dbda
Took out.vscode
khalilxlj 05f840d
Update and rename test.sh to scripts/test.sh
d5ca5d4
Update Serial_TC.cpp
1a0ea90
Update Serial_TC.h
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
{ | ||
"files.associations": { | ||
"ostream": "cpp" | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
// Year-Month-Day Format for DateTime | ||
khalilxl marked this conversation as resolved.
Show resolved
Hide resolved
|
||
// https://en.wikipedia.org/wiki/ISO_8601 | ||
|
||
#include <Arduino.h> | ||
#include <RTClib.h> | ||
|
||
class TC_Serial { | ||
khalilxl marked this conversation as resolved.
Show resolved
Hide resolved
|
||
private: | ||
const float RREF = 430.0; | ||
khalilxl marked this conversation as resolved.
Show resolved
Hide resolved
|
||
// RTC_PCF8523 rtc; | ||
|
||
public: | ||
TC_Serial() { | ||
Serial.begin(9600); | ||
} | ||
|
||
void print_PID(double Kp, double Ki, double Kd, double output) { | ||
Serial.print(F("Kp:")); | ||
Serial.print(Kp); | ||
Serial.print(F(" Ki:")); | ||
Serial.print(Ki); | ||
Serial.print(F(" Kd:")); | ||
Serial.println(Kd); | ||
Serial.print(F("PID output (s): ")); | ||
Serial.println(output / 1000, 1); | ||
} | ||
|
||
void print_DateTime(DateTime now) { | ||
khalilxl marked this conversation as resolved.
Show resolved
Hide resolved
|
||
Serial.print(now.year(), DEC); | ||
Serial.print('-'); | ||
Serial.print(now.month(), DEC); | ||
Serial.print('-'); | ||
Serial.print(now.day(), DEC); | ||
Serial.print(' '); | ||
Serial.print(now.hour(), DEC); | ||
Serial.print(':'); | ||
if (now.minute() < 10) { | ||
Serial.print('0'); | ||
} | ||
Serial.print(now.minute(), DEC); | ||
Serial.print(':'); | ||
if (now.second() < 10) { | ||
Serial.print('0'); | ||
} | ||
Serial.print(now.second(), DEC); | ||
Serial.println(); | ||
} | ||
|
||
void print_mac(byte mac[]) { | ||
Serial.print(F("MAC Address: ")); | ||
Serial.print(mac[0]); | ||
for (int i = 1; i < 6; ++i) { | ||
Serial.print(':'); | ||
Serial.print(mac[i]); | ||
} | ||
Serial.println(); | ||
} | ||
|
||
void print(String aString, String aString2) { | ||
Serial.println(aString); | ||
Serial.println(aString2); | ||
} | ||
|
||
void print(String aString, int anInt) { | ||
Serial.print(aString); | ||
Serial.println(anInt); | ||
} | ||
|
||
void print(String aString, int anInt, int format) { | ||
Serial.print(aString); | ||
Serial.println(anInt, format); | ||
} | ||
|
||
void print(String aString) { | ||
Serial.println(aString); | ||
} | ||
|
||
void write(byte aByte) { | ||
Serial.write(aByte); | ||
} | ||
|
||
void write(char arr[], int anInt) { | ||
Serial.write(arr, anInt); | ||
} | ||
}; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
#! /bin/sh | ||
bundle install --path vendor/bundle | ||
bundle config --local path vendor/bundle | ||
bundle install | ||
bundle exec arduino_ci_remote.rb --skip-compilation |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
#include <Serial_TC.h> | ||
|
||
#include "ArduinoUnitTests.h" | ||
|
||
unittest(SerialTest) { | ||
GodmodeState* state = GODMODE(); | ||
state->serialPort[0].dataIn = ""; // the queue of data waiting to be read | ||
state->serialPort[0].dataOut = ""; // the history of data written | ||
|
||
TC_Serial mySerial; | ||
|
||
assertTrue(true); | ||
|
||
mySerial.write('b'); | ||
assertEqual("", state->serialPort[0].dataIn); | ||
assertEqual("b", state->serialPort[0].dataOut); | ||
|
||
String test = "test:"; | ||
mySerial.print(test); | ||
assertEqual("", state->serialPort[0].dataIn); | ||
assertEqual("btest:\r\n", state->serialPort[0].dataOut); | ||
|
||
mySerial.print(test, 3); | ||
assertEqual("", state->serialPort[0].dataIn); | ||
assertEqual("btest:\r\ntest:3\r\n", state->serialPort[0].dataOut); | ||
} | ||
|
||
unittest_main() | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We should have tests for each of the public API functions. It wouldn't take much to add a few more. |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It doesn't seem that this file association should be necessary. In any case, please update
.gitignore
to remove lines 4-7 so that this isn't part of your PR.