Skip to content

Commit

Permalink
Changes submitted by Ron aka rescotti47
Browse files Browse the repository at this point in the history
  • Loading branch information
sarfata committed Nov 23, 2017
1 parent f8a0f7f commit 2a63483
Show file tree
Hide file tree
Showing 14 changed files with 196 additions and 89 deletions.
10 changes: 7 additions & 3 deletions lib/KBox/src/KBox.cpp
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -45,11 +45,13 @@ void KBox::setup() {
neopixels.show();

// Initialize serialports
digitalWrite(nmea1_out_enable, 0);
//RES_MOD_11_6_17 enable nmea1 output - set one to 'high' 1`?!
digitalWrite(nmea1_out_enable, 1);
digitalWrite(nmea2_out_enable, 0);
pinMode(nmea1_out_enable, OUTPUT);
pinMode(nmea2_out_enable, OUTPUT);
NMEA1_SERIAL.begin(38400);
//RES_MOD_7_25_17 set baud rate for NMEA0183
NMEA1_SERIAL.begin(4800);
NMEA2_SERIAL.begin(38400);

// Initialize ADC
Expand All @@ -71,11 +73,13 @@ void KBox::setup() {
//adc.setConversionSpeed(ADC_LOW_SPEED, ADC_1);
//adc.setSamplingSpeed(ADC_HIGH_SPEED, ADC_1);


taskManager.addTask(&mfd);
taskManager.setup();
}

void KBox::loop() {
taskManager.loop();
//RES_MOD_11_6_17 add next line to test writting to NMEA1 out
NMEA1_SERIAL.write("in loop");
DEBUG("debug in loop");
}
7 changes: 4 additions & 3 deletions lib/KBox/src/KMessage.h
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,9 @@ class KMessage {
class KVisitor {
public:
virtual void visit(const NMEASentence &) {};
virtual void visit(const BarometerMeasurement &) {};
virtual void visit(const VoltageMeasurement &) {};
virtual void visit(const NMEA2000Message &) {};
virtual void visit(const BarometerMeasurement &) {};
virtual void visit(const IMUMessage &) {};
};

Expand Down Expand Up @@ -180,14 +180,15 @@ class IMUMessage: public KMessage {
* Pitch in radians. Positive when bow rises.
*/
double getPitch() const {
return pitch;
return pitch;
};

/*
* Roll in radians. Positive when tilted right.
*/

double getRoll() const {
return roll;
return roll;
};
};

Expand Down
87 changes: 51 additions & 36 deletions lib/KBox/src/KMessageNMEAVisitor.cpp
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -23,28 +23,14 @@
*/

#include "KMessageNMEAVisitor.h"
#include "KBoxDebug.h"
#include "util/NMEASentenceBuilder.h"
#include "util/nmea2000.h"

void KMessageNMEAVisitor::visit(const NMEASentence& s) {
nmeaContent += s.getSentence() + "\r\n";
}

void KMessageNMEAVisitor::visit(const BarometerMeasurement &bm) {
// XDR is not a very well defined sentence. Can be used for lots of things
// apparently but that is better than nothing.
NMEASentenceBuilder sb("II", "XDR", 8);
sb.setField(1, "P");
sb.setField(2, bm.getPressure(), 5);
sb.setField(3, "B");
sb.setField(4, "Barometer");
sb.setField(5, "T");
sb.setField(6, bm.getTemperature());
sb.setField(7, "C");
sb.setField(8, "TempAir");
nmeaContent += sb.toNMEA() + "\r\n";
}

void KMessageNMEAVisitor::visit(const VoltageMeasurement &vm) {
NMEASentenceBuilder sb("II", "XDR", 4);
sb.setField(1, "V");
Expand All @@ -63,37 +49,66 @@ void KMessageNMEAVisitor::visit(const NMEA2000Message &n2km) {
free(s);
}

void KMessageNMEAVisitor::visit(const BarometerMeasurement &bm) {
// XDR is not a very well defined sentence. Can be used for lots of things
// apparently but that is better than nothing.
double respressure = bm.getPressure();
//RES_MOD_7_29_17 convert pressure to Bar not hBar - 5 decimal places
respressure = respressure/100000;
NMEASentenceBuilder sb("II", "XDR", 8);
sb.setField(1, "P");
sb.setField(2, respressure, 5);
sb.setField(3, "B");
sb.setField(4, "Barometer");
sb.setField(5, "C");
sb.setField(6, bm.getTemperature());
sb.setField(7, "C");
sb.setField(8, "TempAir");
nmeaContent += sb.toNMEA() + "\r\n";
}

inline static double RadToDeg(double v) { return v*180.0/3.1415926535897932384626433832795; }

//RES_MOD_7_29_17 for OpenCPN drop yaw data now only 12 instead of 16 data
// part of message, switch pitch and roll to match my mount
void KMessageNMEAVisitor::visit(const IMUMessage &imu) {
NMEASentenceBuilder sb("II", "XDR", 16);
NMEASentenceBuilder sb("II", "XDR", 12);
//sb.setField(1, "A");
//sb.setField(2, imu.getYaw(), 1);
//sb.setField(3, "D");
//sb.setField(4, "Yaw");

//RES_MOD_7_29_17 DEFINE NEW VARIABLEs TO ADD OFFSET to pitch and roll
// and switch pitch and roll for my mounting, adjust SetField
double resrolloffset = imu.getPitch();
double resptchoffset = imu.getRoll();
resrolloffset = - resrolloffset;
resptchoffset = - resptchoffset;
sb.setField(1, "A");
sb.setField(2, RadToDeg(imu.getYaw()), 1);
//RES_MOD_7_29_17 use new variable
//sb.setField(6, imu.getPitch(), 1);
sb.setField(2, resrolloffset, 1);
sb.setField(3, "D");
sb.setField(4, "Yaw");
//make pitch to be roll
sb.setField(4, "ROLL");

sb.setField(5, "A");
sb.setField(6, RadToDeg(imu.getPitch()), 1);
//sb.setField(10, imu.getRoll(), 1);
sb.setField(6, resptchoffset, 1);
sb.setField(7, "D");
sb.setField(8, "Pitch");
// make roll to be pitch; PTCH in OpenCPN
sb.setField(8, "PTCH");

sb.setField(9, "A");
sb.setField(10, RadToDeg(imu.getRoll()), 1);
sb.setField(11, "D");
sb.setField(12, "Roll");

sb.setField(13, "");
sb.setField(14, imu.getCalibration());
sb.setField(15, "");
sb.setField(16, "Calibration");
sb.setField(9, "");
sb.setField(10, imu.getCalibration());
sb.setField(11, "");
sb.setField(12, "Calibration");

nmeaContent += sb.toNMEA() + "\r\n";

NMEASentenceBuilder sb2("II", "HDM", 2);
sb2.setField(1, RadToDeg(imu.getCourse()));
sb2.setField(2, "M");
//RES_MOD_10_28_17 remove HDM output, as repeated from GPS
//NMEASentenceBuilder sb2("II", "HDM", 2);
//sb2.setField(1, imu.getCourse());
//sb2.setField(2, "M");

nmeaContent += sb2.toNMEA() + "\r\n";
}
//nmeaContent += sb2.toNMEA() + "\r\n";

}
3 changes: 2 additions & 1 deletion lib/KBox/src/TaskManager.cpp
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,8 @@ void TaskManager::loop() {
loopStats.recordRun(loopTimer);

if (statDisplayTimer > statDisplayInterval) {
displayStats();
//RES_MOD_10_28_17 remove stat display
// displayStats();
statDisplayTimer = 0;
}
}
Expand Down
51 changes: 37 additions & 14 deletions lib/KBox/src/pages/BatteryMonitorPage.cpp
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -35,17 +35,19 @@ BatteryMonitorPage::BatteryMonitorPage() {

addLayer(new TextLayer(Point(col1, row1), Size(20, 20), "House Battery", ColorWhite, ColorBlack, FontDefault));
addLayer(new TextLayer(Point(col2, row1), Size(20, 20), "House Current", ColorWhite, ColorBlack, FontDefault));
addLayer(new TextLayer(Point(col1, row3), Size(20, 20), "Engine Battery", ColorWhite, ColorBlack, FontDefault));
addLayer(new TextLayer(Point(col1, row3), Size(20, 20), "Baro Pressure", ColorWhite, ColorBlack, FontDefault));
addLayer(new TextLayer(Point(col2, row3), Size(20, 20), "Supply Voltage", ColorWhite, ColorBlack, FontDefault));

houseVoltage = new TextLayer(Point(col1, row2), Size(20, 20), "--", ColorWhite, ColorBlack, FontLarge);
houseCurrent = new TextLayer(Point(col2, row2), Size(20, 20), "--", ColorWhite, ColorBlack, FontLarge);
starterVoltage = new TextLayer(Point(col1, row4), Size(20, 20), "--", ColorWhite, ColorBlack, FontLarge);
baroPressure = new TextLayer(Point(col1, row4), Size(20, 20), "101.535", ColorWhite, ColorBlack, FontLarge);
supplyVoltage = new TextLayer(Point(col2, row4), Size(20, 20), "--", ColorWhite, ColorBlack, FontLarge);

addLayer(houseVoltage);
addLayer(houseCurrent);
addLayer(starterVoltage);
//RES_MOD_10_28_17 substatue baroPressure for starterVoltage see above also
addLayer(baroPressure);
//addLayer(starterVoltage);
addLayer(supplyVoltage);
}

Expand All @@ -57,35 +59,56 @@ Color BatteryMonitorPage::colorForVoltage(float v) {
return ColorRed;
}
if (v < 13.5) {
return ColorGreen;
}
return ColorBlue;
}

//RES_MOD_10_28_17 add color for pressure
Color BatteryMonitorPage::colorForPressure(float b) {
return ColorRed;
}
String BatteryMonitorPage::formatMeasurement(float measure, const char *unit) {
// extra spaces at the end needed to clear previous value completely
// (we use a non-fixed width font)
char s[10];
//RES_MOD_10_28_17 change format to 6.2?
//snprintf(s, sizeof(s), "%6.2f %s ", measure, unit);
if (unit = "V"){
snprintf(s, sizeof(s), "%.1f %s ", measure, unit);
return String(s);
}
else {
snprintf(s, sizeof(s), "%8.4f %s ", measure, unit);
}
return String(s);
}

void BatteryMonitorPage::processMessage(const KMessage &message) {
message.accept(*this);
}

//RES_MOD_10_28_17 My playing around with the display
void BatteryMonitorPage::visit(const BarometerMeasurement &bm) {
//double respressure = bm.getPressure();
//RES_MOD_7_29_17 convert pressure to Bar not hBar - 5 decimal places
//respressure = respressure/1000;
//respressure = 101.3;
DEBUG(" pressure from BatteryMonitorPage", bm.getTemperature());
baroPressure->setText(formatMeasurement(bm.getTemperature(), "C"));
baroPressure->setColor(colorForPressure(bm.getTemperature()));
}

void BatteryMonitorPage::visit(const VoltageMeasurement &vm) {
if (vm.getLabel() == "house") {
houseVoltage->setText(formatMeasurement(vm.getVoltage(), "V"));
houseVoltage->setColor(colorForVoltage(vm.getVoltage()));
}
houseVoltage->setText(formatMeasurement(vm.getVoltage(), "V"));
houseVoltage->setColor(colorForVoltage(vm.getVoltage()));
DEBUG("print from Display", vm.getVoltage());
}
if (vm.getLabel() == "supply") {
supplyVoltage->setText(formatMeasurement(vm.getVoltage(), "V"));
supplyVoltage->setColor(colorForVoltage(vm.getVoltage()));
}
if (vm.getLabel() == "starter") {
starterVoltage->setText(formatMeasurement(vm.getVoltage(), "V"));
starterVoltage->setColor(colorForVoltage(vm.getVoltage()));
}
//if (vm.getLabel() == "starter") {
//Original below
//starterVoltage->setText(formatMeasurement(vm.getVoltage(), "V"));
//starterVoltage->setColor(colorForVoltage(vm.getVoltage()));
//}
}

11 changes: 10 additions & 1 deletion lib/KBox/src/pages/BatteryMonitorPage.h
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -25,17 +25,26 @@
#include "MFD.h"
#include "KMessage.h"
#include "ui/TextLayer.h"
//RES_MOD_10_28_17 indclude DEBUG
#include "KBoxDebug.h"

class BatteryMonitorPage : public Page, public KReceiver, public KVisitor {
private:
TextLayer *houseVoltage, *houseCurrent, *starterVoltage, *supplyVoltage;
//RES_MOD_10_28_17 substatue baroPressure for starterVoltage
TextLayer *houseVoltage, *houseCurrent, *baroPressure, *supplyVoltage;

Color colorForVoltage(float v);
String formatMeasurement(float measure, const char *unit);

//RES_MOD_10_28_17 setup color for Pressure
Color colorForPressure(float b);


public:
BatteryMonitorPage();

void processMessage(const KMessage& message);
void visit(const VoltageMeasurement&);
//RES_MOD_10_28_17 add this to public
void visit(const BarometerMeasurement&);
};
4 changes: 2 additions & 2 deletions lib/KBox/src/tasks/BarometerTask.cpp
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,8 @@ void BarometerTask::setup() {
void BarometerTask::fetchValues() {
temperature = bmp280.readTemperature();
pressure = bmp280.readPressure();

DEBUG("Read temperature=%.2f C and pressure=%.1f hPa", temperature, pressure/100);
//RES_MOD_10_28_17 clean up debug output to nmea cmmds only
//DEBUG("Read temperature=%.2f C and pressure=%.1f hPa", temperature, pressure/100);
BarometerMeasurement m(temperature, pressure);
sendMessage(m);
}
Expand Down
9 changes: 7 additions & 2 deletions lib/KBox/src/tasks/SDCardTask.cpp
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -59,11 +59,16 @@ void SDCardTask::loop() {
if (!isLogging()) {
return;
}
for (LinkedList<Loggable>::iterator it = receivedMessages.begin(); it != receivedMessages.end(); it++) {
for (LinkedList<Loggable>::iterator it = receivedMessages.begin(); it != receivedMessages.end(); it++) {
logFile->print(it->timestamp);
logFile->print(",");
logFile->print(it->_message);
logFile->println();
//RES_MOD_10_28_17 send character message to DEBUG
const char *messagecpy = (it->_message.c_str());
//DEBUG("Nmea data to follow","\n");
DEBUG(messagecpy);
//end of my MOD
}
// Force data to SD and update the directory entry to avoid data loss.
if (!logFile->sync() || logFile->getWriteError()) {
Expand Down Expand Up @@ -154,7 +159,7 @@ uint64_t SDCardTask::getFreeSpace() const {
// the running led stops flashing (although we do still call digitalWrite on it)
// the serial ports start messing up big time (missing a lot of data)
// eventually other things crash...
// Could be a memory problem or something like that. Have not found
// Could be a memory problem or something like that. Have not found
// it yet but the culprit is this line so for now it is disabled.
uint64_t space = 0; //logFile->volume()->freeClusterCount();
space *= logFile->volume()->blocksPerCluster();
Expand Down
3 changes: 3 additions & 0 deletions lib/KBox/src/tasks/SDCardTask.h
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,9 @@ class SDCardTask : public Task, public KReceiver {
LinkedList<Loggable> receivedMessages;

public:
//RES_MOD_10_28_17 add messagecpy to public string
String messagecpy() const;
//end of my add
SDCardTask();
virtual ~SDCardTask();

Expand Down
9 changes: 6 additions & 3 deletions lib/KBox/src/tasks/WiFiTask.cpp
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -41,11 +41,14 @@ void WiFiTask::loop() {
if (rxBuf[rxIndex - 1] == '\n') {
rxBuf[rxIndex - 1] = 0;
DEBUG("WiFi: %s", rxBuf);
//RES_MOD_10_28_17 add a blank line in output
DEBUG("");
rxIndex = 0;
}
if (rxIndex >= sizeof(rxBuf) - 1) {
rxBuf[rxIndex] = 0;
DEBUG("WiFi full: %s", rxBuf);
DEBUG("");
rxIndex = 0;
}
}
Expand All @@ -62,13 +65,15 @@ void WiFiTask::loop() {
}

if (WiFiSerial.availableForWrite() <= 0) {
//DEBUG("Not sending because send buffer is full (need %i but %i available).", toSend.length(), WiFiSerial.availableForWrite());
//RES_MOD_9_6_17 comment debug
//DEBUG("Not sending because send buffer is full (need %i but %i available).", toSend.length(), WiFiSerial.availableForWrite());
break;
}
size_t available = WiFiSerial.availableForWrite();
String s = toSend;
s.remove(available);
size_t written = WiFiSerial.print(s);
//RES_MOD_9_6_17 comment debug
//DEBUG("Sent %i/%i (%i avail) of %s", written, toSend.length(), available, toSend.c_str());

if (written == toSend.length()) {
Expand Down Expand Up @@ -96,5 +101,3 @@ void WiFiTask::processMessage(const KMessage &m) {
m.accept(v);
sendQueue.add(v.toNMEA());
}


Loading

0 comments on commit 2a63483

Please sign in to comment.