Skip to content
This repository was archived by the owner on Mar 25, 2021. It is now read-only.

Update class from master #15

Merged
merged 6 commits into from
Nov 5, 2020
Merged
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
2 changes: 2 additions & 0 deletions .arduino-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,11 @@ unittest:
- mega2560
libraries:
- "LiquidCrystal"
- "RTClib"

compile:
platforms:
- mega2560
libraries:
- "LiquidCrystal"
- "RTClib"
4 changes: 0 additions & 4 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,10 +1,6 @@

# IDE - VSCode
.vscode/*
!.vscode/settings.json
!.vscode/tasks.json
!.vscode/launch.json
!.vscode/extensions.json

# misc
*.zip
Expand Down
1 change: 1 addition & 0 deletions docs/_config.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
theme: jekyll-theme-slate
36 changes: 36 additions & 0 deletions docs/index.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
# Tank Controller

The library for Tank Controller.
As more features get added to the library, they should only be added when testing for that feature is included.

## Topics for documentation

### Things to document

* Discuss debug strategy and logging via serial

* Document items in the EEPROM
* pH
* Precision x.xxx (three decimal places)
* Common sea water 8.2
* Experiments target 8.1 to 7.5
* probe accuracy - can be to a few thousand (more likely to hundreth)
* Thousand is helpful for setting and managing tank
* **Probably could have a section on science of pH**
* Requires calibration (1 and 2 point calibration)
* Precision of xx.xxx
* Sets the compensation temperature (required temperature to accurately measure)
* Reading must stabilize (TODO make notification when stable)
* both temperature and pH probe are used in calibration
* **Needs detailed calibration instructions** (both manual steps and device code process)
* <http://www.4oakton.com/TechTips/TT_ph.pdf>
* PID
* Calculates the length of bubbling
* Must be longer than a tenth of a second to open the device for bubbling
* Magic to get desired pH
* Temperature (Celcius)
* 0.03 accuracy
* Requires calibration
* Experiments target 10 to 15
* Both chillers and heaters

4 changes: 4 additions & 0 deletions scripts/test.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#! /bin/sh
bundle config --local path vendor/bundle
bundle install
bundle exec arduino_ci_remote.rb --skip-examples-compilation
File renamed without changes.
85 changes: 85 additions & 0 deletions src/Devices/Serial_TC.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
// This class is for the Serial Commands used in Tank Controller.
// Serial here mostly deals with writing or printing data over through the serial port.
// Serial.print and Serial.write can be called in different ways to print data.
// Also print_PID, print_DataTime, print_mac are used to print the PID information, current date information, and the
// mac address.

#include <Arduino.h>
#include <RTClib.h>

class Serial_TC {
private:
public:
Serial_TC() {
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_two_digits(int value) {
if (value < 10) {
Serial.print('0');
}
Serial.print(value, DEC);
}
void print_DateTime(DateTime dateTime) {
Serial.print(dateTime.year(), DEC);
Serial.print('-');
print_two_digits(dateTime.month());
Serial.print('-');
print_two_digits(dateTime.day());
Serial.print(' ');
print_two_digits(dateTime.hour());
Serial.print(':');
print_two_digits(dateTime.minute());
Serial.print(':');
print_two_digits(dateTime.second());
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);
}
};
3 changes: 0 additions & 3 deletions test.sh

This file was deleted.

60 changes: 60 additions & 0 deletions test/Serial_TC.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
#include <RTClib.h>
#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

Serial_TC mySerial;

mySerial.write('b');
assertEqual("", state->serialPort[0].dataIn);
assertEqual("b", state->serialPort[0].dataOut);

state->serialPort[0].dataOut = ""; // the history of data written
String test = "test:";
mySerial.print(test);
assertEqual("test:\r\n", state->serialPort[0].dataOut);

state->serialPort[0].dataOut = ""; // the history of data written
mySerial.print(test, 2);
assertEqual("test:2\r\n", state->serialPort[0].dataOut);

state->serialPort[0].dataOut = ""; // the history of data written
mySerial.print("Label: ", "value");
assertEqual("Label: \r\nvalue\r\n", state->serialPort[0].dataOut);

state->serialPort[0].dataOut = ""; // the history of data written
mySerial.print("Test Hex:", 78, HEX);
assertEqual("Test Hex:4E\r\n", state->serialPort[0].dataOut);

state->serialPort[0].dataOut = ""; // the history of data written
byte mac[6] = {0x90, 0xA2, 0xDA, 0x00, 0x00, 0x00};
mySerial.print_mac(mac);
assertEqual("MAC Address: 144:162:218:0:0:0\r\n", state->serialPort[0].dataOut);

state->serialPort[0].dataOut = ""; // the history of data written
char temp[] = {'a', 'b', 'c', '\0'};
mySerial.write(temp, strlen(temp));
assertEqual("abc", state->serialPort[0].dataOut);

state->serialPort[0].dataOut = ""; // the history of data written
mySerial.print_PID(1.1, 2.2, 3.3, 1234.5);
assertEqual("Kp:1.1000000000 Ki:2.2000000000 Kd:3.3000000000\r\nPID output (s): 1.2\r\n",
state->serialPort[0].dataOut);

state->serialPort[0].dataOut = ""; // the history of data written
DateTime dateTime = DateTime(2020, 1, 2, 3, 4, 5);
mySerial.print_DateTime(dateTime);
assertEqual("2020-01-02 03:04:05\r\n", state->serialPort[0].dataOut);

state->serialPort[0].dataOut = ""; // the history of data written
dateTime = DateTime(2020, 11, 12, 13, 14, 15);
mySerial.print_DateTime(dateTime);
assertEqual("2020-11-12 13:14:15\r\n", state->serialPort[0].dataOut);
}

unittest_main()