Skip to content

Instantly share code, notes, and snippets.

@antipole2
antipole2 / detailHandles.js
Created January 5, 2024 17:20
Get details of OCPN active handles
handles = OCPNgetActiveDriverHandles()
for (h = 0; h < handles.length; h++){
attributes = OCPNgetDriverAttributes(handles[h]);
print(handles[h], "\t", attributes, "\n");
}
@antipole2
antipole2 / gist:829ff97d7f4a69dd87e1270c3831d33a
Created May 1, 2021 09:48
WordPress - login by email address only
/* ------------------------------------------------------------------------- *
* (4) Add custom authentication function
/* ------------------------------------------------------------------------- */
add_filter('authenticate', function($user, $email, $password){
//Check for empty fields
if(empty($email) || empty ($password)){
//create new error object and add errors to it.
$error = new WP_Error();
@antipole2
antipole2 / SendActiveRoute.js
Created April 6, 2021 11:29
Cause remove device to follow OpenCPN route navigation
// This script sends any active route out as WPT and RTE sentences so that iNavX shows the up-to-date active route.
// If the route or its routepoints are updated, iNavX will update to reflect this
// V2.0 - major rewrite to utilise latest plugin capabilities - much simplified
Position = require("Position"); // load the required constructors
Route = require("Route");
// here we define enduring variables we need outside the functions
var debug = false; // for debug prints
const prefix = "$JS"; // NMEA identifier
// Tack advisor v0.2.1 27 Sep 2021
// Since v0.1 added down-wind tacking and onExit clean-up
// v0.2.1 removes degree character from comments in three places as Windows objects
// configuration
repeatInterval = 5; // seconds
// wind angles we will work at
minWindAngle = 10; // Min wind angle to work with
maxWindAngle = 60; // Max angle off wind we will work with
maxRunWindAngle = 179; // Don't work if virtually straight down wind
// Drive ship in absence of real NMEA inputs
Position = require("Position");
// we construct the panel dynamically, so we can note where things are
panel = [];
panel.push({type:"caption", value:"Simple ship and wind driver"});
panel.push({type:"text", value:"Set desired parameters\nthen select action button to update"});
panel.push({type:"text", value:"Status: Standing by"});
statusRow = panel.length-1;
panel.push({type:"slider", range:[0,10], value:5, width:300, label:"SOG knots"});
@antipole2
antipole2 / NMEA_counter.js
Created November 19, 2020 17:48
Counts sentences over time
// listens for OpenCPN sentences and NMEA messages over configured time and reports
// sorts NMEA messages by count and then alphabetically
var timeSeconds = 30; // time period over which to count
var progressSeconds = 5; // count down this often
var secondsLeft = timeSeconds;
var log = []; // will be array of entries
onSeconds(progress, 1); // count down every progressSeconds secs, but first almost immediately
onSeconds(report, timeSeconds);
@antipole2
antipole2 / dialogue_demo.js
Last active November 18, 2020 19:33
Demonstrates dialogue
dialogue = [
{type:"caption", value:"Boat registration"},
{type:"text", value:"You may register your boat here", style:{size:16}},
{type:"field", label:"Boat name", width:250, fieldStyle:{italic:true}},
{type:"radio", label:"Type", value:["Yacht","Motor cruiser","Keel boat","Dinghy"]},
{type:"field", label:"Model", },
{type:"slider", label:"Length (m)", range:[2, 40], value:10},
{type:"spinner", label:"Draught (decimeters)", range:[10,30], value:20},
{type:"tickList", label:"Down wind sails", value:["Spinnaker","Cruising 'chute", "Code 0"]},
{type:"hLine"},
@antipole2
antipole2 / timeout_tester.js
Created November 16, 2020 22:10
Demonstrates and tests JavaScript plugin timeouts
// time-out exerciser and tester
function calc(n){ // this takes some time
a = 99999;
while(n-- > 0) a = Math.sqrt(a);
}
var calcLength = 1000
try {scriptResult("");} // supress result
catch(err){throw("Timeouts not supported in plugin versions efore 0.3");}
@antipole2
antipole2 / build_race_courses.js
Last active September 27, 2021 12:35
OCPN JavaScript to build race course routes from a selection of race marks
// This script for the JavaScript plugin provides creation of racing routes by selecting race marks from a list
// being a subset of OpenCPN waypoints
Position = require("Position");
// declare enduring variables
var routeName;
var replaceRoute;
var pattern;
var waypoints = []; // to be array of waypoints
var routeList = []; // array of pre-existing routes in OpenCPN
@antipole2
antipole2 / dialogue_example.js
Created October 22, 2020 16:30
Example of script using dialogues
dialogue = [
{type:"text", value:"Register your boat"},
{type:"field", label:"Name"},
{type:"field", label:"Length", suffix:"m", width:30},
{type:"radio", label:"type", value:["yacht", "motor cruiser", "keelboat", "dinghy"]},
{type:"tick", value:"share details?"},
{type:"button", label:["cancel", "register"]}
];
OCPNonDialogue(handle, dialogue);