Commit 9474d443 authored by Jens-Christian Fischer's avatar Jens-Christian Fischer
Browse files

send pitch/roll/yaw

parent a74c2d73
......@@ -3,7 +3,7 @@ defmodule Grains.Mixfile do
def project do
[app: :grains,
version: "0.0.22",
version: "0.0.23",
elixir: "~> 1.2",
elixirc_paths: elixirc_paths(Mix.env),
compilers: [:phoenix, :gettext] ++ Mix.compilers,
......
......@@ -18,8 +18,10 @@ defmodule Grains.OrientationChannel do
def handle_in("orientation", params, socket) do
Logger.info("orientations #{inspect(params)}")
pitch = params["pitch"]
# roll = params["roll"]
pitch = params["pitch"]
roll = params["roll"]
yaw = params["yaw"]
heading = params["heading"]
StatefulMap.put("pitch", pitch)
......@@ -28,6 +30,16 @@ defmodule Grains.OrientationChannel do
element: "pitch",
value: pitch
}
broadcast! socket, "orientation", %{
user: %{id: "anon"},
element: "roll",
value: roll
}
broadcast! socket, "orientation", %{
user: %{id: "anon"},
element: "yaw",
value: yaw
}
{:reply, :ok, socket}
......
......@@ -37,10 +37,7 @@ let OrientationPanel = {
console.log("adding orientation");
this.orientation = new Interface.Orientation({
onvaluechange: function(pitch, roll, yaw, heading) {
console.log(pitch, roll, yaw, heading);
let rollEl = document.getElementById("roll");
rollEl.innerHTML = roll;
that.send_value(pitch, roll, yaw, heading);
that.send_value([pitch, roll, yaw, heading]);
}
}).start();
......@@ -62,8 +59,15 @@ let OrientationPanel = {
console.log("initialized orientation");
},
send_value(pitch, roll, yaw, heading) {
let payload = {pitch: pitch, roll: roll, yaw: yaw, heading: heading};
send_value(values) {
let scaled = values.map(function(i) {
return parseInt(i * 127);
});
let payload = {pitch: scaled[0],
roll: scaled[1],
yaw: scaled[2],
heading: scaled[4]
};
this.orientationChannel.push("orientation", payload)
.receive("error", e => console.log(e));
......
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