Commit 845f0bff authored by Jens-Christian Fischer's avatar Jens-Christian Fischer
Browse files

Add orientationPanel

parent 34e1fb76
......@@ -3,7 +3,7 @@ defmodule Grains.Mixfile do
def project do
[app: :grains,
version: "0.0.11",
version: "0.0.12",
elixir: "~> 1.2",
elixirc_paths: elixirc_paths(Mix.env),
compilers: [:phoenix, :gettext] ++ Mix.compilers,
......
......@@ -15,8 +15,10 @@ import "phoenix_html";
import socket from "./socket"
import SliderPanel from "./slider";
import OrientationPanel from "./orientation";
SliderPanel.init(socket, "#sliderPanel", ["s1", "s2", "s3"]);
OrientationPanel.init(socket, "#orientationPanel");
// Import local files
//
......
import Interface from "interface.js";
let OrientationPanel = {
orientationChannel : null,
sliders: {},
slider_titles: ["pitch", "roll", "yaw", "heading"],
init(socket, domId) {
if (!document.getElementById(domId)) {
return;
}
let that = this;
socket.connect();
this.orientationChannel = socket.channel("orientation:" + domId);
this.orientationChannel.on("orientation", (resp) => {
this.setSliderValue(resp);
});
this.orientationChannel.join()
.receive("ok", resp => {
resp.values.forEach( (element) => {
this.setSliderValue(element);
} );
})
.receive("error", reason => console.log("join failed", reason));
let a = new Interface.Panel({
container:document.getElementById(domId)
});
this.orientation = new Interface.Orientation({
onvaluechange: function(pitch, roll, yaw, heading) {
console.log(pitch, roll, yaw, heading);
that.send_value(pitch, roll, yaw, heading); }
});
let nrSliders = this.sliders_titles.length;
this.slider_titles.forEach( (s, idx) => {
this.sliders[s] = new Interface.Slider({
bounds: [(1/nrSliders) * idx, .1, 1 / nrSliders, .5],
label: s
});
console.log(s);
a.add(this.sliders[s]);
});
a.background = 'black';
console.log("initialized orientation");
},
send_value(pitch, roll, yaw, heading) {
let payload = {pitch: pitch, roll: roll, yaw: yaw, heading: heading};
this.orientationChannel.push("orientation", payload)
.receive("error", e => console.log(e));
},
setSliderValue(resp){
console.log(resp);
let slider = this.sliders[resp.element];
// slider.setValue(resp.value);
}
};
export default OrientationPanel;
......@@ -7,6 +7,11 @@ let SliderPanel = {
sliders: {},
init(socket, domId, sliders) {
if (!document.getElementById(domId)) {
return;
}
let that = this;
socket.connect();
this.sliderChannel = socket.channel("slider:" + domId);
......
<h1>Grain <%= @grain %></h1>
<div id="#sliderPanel" class="interfacePanel"></div>
<div id="#orientationPanel" class="interfacePanel"></div>
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment