Skip to content

Commit 2110620

Browse files
author
Olivier LeDiouris
committed
Scrolling graph
1 parent 00c490f commit 2110620

File tree

4 files changed

+74
-61
lines changed

4 files changed

+74
-61
lines changed

RESTNavServer/nmea.mux.no.gps.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ http.port=9999
99
#
1010
# Channels (input)
1111
#
12-
# mux.01.type=zda
12+
mux.01.type=zda
1313
#
1414
#
1515
# No Forwarders

RasPISamples/weather.logger/raspi/reports.v2/js/Graph.js

Lines changed: 19 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -117,19 +117,27 @@ function Graph(cName, // Canvas Name
117117
}, 0);
118118

119119
var relativeMouseCoords = function (event, element) {
120-
var totalOffsetX = 0;
121-
var totalOffsetY = 0;
120+
// var totalOffsetX = 0;
121+
// var totalOffsetY = 0;
122122
var canvasX = 0;
123123
var canvasY = 0;
124-
var currentElement = element;
125-
126-
do {
127-
totalOffsetX += currentElement.offsetLeft - currentElement.scrollLeft;
128-
totalOffsetY += currentElement.offsetTop - currentElement.scrollTop;
129-
} while (currentElement = currentElement.offsetParent)
130-
131-
canvasX = event.pageX - totalOffsetX;
132-
canvasY = event.pageY - totalOffsetY;
124+
// var currentElement = element;
125+
//
126+
// do {
127+
// totalOffsetX += currentElement.offsetLeft - currentElement.scrollLeft;
128+
// totalOffsetY += currentElement.offsetTop - currentElement.scrollTop;
129+
// } while (currentElement = currentElement.offsetParent)
130+
//
131+
// canvasX = event.pageX - totalOffsetX;
132+
// canvasY = event.pageY - totalOffsetY;
133+
134+
var bcr = element.getBoundingClientRect();
135+
136+
canvasX = event.clientX;
137+
canvasY = event.clientY;
138+
139+
canvasX -= bcr.left;
140+
canvasY -= bcr.top;
133141

134142
return {x:canvasX, y:canvasY};
135143
};

TwoLeds/src/twoleds/MainController.java

Lines changed: 32 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -2,34 +2,41 @@
22

33
import com.pi4j.io.gpio.GpioController;
44
import com.pi4j.io.gpio.GpioFactory;
5-
65
import com.pi4j.io.gpio.RaspiPin;
7-
86
import twoleds.led.OneLed;
97

10-
public class MainController
11-
{
12-
public static void main(String... args)
13-
{
14-
GpioController gpio = GpioFactory.getInstance();
15-
OneLed yellowLed = new OneLed(gpio, RaspiPin.GPIO_01, "yellow");
16-
OneLed greenLed = new OneLed(gpio, RaspiPin.GPIO_04, "green");
8+
public class MainController {
9+
public static void main(String... args) {
10+
GpioController gpio = GpioFactory.getInstance();
11+
OneLed yellowLed = new OneLed(gpio, RaspiPin.GPIO_01, "yellow");
12+
OneLed greenLed = new OneLed(gpio, RaspiPin.GPIO_04, "green");
1713

18-
long step = 50L;
14+
long step = 50L;
1915

20-
for (int i=0; i<10; i++)
21-
{
22-
yellowLed.on();
23-
try { Thread.sleep(5 * step); } catch (InterruptedException ie) {}
24-
yellowLed.off();
25-
greenLed.on();
26-
try { Thread.sleep(5 * step); } catch (InterruptedException ie) {}
27-
yellowLed.on();
28-
try { Thread.sleep(10 * step); } catch (InterruptedException ie) {}
29-
yellowLed.off();
30-
greenLed.off();
31-
try { Thread.sleep(step); } catch (InterruptedException ie) {}
32-
}
33-
gpio.shutdown();
34-
}
16+
for (int i = 0; i < 10; i++) {
17+
yellowLed.on();
18+
try {
19+
Thread.sleep(5 * step);
20+
} catch (InterruptedException ie) {
21+
}
22+
yellowLed.off();
23+
greenLed.on();
24+
try {
25+
Thread.sleep(5 * step);
26+
} catch (InterruptedException ie) {
27+
}
28+
yellowLed.on();
29+
try {
30+
Thread.sleep(10 * step);
31+
} catch (InterruptedException ie) {
32+
}
33+
yellowLed.off();
34+
greenLed.off();
35+
try {
36+
Thread.sleep(step);
37+
} catch (InterruptedException ie) {
38+
}
39+
}
40+
gpio.shutdown();
41+
}
3542
}

TwoLeds/src/twoleds/led/OneLed.java

Lines changed: 22 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -5,28 +5,26 @@
55
import com.pi4j.io.gpio.Pin;
66
import com.pi4j.io.gpio.PinState;
77

8-
public class OneLed
9-
{
10-
private GpioPinDigitalOutput led = null;
11-
private String name;
12-
13-
public OneLed(GpioController gpio, Pin pin, String name)
14-
{
15-
this.name = name;
16-
led = gpio.provisionDigitalOutputPin(pin, "Led", PinState.LOW);
17-
}
18-
19-
public void on()
20-
{
21-
if ("true".equals(System.getProperty("verbose", "false")))
22-
System.out.println(this.name + " is on.");
23-
led.high();
24-
}
25-
26-
public void off()
27-
{
28-
if ("true".equals(System.getProperty("verbose", "false")))
29-
System.out.println(this.name + " is off.");
30-
led.low();
31-
}
8+
public class OneLed {
9+
private GpioPinDigitalOutput led = null;
10+
private String name;
11+
12+
public OneLed(GpioController gpio, Pin pin, String name) {
13+
this.name = name;
14+
led = gpio.provisionDigitalOutputPin(pin, "Led", PinState.LOW);
15+
}
16+
17+
public void on() {
18+
if ("true".equals(System.getProperty("verbose", "false"))) {
19+
System.out.println(this.name + " is on.");
20+
}
21+
led.high();
22+
}
23+
24+
public void off() {
25+
if ("true".equals(System.getProperty("verbose", "false"))) {
26+
System.out.println(this.name + " is off.");
27+
}
28+
led.low();
29+
}
3230
}

0 commit comments

Comments
 (0)