diff --git a/src/MeadeCommandProcessor.cpp b/src/MeadeCommandProcessor.cpp index 419f7630..e95e0254 100644 --- a/src/MeadeCommandProcessor.cpp +++ b/src/MeadeCommandProcessor.cpp @@ -97,12 +97,26 @@ meade::RaCoordinate raFrom(const DayTime &t) }; } +Declination decToInternal(const meade::DecCoordinate &d) +{ + long seconds = labs(static_cast(d.degrees)) * 3600L + d.minutes * 60L + d.seconds; + return Declination::FromSeconds(d.degrees < 0 ? -seconds : seconds); +} + meade::DecCoordinate decFrom(const Declination &d) { + const long celestialSeconds = inNorthernHemisphere ? 90L * 3600L - labs(d.getTotalSeconds()) : -90L * 3600L + labs(d.getTotalSeconds()); + const long absoluteSeconds = labs(celestialSeconds); + int16_t degrees = static_cast(absoluteSeconds / 3600L); + if (celestialSeconds < 0) + { + degrees = -degrees; + } + return meade::DecCoordinate { - static_cast(d.getHours()), - static_cast(d.getMinutes()), - static_cast(d.getSeconds()), + degrees, + static_cast((absoluteSeconds / 60L) % 60L), + static_cast(absoluteSeconds % 60L), }; } } // namespace @@ -160,9 +174,16 @@ meade::MeadeLatitude MeadeCommandProcessor::onSiteLatitude() meade::MeadeLongitude MeadeCommandProcessor::onSiteLongitude() { const Longitude lon = _mount->longitude(); + long secs = labs(static_cast(lon.getTotalSeconds())); + int16_t deg = static_cast(secs / 3600L); + uint8_t min = static_cast((secs / 60L) % 60L); + if (lon.getTotalHours() > 0) + { + deg = -deg; + } return meade::MeadeLongitude { - static_cast(lon.getHours()), - static_cast(lon.getMinutes()), + deg, + min, }; } @@ -248,7 +269,7 @@ void MeadeCommandProcessor::onSyncToTarget() ///////////////////////////// bool MeadeCommandProcessor::onSetTargetDec(meade::DecCoordinate dec) { - _mount->targetDEC() = Declination(static_cast(dec.degrees), static_cast(dec.minutes), static_cast(dec.seconds)); + _mount->targetDEC() = decToInternal(dec); LOG(DEBUG_MEADE, "[MEADE]: SetInfo: Received Target DEC: %s", _mount->targetDEC().ToString()); return true; } @@ -282,7 +303,7 @@ bool MeadeCommandProcessor::onSetHourAngle(uint8_t hours, uint8_t minutes) bool MeadeCommandProcessor::onSyncCoordinates(meade::DecCoordinate dec, meade::RaCoordinate ra) { - Declination decValue(static_cast(dec.degrees), static_cast(dec.minutes), static_cast(dec.seconds)); + Declination decValue = decToInternal(dec); DayTime raValue(static_cast(ra.hours), static_cast(ra.minutes), static_cast(ra.seconds)); _mount->syncPosition(raValue, decValue); return true; @@ -296,7 +317,7 @@ bool MeadeCommandProcessor::onSetSiteLatitude(meade::MeadeLatitude lat) bool MeadeCommandProcessor::onSetSiteLongitude(meade::MeadeLongitude lon) { - _mount->setLongitude(Longitude(static_cast(lon.degrees), static_cast(lon.minutes), 0)); + _mount->setLongitude(Longitude(-static_cast(lon.degrees), static_cast(lon.minutes), 0)); return true; }