Skip to content

Commit b608de7

Browse files
committed
Changes submitted by Ron aka rescotti47
1 parent f8a0f7f commit b608de7

14 files changed

+196
-89
lines changed

lib/KBox/src/KBox.cpp

100644100755
+7-3
Original file line numberDiff line numberDiff line change
@@ -45,11 +45,13 @@ void KBox::setup() {
4545
neopixels.show();
4646

4747
// Initialize serialports
48-
digitalWrite(nmea1_out_enable, 0);
48+
//RES_MOD_11_6_17 enable nmea1 output - set one to 'high' 1`?!
49+
digitalWrite(nmea1_out_enable, 1);
4950
digitalWrite(nmea2_out_enable, 0);
5051
pinMode(nmea1_out_enable, OUTPUT);
5152
pinMode(nmea2_out_enable, OUTPUT);
52-
NMEA1_SERIAL.begin(38400);
53+
//RES_MOD_7_25_17 set baud rate for NMEA0183
54+
NMEA1_SERIAL.begin(4800);
5355
NMEA2_SERIAL.begin(38400);
5456

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

74-
7576
taskManager.addTask(&mfd);
7677
taskManager.setup();
7778
}
7879

7980
void KBox::loop() {
8081
taskManager.loop();
82+
//RES_MOD_11_6_17 add next line to test writting to NMEA1 out
83+
NMEA1_SERIAL.write("in loop");
84+
DEBUG("debug in loop");
8185
}

lib/KBox/src/KMessage.h

100644100755
+4-3
Original file line numberDiff line numberDiff line change
@@ -47,9 +47,9 @@ class KMessage {
4747
class KVisitor {
4848
public:
4949
virtual void visit(const NMEASentence &) {};
50-
virtual void visit(const BarometerMeasurement &) {};
5150
virtual void visit(const VoltageMeasurement &) {};
5251
virtual void visit(const NMEA2000Message &) {};
52+
virtual void visit(const BarometerMeasurement &) {};
5353
virtual void visit(const IMUMessage &) {};
5454
};
5555

@@ -180,14 +180,15 @@ class IMUMessage: public KMessage {
180180
* Pitch in radians. Positive when bow rises.
181181
*/
182182
double getPitch() const {
183-
return pitch;
183+
return pitch;
184184
};
185185

186186
/*
187187
* Roll in radians. Positive when tilted right.
188188
*/
189+
189190
double getRoll() const {
190-
return roll;
191+
return roll;
191192
};
192193
};
193194

lib/KBox/src/KMessageNMEAVisitor.cpp

100644100755
+51-36
Original file line numberDiff line numberDiff line change
@@ -23,28 +23,14 @@
2323
*/
2424

2525
#include "KMessageNMEAVisitor.h"
26+
#include "KBoxDebug.h"
2627
#include "util/NMEASentenceBuilder.h"
2728
#include "util/nmea2000.h"
2829

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

33-
void KMessageNMEAVisitor::visit(const BarometerMeasurement &bm) {
34-
// XDR is not a very well defined sentence. Can be used for lots of things
35-
// apparently but that is better than nothing.
36-
NMEASentenceBuilder sb("II", "XDR", 8);
37-
sb.setField(1, "P");
38-
sb.setField(2, bm.getPressure(), 5);
39-
sb.setField(3, "B");
40-
sb.setField(4, "Barometer");
41-
sb.setField(5, "T");
42-
sb.setField(6, bm.getTemperature());
43-
sb.setField(7, "C");
44-
sb.setField(8, "TempAir");
45-
nmeaContent += sb.toNMEA() + "\r\n";
46-
}
47-
4834
void KMessageNMEAVisitor::visit(const VoltageMeasurement &vm) {
4935
NMEASentenceBuilder sb("II", "XDR", 4);
5036
sb.setField(1, "V");
@@ -63,37 +49,66 @@ void KMessageNMEAVisitor::visit(const NMEA2000Message &n2km) {
6349
free(s);
6450
}
6551

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

67-
inline static double RadToDeg(double v) { return v*180.0/3.1415926535897932384626433832795; }
68-
70+
//RES_MOD_7_29_17 for OpenCPN drop yaw data now only 12 instead of 16 data
71+
// part of message, switch pitch and roll to match my mount
6972
void KMessageNMEAVisitor::visit(const IMUMessage &imu) {
70-
NMEASentenceBuilder sb("II", "XDR", 16);
73+
NMEASentenceBuilder sb("II", "XDR", 12);
74+
//sb.setField(1, "A");
75+
//sb.setField(2, imu.getYaw(), 1);
76+
//sb.setField(3, "D");
77+
//sb.setField(4, "Yaw");
78+
79+
//RES_MOD_7_29_17 DEFINE NEW VARIABLEs TO ADD OFFSET to pitch and roll
80+
// and switch pitch and roll for my mounting, adjust SetField
81+
double resrolloffset = imu.getPitch();
82+
double resptchoffset = imu.getRoll();
83+
resrolloffset = - resrolloffset;
84+
resptchoffset = - resptchoffset;
7185
sb.setField(1, "A");
72-
sb.setField(2, RadToDeg(imu.getYaw()), 1);
86+
//RES_MOD_7_29_17 use new variable
87+
//sb.setField(6, imu.getPitch(), 1);
88+
sb.setField(2, resrolloffset, 1);
7389
sb.setField(3, "D");
74-
sb.setField(4, "Yaw");
90+
//make pitch to be roll
91+
sb.setField(4, "ROLL");
7592

7693
sb.setField(5, "A");
77-
sb.setField(6, RadToDeg(imu.getPitch()), 1);
94+
//sb.setField(10, imu.getRoll(), 1);
95+
sb.setField(6, resptchoffset, 1);
7896
sb.setField(7, "D");
79-
sb.setField(8, "Pitch");
97+
// make roll to be pitch; PTCH in OpenCPN
98+
sb.setField(8, "PTCH");
8099

81-
sb.setField(9, "A");
82-
sb.setField(10, RadToDeg(imu.getRoll()), 1);
83-
sb.setField(11, "D");
84-
sb.setField(12, "Roll");
85-
86-
sb.setField(13, "");
87-
sb.setField(14, imu.getCalibration());
88-
sb.setField(15, "");
89-
sb.setField(16, "Calibration");
100+
sb.setField(9, "");
101+
sb.setField(10, imu.getCalibration());
102+
sb.setField(11, "");
103+
sb.setField(12, "Calibration");
90104

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

93-
NMEASentenceBuilder sb2("II", "HDM", 2);
94-
sb2.setField(1, RadToDeg(imu.getCourse()));
95-
sb2.setField(2, "M");
107+
//RES_MOD_10_28_17 remove HDM output, as repeated from GPS
108+
//NMEASentenceBuilder sb2("II", "HDM", 2);
109+
//sb2.setField(1, imu.getCourse());
110+
//sb2.setField(2, "M");
96111

97-
nmeaContent += sb2.toNMEA() + "\r\n";
98-
}
112+
//nmeaContent += sb2.toNMEA() + "\r\n";
99113

114+
}

lib/KBox/src/TaskManager.cpp

100644100755
+2-1
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,8 @@ void TaskManager::loop() {
6363
loopStats.recordRun(loopTimer);
6464

6565
if (statDisplayTimer > statDisplayInterval) {
66-
displayStats();
66+
//RES_MOD_10_28_17 remove stat display
67+
// displayStats();
6768
statDisplayTimer = 0;
6869
}
6970
}

lib/KBox/src/pages/BatteryMonitorPage.cpp

100644100755
+37-14
Original file line numberDiff line numberDiff line change
@@ -35,17 +35,19 @@ BatteryMonitorPage::BatteryMonitorPage() {
3535

3636
addLayer(new TextLayer(Point(col1, row1), Size(20, 20), "House Battery", ColorWhite, ColorBlack, FontDefault));
3737
addLayer(new TextLayer(Point(col2, row1), Size(20, 20), "House Current", ColorWhite, ColorBlack, FontDefault));
38-
addLayer(new TextLayer(Point(col1, row3), Size(20, 20), "Engine Battery", ColorWhite, ColorBlack, FontDefault));
38+
addLayer(new TextLayer(Point(col1, row3), Size(20, 20), "Baro Pressure", ColorWhite, ColorBlack, FontDefault));
3939
addLayer(new TextLayer(Point(col2, row3), Size(20, 20), "Supply Voltage", ColorWhite, ColorBlack, FontDefault));
4040

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

4646
addLayer(houseVoltage);
4747
addLayer(houseCurrent);
48-
addLayer(starterVoltage);
48+
//RES_MOD_10_28_17 substatue baroPressure for starterVoltage see above also
49+
addLayer(baroPressure);
50+
//addLayer(starterVoltage);
4951
addLayer(supplyVoltage);
5052
}
5153

@@ -57,35 +59,56 @@ Color BatteryMonitorPage::colorForVoltage(float v) {
5759
return ColorRed;
5860
}
5961
if (v < 13.5) {
60-
return ColorGreen;
6162
}
6263
return ColorBlue;
6364
}
64-
65+
//RES_MOD_10_28_17 add color for pressure
66+
Color BatteryMonitorPage::colorForPressure(float b) {
67+
return ColorRed;
68+
}
6569
String BatteryMonitorPage::formatMeasurement(float measure, const char *unit) {
6670
// extra spaces at the end needed to clear previous value completely
6771
// (we use a non-fixed width font)
6872
char s[10];
73+
//RES_MOD_10_28_17 change format to 6.2?
74+
//snprintf(s, sizeof(s), "%6.2f %s ", measure, unit);
75+
if (unit = "V"){
6976
snprintf(s, sizeof(s), "%.1f %s ", measure, unit);
70-
return String(s);
77+
}
78+
else {
79+
snprintf(s, sizeof(s), "%8.4f %s ", measure, unit);
80+
}
81+
return String(s);
7182
}
7283

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

88+
//RES_MOD_10_28_17 My playing around with the display
89+
void BatteryMonitorPage::visit(const BarometerMeasurement &bm) {
90+
//double respressure = bm.getPressure();
91+
//RES_MOD_7_29_17 convert pressure to Bar not hBar - 5 decimal places
92+
//respressure = respressure/1000;
93+
//respressure = 101.3;
94+
DEBUG(" pressure from BatteryMonitorPage", bm.getTemperature());
95+
baroPressure->setText(formatMeasurement(bm.getTemperature(), "C"));
96+
baroPressure->setColor(colorForPressure(bm.getTemperature()));
97+
}
98+
7799
void BatteryMonitorPage::visit(const VoltageMeasurement &vm) {
78100
if (vm.getLabel() == "house") {
79-
houseVoltage->setText(formatMeasurement(vm.getVoltage(), "V"));
80-
houseVoltage->setColor(colorForVoltage(vm.getVoltage()));
81-
}
101+
houseVoltage->setText(formatMeasurement(vm.getVoltage(), "V"));
102+
houseVoltage->setColor(colorForVoltage(vm.getVoltage()));
103+
DEBUG("print from Display", vm.getVoltage());
104+
}
82105
if (vm.getLabel() == "supply") {
83106
supplyVoltage->setText(formatMeasurement(vm.getVoltage(), "V"));
84107
supplyVoltage->setColor(colorForVoltage(vm.getVoltage()));
85108
}
86-
if (vm.getLabel() == "starter") {
87-
starterVoltage->setText(formatMeasurement(vm.getVoltage(), "V"));
88-
starterVoltage->setColor(colorForVoltage(vm.getVoltage()));
89-
}
109+
//if (vm.getLabel() == "starter") {
110+
//Original below
111+
//starterVoltage->setText(formatMeasurement(vm.getVoltage(), "V"));
112+
//starterVoltage->setColor(colorForVoltage(vm.getVoltage()));
113+
//}
90114
}
91-

lib/KBox/src/pages/BatteryMonitorPage.h

100644100755
+10-1
Original file line numberDiff line numberDiff line change
@@ -25,17 +25,26 @@
2525
#include "MFD.h"
2626
#include "KMessage.h"
2727
#include "ui/TextLayer.h"
28+
//RES_MOD_10_28_17 indclude DEBUG
29+
#include "KBoxDebug.h"
2830

2931
class BatteryMonitorPage : public Page, public KReceiver, public KVisitor {
3032
private:
31-
TextLayer *houseVoltage, *houseCurrent, *starterVoltage, *supplyVoltage;
33+
//RES_MOD_10_28_17 substatue baroPressure for starterVoltage
34+
TextLayer *houseVoltage, *houseCurrent, *baroPressure, *supplyVoltage;
3235

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

39+
//RES_MOD_10_28_17 setup color for Pressure
40+
Color colorForPressure(float b);
41+
42+
3643
public:
3744
BatteryMonitorPage();
3845

3946
void processMessage(const KMessage& message);
4047
void visit(const VoltageMeasurement&);
48+
//RES_MOD_10_28_17 add this to public
49+
void visit(const BarometerMeasurement&);
4150
};

lib/KBox/src/tasks/BarometerTask.cpp

100644100755
+2-2
Original file line numberDiff line numberDiff line change
@@ -41,8 +41,8 @@ void BarometerTask::setup() {
4141
void BarometerTask::fetchValues() {
4242
temperature = bmp280.readTemperature();
4343
pressure = bmp280.readPressure();
44-
45-
DEBUG("Read temperature=%.2f C and pressure=%.1f hPa", temperature, pressure/100);
44+
//RES_MOD_10_28_17 clean up debug output to nmea cmmds only
45+
//DEBUG("Read temperature=%.2f C and pressure=%.1f hPa", temperature, pressure/100);
4646
BarometerMeasurement m(temperature, pressure);
4747
sendMessage(m);
4848
}

lib/KBox/src/tasks/SDCardTask.cpp

100644100755
+7-2
Original file line numberDiff line numberDiff line change
@@ -59,11 +59,16 @@ void SDCardTask::loop() {
5959
if (!isLogging()) {
6060
return;
6161
}
62-
for (LinkedList<Loggable>::iterator it = receivedMessages.begin(); it != receivedMessages.end(); it++) {
62+
for (LinkedList<Loggable>::iterator it = receivedMessages.begin(); it != receivedMessages.end(); it++) {
6363
logFile->print(it->timestamp);
6464
logFile->print(",");
6565
logFile->print(it->_message);
6666
logFile->println();
67+
//RES_MOD_10_28_17 send character message to DEBUG
68+
const char *messagecpy = (it->_message.c_str());
69+
//DEBUG("Nmea data to follow","\n");
70+
DEBUG(messagecpy);
71+
//end of my MOD
6772
}
6873
// Force data to SD and update the directory entry to avoid data loss.
6974
if (!logFile->sync() || logFile->getWriteError()) {
@@ -154,7 +159,7 @@ uint64_t SDCardTask::getFreeSpace() const {
154159
// the running led stops flashing (although we do still call digitalWrite on it)
155160
// the serial ports start messing up big time (missing a lot of data)
156161
// eventually other things crash...
157-
// Could be a memory problem or something like that. Have not found
162+
// Could be a memory problem or something like that. Have not found
158163
// it yet but the culprit is this line so for now it is disabled.
159164
uint64_t space = 0; //logFile->volume()->freeClusterCount();
160165
space *= logFile->volume()->blocksPerCluster();

lib/KBox/src/tasks/SDCardTask.h

100644100755
+3
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,9 @@ class SDCardTask : public Task, public KReceiver {
4949
LinkedList<Loggable> receivedMessages;
5050

5151
public:
52+
//RES_MOD_10_28_17 add messagecpy to public string
53+
String messagecpy() const;
54+
//end of my add
5255
SDCardTask();
5356
virtual ~SDCardTask();
5457

lib/KBox/src/tasks/WiFiTask.cpp

100644100755
+6-3
Original file line numberDiff line numberDiff line change
@@ -41,11 +41,14 @@ void WiFiTask::loop() {
4141
if (rxBuf[rxIndex - 1] == '\n') {
4242
rxBuf[rxIndex - 1] = 0;
4343
DEBUG("WiFi: %s", rxBuf);
44+
//RES_MOD_10_28_17 add a blank line in output
45+
DEBUG("");
4446
rxIndex = 0;
4547
}
4648
if (rxIndex >= sizeof(rxBuf) - 1) {
4749
rxBuf[rxIndex] = 0;
4850
DEBUG("WiFi full: %s", rxBuf);
51+
DEBUG("");
4952
rxIndex = 0;
5053
}
5154
}
@@ -62,13 +65,15 @@ void WiFiTask::loop() {
6265
}
6366

6467
if (WiFiSerial.availableForWrite() <= 0) {
65-
//DEBUG("Not sending because send buffer is full (need %i but %i available).", toSend.length(), WiFiSerial.availableForWrite());
68+
//RES_MOD_9_6_17 comment debug
69+
//DEBUG("Not sending because send buffer is full (need %i but %i available).", toSend.length(), WiFiSerial.availableForWrite());
6670
break;
6771
}
6872
size_t available = WiFiSerial.availableForWrite();
6973
String s = toSend;
7074
s.remove(available);
7175
size_t written = WiFiSerial.print(s);
76+
//RES_MOD_9_6_17 comment debug
7277
//DEBUG("Sent %i/%i (%i avail) of %s", written, toSend.length(), available, toSend.c_str());
7378

7479
if (written == toSend.length()) {
@@ -96,5 +101,3 @@ void WiFiTask::processMessage(const KMessage &m) {
96101
m.accept(v);
97102
sendQueue.add(v.toNMEA());
98103
}
99-
100-

0 commit comments

Comments
 (0)