Skip to content

Commit

Permalink
fix autopilot target adjust values
Browse files Browse the repository at this point in the history
not being sent to autopilot.
  • Loading branch information
panaaj committed Nov 8, 2023
1 parent d3dce05 commit 7ad1c09
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 13 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# CHANGELOG: Freeboard

### v2.3.1

- **Fixed**: Issue in autopilot display where +/- adjustment buttons were not sending data to Pypilot.

### v2.3.0

- **Added**: Display a badge on menu icon when server has security enabled and client is not authenticated.
Expand Down
24 changes: 14 additions & 10 deletions helper/pypilot.ts
Original file line number Diff line number Diff line change
Expand Up @@ -170,10 +170,10 @@ const initApiRoutes = () => {

const v = req.body.value * (180 / Math.PI);
let deg = apData.target + v;
if (deg > 359) {
deg = 359;
} else if (deg < -179) {
deg = -179;
if (deg > 360) {
deg = 360;
} else if (deg < -180) {
deg = -180;
}

const r = sendToPyPilot('target', deg);
Expand Down Expand Up @@ -282,7 +282,7 @@ const initPyPilotListeners = () => {

// Send values to pypilot
const sendToPyPilot = (command: string, value: string | number | boolean) => {
server.debug(`command: ${command} = ${value}`);
server.debug(`sendToPyPilot: ${command} = ${value}`);
let mode = '';

if (command === 'mode') {
Expand All @@ -295,8 +295,8 @@ const sendToPyPilot = (command: string, value: string | number | boolean) => {
mode = 'ap.enabled';
}
} else if (command === 'target') {
if (typeof value === 'string') {
value = (180 / Math.PI) * parseFloat(value); // rad to deg
server.debug(`command: ${command}, value: ${value}, ${typeof value}`);
if (typeof value === 'number') {
mode = 'ap.heading_command';
}
} else {
Expand All @@ -309,6 +309,7 @@ const sendToPyPilot = (command: string, value: string | number | boolean) => {
}

try {
server.debug(`out -> ${mode}=${JSON.stringify(value)}`);
socket.emit('pypilot', mode + '=' + JSON.stringify(value));
return {
state: 'COMPLETED',
Expand Down Expand Up @@ -337,10 +338,13 @@ const handlePyPilotUpdateMsg = (data: any) => {
}*/

if (typeof data['ap.heading_command'] !== 'undefined') {
const heading =
const h =
data['ap.heading_command'] === false ? null : data['ap.heading_command'];
if (heading !== apData.heading_command) {
apData.target = heading;
if (h !== apData.heading_command) {
apData.target = h;
server.debug(
`in -> deg: ${apData.target}, rad: ${(Math.PI / 180) * apData.target}`
);
emitAPDelta('target' as Path, (Math.PI / 180) * apData.target);
}
}
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@signalk/freeboard-sk",
"version": "2.3.0",
"version": "2.3.1",
"description": "Openlayers chart plotter implementation for Signal K",
"keywords": [
"signalk-webapp",
Expand Down
2 changes: 1 addition & 1 deletion src/app/app.info.ts
Original file line number Diff line number Diff line change
Expand Up @@ -268,7 +268,7 @@ export class AppInfo extends Info {
this.name = 'Freeboard-SK';
this.shortName = 'Freeboard';
this.description = `Signal K Chart Plotter.`;
this.version = '2.3.0';
this.version = '2.3.1';
this.url = 'https://github.com/signalk/freeboard-sk';
this.logo = './assets/img/app_logo.png';

Expand Down
2 changes: 1 addition & 1 deletion src/app/lib/components/autopilot.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -244,7 +244,7 @@ export class AutopilotComponent {
}

formatTargetValue(value: number) {
if (value) {
if (typeof value === 'number') {
return Convert.radiansToDegrees(value)?.toFixed(1);
} else return '--';
}
Expand Down

0 comments on commit 7ad1c09

Please sign in to comment.