Skip to content

Commit 40ae16c

Browse files
committed
Initial submit of the topdown compass plugin
1 parent 977a68c commit 40ae16c

6 files changed

Lines changed: 156 additions & 1 deletion

File tree

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
function topdowncompass(name, deps) {
2+
console.log('topdowncompass loads here');
3+
}
4+
module.exports = topdowncompass;
3.32 KB
Loading
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
.topdowncompass{
2+
display:block;
3+
width:61px;
4+
height:76px;
5+
position: relative;
6+
top:0px;
7+
left:400px;
8+
9+
}
10+
11+
.compassNeedle{
12+
position:absolute;
13+
top:0px;
14+
left:0px;
15+
background-image: url('compassneedle.png');
16+
width:61px;
17+
height:76px;
18+
background-size:61px 76px;
19+
background-repeat:no-repeat;
20+
-webkit-transition: 100ms ease-in-out;
21+
-moz-transition: 100ms ease-in-out;
22+
-o-transition: 100ms ease-in-out;
23+
transition: 100ms ease-in-out;
24+
}
Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
(function (window, $, undefined) {
2+
'use strict';
3+
var TopDownCompass = function(cockpit) {
4+
5+
var context = this;
6+
7+
// Event bindings
8+
setInterval(this.handleResize, 100);
9+
10+
// Instance variables
11+
this.cockpit = cockpit;
12+
13+
this.compassPanel = $("<div></div>").addClass('topdowncompasspanel');
14+
this.compass = $("<div></div>").addClass("topdowncompass");
15+
this.compass.append($("<div></div>").addClass("compassNeedle"));
16+
17+
this.compassPanel.append(this.compass);
18+
19+
// Add required UI elements
20+
$('#footercontent').append(this.compass);
21+
22+
this.cockpit.socket.on('navdata', function (data) {
23+
if (!jQuery.isEmptyObject(data)) {
24+
25+
context.setCompassHeading(parseFloat(data.hdgd));
26+
27+
}
28+
});
29+
30+
this.setCompassHeading(0);
31+
// test
32+
// setInterval(this.setCompassHeading(this.heading+10),250);
33+
34+
};
35+
/**
36+
* Set the compass heading
37+
* @param degrees
38+
*/
39+
var el, rot;
40+
TopDownCompass.prototype.setCompassHeading = function(degrees) {
41+
42+
var aR;
43+
this.heading = this.heading || 0; // if rot undefined or 0, make 0, else rot
44+
aR = this.heading % 360;
45+
if ( aR < 0 ) { aR += 360; }
46+
if ( aR < 180 && (degrees > (aR + 180)) ) { this.heading -= 360; }
47+
if ( aR >= 180 && (degrees <= (aR - 180)) ) { this.heading += 360; }
48+
this.heading += (degrees - aR);
49+
50+
51+
var cp = $(".compassNeedle");
52+
// lb = $(".compassDegValue");
53+
54+
//lb.text(Math.round(degrees));
55+
56+
cp.css({
57+
"transform" : "rotate(" + (this.heading) + "deg)",
58+
"-ms-transform" : "rotate(" + (this.heading) + "deg)",
59+
"-webkit-transform" : "rotate(" + (this.heading) + "deg)"
60+
})
61+
};
62+
63+
/**
64+
* Resize the UI
65+
*/
66+
TopDownCompass.prototype.handleResize = function() {
67+
var wn = $(window),
68+
w = wn.width(),
69+
h = wn.height();
70+
71+
var nd = $(".topdowncompasspanel");
72+
if (nd.length > 0) {
73+
var pn = nd[0].parentNode;
74+
nd.css({
75+
width: $(pn).width(),
76+
height: $(pn).height()
77+
});
78+
}
79+
};
80+
81+
// Add the panel to the plugin list
82+
window.Cockpit.plugins.push(TopDownCompass);
83+
}(window, jQuery));

src/static/README.md

Lines changed: 42 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,47 @@ In the javascript console execute
2121

2222
`window.frames[0].window.simevents.status.forEach(function(x){x({targetHeading: 120})})`
2323

24-
`window.frames[0].window.simevents.status.forEach(function(x){x({hdgd: "0.00", deap: "0.00", pitc: "0.00", roll: "0.00", yaw: "0.00"…}AVCC: "4892"BRDI: "0.25"BRDT: "28.81"BRDV: "11.63"BT1I: "0.00"BT2I: "0.00"CAPA: "14"LIGP: "0.00"LIGT: "0"SC1I: "0.00"SC2I: "0.00"SC3I: "0.00"alps: "3937"atmp: "0.00"cmd: "rmtrmod()"cmpd: "Jul 28 2014, 01"cpuUsage: 0.17000000000000004deap: "0.00"dlms: "0|316321|307462|311223|254734|551015|369616|4900"elevons: "1502,1502"elevtarg: "1500.00,1500.00"fmem: "5777.00"fthr: "0.00"hdgd: "0.00"iout: 0.24log: "No I2C devices found↵"motorAttached: "1"motors: "1500,1500"mtarg: "1500,1500"mtrmod: "1.00,0,1.00,2.00,0,2.00"pitc: "0.00"pres: "0.00"roll: "0.00"servo: "1500"starg: "1500"temp: "0.00"time: "37752936.00"ver: "9134722125e2061624ab09f7f096e0421e3ecd08 -"vout: 11.63yaw: "0.00"})`
24+
`window.frames[0].window.simevents.status.forEach(function(x){x({vout: 2.00})})`
25+
26+
`window.frames[0].window.simevents.status.forEach(function(x){x({hdgd: "0.00", deap: "0.00", pitc: "0.00", roll: "0.00", yaw: "0.00", AVCC: "4892" ,
27+
BRDI: "0.25",
28+
BRDT: "28.81",
29+
BRDV: "11.63",
30+
BT1I: "0.00",
31+
BT2I: "0.00",
32+
CAPA: "14",
33+
LIGP: "0.00",
34+
LIGT: "0",
35+
SC1I: "0.00",
36+
SC2I: "0.00",
37+
SC3I: "0.00",
38+
alps: "3937",
39+
atmp: "0.00",
40+
cmd: "rmtrmod()",
41+
cmpd: "Jul 28 2014, 01",
42+
cpuUsage: 0.17000000000000004,
43+
deap: "0.00",
44+
dlms: "0|316321|307462|311223|254734|551015|369616|4900",
45+
elevons: "1502,1502",
46+
elevtarg: "1500.00,1500.00",
47+
fmem: "5777.00",
48+
fthr: "0.00",
49+
hdgd: "0.00",
50+
iout: 0.24,
51+
log: "No I2C devices found↵",
52+
motorAttached: "1",
53+
motors: "1500,1500",
54+
mtarg: "1500,1500",
55+
mtrmod: "1.00,0,1.00,2.00,0,2.00",
56+
pitc: "0.00",
57+
pres: "0.00",
58+
roll: "0.00",
59+
servo: "1500",
60+
starg: "1500",
61+
temp: "0.00",
62+
time: "37752936.00",
63+
ver: "9134722125e2061624ab09f7f096e0421e3ecd08 -",
64+
vout: 11.63,
65+
yaw: "0.00"})})`
2566

2667
Where 0 is the index of the listener you want to make go

src/static/testviews.html

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,8 @@
5555
scripts.push('../plugins/serial-monitor/public/js/serial-monitor.js');
5656
scripts.push('../plugins/tankcontrol/public/js/tankcontrol.js');
5757
scripts.push('../plugins/telemetry/public/js/telemetry.js');
58+
scripts.push('../plugins/topdowncompass/public/js/topdowncompass.js');
59+
5860
// scripts.push('../plugins/touchcontroller/public/js/gamecontroller.js');
5961
scripts.push('../plugins/touchcontroller/public/js/touchcontroller.js');
6062
scripts.push('../plugins/visualisation3d/public/js/Babylon.js');
@@ -70,6 +72,7 @@
7072
styles.push('../plugins/visualisation3d/public/css/style.css');
7173
styles.push('../plugins/rovpilot/public/css/style.css');
7274
styles.push('../plugins/headsup-menu/public/css/style.css');
75+
styles.push('../plugins/topdowncompass/public/css/topdowncompass.css');
7376

7477
frameDoc.writeln(new EJS({url: '../views/index.ejs'}).render({title: "testing", styles:styles, scripts:scripts}));
7578
frameDoc.close();

0 commit comments

Comments
 (0)