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");
}
// Add hyperlinks to an existing waypoint with markName of 'lunch stop'
wpName = "lunch stop";
guids = OCPNgetWaypointGUIDs();
foundIt = false;
for (i = 0; i < guids.length; i++){
// look for our waypoint
lunchWaypoint = OCPNgetSingleWaypoint(guids[i]);
if (lunchWaypoint.markName == wpName){
foundIt = true;
break;
@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
// 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
@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
// 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"});
// insert magnetic variation into RMC sentence
// corrected 22 Dec 2020 for NMEA sentence as structure
var vardegs = "";
var varEW = "";
OCPNonNMEAsentence(processNMEA);
function processNMEA(input){
if (input.OK){
sentence = input.value;
@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 / Tester.js
Last active November 19, 2020 17:44
// Position, waypoint and route confidence tester
function compareWaypoints(waypoint1, waypoint2){
// compares two waypoints and displays any mismatches.
// returns true if error else false if OK
function display(attribute){
if (!displaying) printOrange("The following attributes of waypoints do not match:\n");
displaying = true;
printOrange(attribute, "\n");
}