Skip to content

Commit

Permalink
Merge pull request #9 from MichaKersloot/main
Browse files Browse the repository at this point in the history
Made the auto calibration options more versatile
  • Loading branch information
htool authored Aug 21, 2024
2 parents 6f8c311 + 1715eed commit e5c3b57
Showing 1 changed file with 24 additions and 2 deletions.
26 changes: 24 additions & 2 deletions ESP32_Precision-9_compass_CMPS14.ino
Original file line number Diff line number Diff line change
Expand Up @@ -221,6 +221,7 @@ void setup()
nmea2000->Open();

Serial.println("Press 'o' to enable serial output. 'c' to cycle through calibration modes. 'z' to clear calibration.");
Serial.println("Press '0: Auto calibration off. 1: Auto calibration on, 2: Auto calibration locked, 3: Auto calibration auto");
t_next = 0;
}

Expand Down Expand Up @@ -302,6 +303,26 @@ void loop()
Serial.println("Changing autocalibration state");
configureAutoCalibration(compass_autocalibration);
}
if (InputChar == '0') {
compass_autocalibration = 0;
Serial.println("Changing autocalibration state");
configureAutoCalibration(compass_autocalibration);
}
if (InputChar == '1') {
compass_autocalibration = 1;
Serial.println("Changing autocalibration state");
configureAutoCalibration(compass_autocalibration);
}
if (InputChar == '2') {
compass_autocalibration = 2;
Serial.println("Changing autocalibration state");
configureAutoCalibration(compass_autocalibration);
}
if (InputChar == '3') {
compass_autocalibration = 3;
Serial.println("Changing autocalibration state");
configureAutoCalibration(compass_autocalibration);
}
if (InputChar == 's' && calibrationRecording == false) {
Serial.println("Calibration recording started. Keep turning at a steady 3 degrees/second for 390 degrees.");
calibrationRecording = true;
Expand Down Expand Up @@ -473,8 +494,6 @@ bool ParseN2kPGN130845(const tN2kMsg &N2kMsg, uint16_t &Key, uint16_t &Command,
compass_autocalibration = N2kMsg.GetByte(Index);
if (SetN2kPGN130845(N2kMsgReply, DEVICE_ID, 0xd400, 2))
nmea2000->SendMsg(N2kMsgReply);
EEPROM.writeByte(EEP_AUTOCALIBRATION, (unsigned char)compass_autocalibration);
EEPROM.commit();
configureAutoCalibration(compass_autocalibration);
break;
case 0xd300: // Warning
Expand Down Expand Up @@ -1257,6 +1276,9 @@ void changeCalibrationState(byte state) {

void configureAutoCalibration(unsigned char m) {
Serial.printf("configureAutoCalibration mode: %s\n", String(m));
EEPROM.writeByte(EEP_AUTOCALIBRATION, m);
EEPROM.commit();

if (m == 0x00) {
Serial.println("Turning autocalibration off");
delay(100);
Expand Down

0 comments on commit e5c3b57

Please sign in to comment.