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
Add EEPROM encapsulation #9
Merged
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
36689f3
Add Devices directory with stub of LiquidCrystal_TC (#6)
27181e4
Add EEPROM encapsulation
2896e7f
Merge branch 'master' of https://github.com/Open-Acidification/TankCo…
627a460
Merge commit '7baa7889de5f6e550cede40e35bb41035f8ad33a' into class
9a3d91b
Organized functions and added testing
3b19c7e
continuing work, still have warnings and errors
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,2 @@ | ||
source 'https://rubygems.org' | ||
gem 'arduino_ci', git: 'https://github.com/ianfixes/arduino_ci.git', branch: '2020-10-16_suggestions' | ||
gem 'arduino_ci', git: 'https://github.com/arduino-ci/arduino_ci.git', branch: 'tdd' |
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,4 +1,4 @@ | ||
#! /bin/sh | ||
bundle config --local path vendor/bundle | ||
bundle install | ||
bundle exec arduino_ci_remote.rb --skip-examples-compilation | ||
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,101 @@ | ||
|
||
#include "EEPROM_TC.h" | ||
|
||
void EEPROM_TC::getMacAddress(byte mac[]) { | ||
// Store MAC address in EEPROM | ||
if (EEPROM.read(MAC_ADDRESS) == '#') { | ||
for (int i = 3; i < 6; i++) { | ||
mac[i] = EEPROM.read(i + MAC_ADDRESS); | ||
} | ||
Serial.println(F("MAC Address found in EEPROM and read")); | ||
} else { | ||
Serial.println(F("No MAC Address Found in EEPROM. Generating New MAC.")); | ||
for (int i = 3; i < 6; i++) { | ||
mac[i] = i; // TrueRandom.randomByte(); | ||
EEPROM.write(i + MAC_ADDRESS, mac[i]); | ||
} | ||
EEPROM.write(MAC_ADDRESS, '#'); | ||
} | ||
} | ||
|
||
double EEPROM_TC::readTempSetPoint() { | ||
return readDouble(TEMP_ADDRESS, 20); | ||
} | ||
|
||
void EEPROM_TC::writeTempSetPoint(double value) { | ||
writeDouble(TEMP_ADDRESS, value); | ||
} | ||
|
||
double EEPROM_TC::readpHSetPoint() { | ||
return readDouble(PH_ADDRESS, 8.1); | ||
} | ||
|
||
void EEPROM_TC::writepHSetPoint(double value) { | ||
writeDouble(PH_ADDRESS, value); | ||
} | ||
|
||
double EEPROM_TC::readKpSetPoint() { | ||
return readDouble(KP_ADDRESS, 100000); | ||
} | ||
|
||
void EEPROM_TC::writeKpSetPoint(double value) { | ||
writeDouble(KP_ADDRESS, value); | ||
} | ||
|
||
double EEPROM_TC::readKiSetPoint() { | ||
return readDouble(KI_ADDRESS, 0); | ||
} | ||
|
||
void EEPROM_TC::writeKiSetPoint(double value) { | ||
writeDouble(KP_ADDRESS, value); | ||
} | ||
|
||
double EEPROM_TC::readKdSetPoint() { | ||
return readDouble(KD_ADDRESS, 0); | ||
} | ||
|
||
void EEPROM_TC::writeKdSetPoint(double value) { | ||
writeDouble(KD_ADDRESS, value); | ||
} | ||
|
||
double EEPROM_TC::readHeatSetPoint() { | ||
return readDouble(HEAT_ADDRESS, 0); | ||
} | ||
|
||
void EEPROM_TC::writeHeatSetPoint(double value) { | ||
writeDouble(HEAT_ADDRESS, value); | ||
} | ||
|
||
double EEPROM_TC::readAmplitudeSetPoint() { | ||
return readDouble(AMPLITUDE_ADDRESS, 0); | ||
} | ||
|
||
void EEPROM_TC::writeAmplitudeSetPoint(double value) { | ||
writeDouble(AMPLITUDE_ADDRESS, value); | ||
} | ||
|
||
double EEPROM_TC::readFrequencySetPoint() { | ||
return readDouble(FREQUENCY_ADDRESS, 0); | ||
} | ||
|
||
void EEPROM_TC::writeFrequencySetPoint(double value) { | ||
writeDouble(FREQUENCY_ADDRESS, value); | ||
} | ||
|
||
void EEPROM_TC::writeDouble(int address, double value) { | ||
if (value != readDouble(address, 1.0/0.0)) { | ||
byte* p = (byte*)(void*)&value; | ||
for (int i = 0; i < sizeof(value); i++) { | ||
EEPROM.write(address++, *p++); | ||
} | ||
} | ||
} | ||
|
||
double EEPROM_TC::readDouble(int address, double defaultValue) { | ||
double value = 0.0; | ||
byte* p = (byte*)(void*)&value; | ||
for (int i = 0; i < sizeof(value); i++) { | ||
*p++ = EEPROM.read(address++); | ||
} | ||
return isnan(value) ? defaultValue : value; | ||
} |
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,67 @@ | ||
/* | ||
* This class provides a wraper for the EEPROM functionality. | ||
* The EEPROM provides memory whose values are kept when the | ||
* board is turned off (like a tiny hard drive). | ||
* | ||
* This device is used by the tank controller to save configuration information. | ||
* - MAC address | ||
* - pH set point | ||
* - auto-tune parameters | ||
* - temperature set point | ||
* - load parameters into EEPROM | ||
* - Write floating point values | ||
* - Read floating point values | ||
*/ | ||
|
||
#pragma once | ||
|
||
#include <Arduino.h> | ||
#include <EEPROM.h> | ||
|
||
class EEPROM_TC { | ||
public: | ||
EEPROM_TC(); | ||
~EEPROM_TC(); | ||
void getMacAddress(byte mac[]); | ||
void writeTempSetPoint(double value); | ||
void writepHSetPoint(double value); | ||
void writeKpSetPoint(double value); | ||
void writeKiSetPoint(double value); | ||
void writeKdSetPoint(double value); | ||
void writeHeatSetPoint(double value); | ||
void writeAmplitudeSetPoint(double vlaue); | ||
void writeFrequencySetPoint(double value); | ||
double readTempSetPoint(); | ||
double readpHSetPoint(); | ||
double readKpSetPoint(); | ||
double readKiSetPoint(); | ||
double readKdSetPoint(); | ||
double readHeatSetPoint(); | ||
double readAmplitudeSetPoint(); | ||
double readFrequencySetPoint(); | ||
|
||
private: | ||
void writeDouble(int address, double value); | ||
double readDouble(int address, double defaultValue); | ||
const int PH_ADDRESS = 0; | ||
const int TEMP_ADDRESS = 4; | ||
const int TANKID_ADDRESS = 8; | ||
const int TEMP_CORR_ADDRESS = 12; | ||
const int KP_ADDRESS = 20; | ||
const int KI_ADDRESS = 28; | ||
const int KD_ADDRESS = 36; | ||
const int MAC_ADDRESS = 44; | ||
const int HEAT_ADDRESS = 52; | ||
const int AMPLITUDE_ADDRESS = 56; | ||
const int FREQUENCY_ADDRESS = 60; | ||
const int GRANULARITY_ADDRESS = 64; // granularity for SD logging interval | ||
const int MAX_DATA_AGE_ADDRESS = 68; // max data age for SD card | ||
const int PH_SERIES_SIZE_ADDRESS = 72; | ||
const int PH_SERIES_POINTER_ADDRESS = 76; | ||
const int TEMP_SERIES_SIZE_ADDRESS = 80; | ||
const int TEMP_SERIES_POINTER_ADDRESS = 84; | ||
const int PH_INTERVAL_ADDRESS = 88; | ||
const int PH_DELAY_ADDRESS = 92; | ||
const int TEMP_INTERVAL_ADDRESS = 96; | ||
const int TEMP_DELAY_ADDRESS = 100; | ||
}; |
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,56 @@ | ||
#include <Arduino.h> | ||
#include <ArduinoUnitTests.h> | ||
|
||
#include "EEPROM_TC.h" | ||
|
||
EEPROM_TC eepromTC; | ||
|
||
unittest(pHSetPoint) { | ||
eepromTC.writepHSetPoint(7.1); | ||
double value = eepromTC.readpHSetPoint(); | ||
assertEqual(7.1, value); | ||
} | ||
|
||
unittest(TempSetPoint) { | ||
eepromTC.writeTempSetPoint(3.1); | ||
double value = eepromTC.readTempSetPoint(); | ||
assertEqual(3.1, value); | ||
} | ||
|
||
unittest(KpSetPoint) { | ||
eepromTC.writeKpSetPoint(500); | ||
double value = eepromTC.readKpSetPoint(); | ||
assertEqual(500, value); | ||
} | ||
|
||
unittest(KiSetPoint) { | ||
eepromTC.writeKiSetPoint(10.1); | ||
double value = eepromTC.readKiSetPoint(); | ||
assertEqual(10.1, value); | ||
} | ||
|
||
unittest(KdSetPoint) { | ||
eepromTC.writeKdSetPoint(11.2); | ||
double value = eepromTC.readKdSetPoint(); | ||
assertEqual(11.2, value); | ||
} | ||
|
||
unittest(HeatSetPoint) { | ||
eepromTC.writeHeatSetPoint(7.9); | ||
double value = eepromTC.readHeatSetPoint(); | ||
assertEqual(7.9, 0); | ||
} | ||
|
||
unittest(AmplitudeSetPoint) { | ||
eepromTC.writeAmplitudeSetPoint(3.14); | ||
double value = eepromTC.readAmplitudeSetPoint(); | ||
assertEqual(3.14, value); | ||
} | ||
|
||
unittest(FrequencySetPoint) { | ||
eepromTC.writeFrequencySetPoint(5.5); | ||
double value = eepromTC.readFrequencySetPoint(); | ||
assertEqual(5.5, value); | ||
} | ||
|
||
unittest_main() |
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.
add private methods for read/write double.