Not sure if device offline, or regression

pull/89/head
Rick Carlino 2014-07-01 06:31:35 -07:00
parent 88cf08a6d2
commit 2f0e4f8b63
2 changed files with 103 additions and 89 deletions

View File

@ -1,14 +1,89 @@
# The Overview controller is in need of a better name. It should be called
# 'controlController' or something. The name 'overview' is somewhat of an
# artifact.
# The overview controller provides an indepth view of a device as well as fine-
# grained controll options. The name is an artifact and needs to be changed.
# TODO: Network status indicator
# TODO: Device selection
# Run this in the command line for diagnostics.
# ======
# curl -X GET http://skynet.im/subscribe/713c69b1-e36a-11e3-93f8-f3e7e8d1cce9?token=0waw1l97lbwc23xrh0oem7d8rbai3sor --header "skynet_auth_uuid: 4bb4a961-e8e6-11e3-93f8-f3e7e8d1cce9" --header "skynet_auth_token: jce90gf7szxxyldihii1m3xv5d9jatt9"
angular.module('FarmBot').controller "OverviewController", [
'$scope'
'Restangular'
'DeviceFactory'
($scope, Restangular, DeviceFactory) ->
($scope, Restangular, Skynet) ->
$scope.x = 0
$scope.y = 0
$scope.z = 0
$scope.upx = ->
$scope.x = $scope.x + 5
$scope.upy = ->
$scope.y = $scope.y + 5
$scope.upz = ->
$scope.z = $scope.z + 5
$scope.downx = ->
$scope.x = $scope.x - 5
$scope.downy = ->
$scope.y = $scope.y - 5
$scope.downz = ->
$scope.z = $scope.z - 5
Restangular.all('devices').getList().then (data) ->
$scope.devices = data
$scope.device = data[0]
$scope.device.connectToSkyNet()
$scope.connectToSkyNet()
]
$scope.goHome = ->
$scope.socket.emit "message",
devices: $scope.device.uuid
payload:
message_type: 'single_command'
time_stamp: new Date()
command:
action: 'MOVE ABSOLUTE'
x: 0
y: 0
z: 0
speed: 100 # Not sure about this one.
amount: 0 # Is this for "DOSE WATER"?
delay: 0
, (data) ->
console.log data
return true
$scope.goAbs = ->
$scope.socket.emit "message",
devices: $scope.device.uuid
payload:
message_type: 'single_command'
time_stamp: new Date()
command:
action: 'MOVE ABSOLUTE'
x: $scope.x
y: $scope.y
z: $scope.z
speed: 100 # Not sure about this one.
amount: 0 # Is this for "DOSE WATER"?
delay: 0
, (data) ->
console.log data
return true
$scope.connectToSkyNet = ->
config =
type: "farmbotdss"
uuid: "901ba251-ed7a-11e3-995a-b7667747c514"
token: "32pwbkzd7qp06bt9zznee5xjhc7kfbt9"
protocol: "websocket"
skynet config, (e, socket) ->
throw e if e
$scope.socket = socket
$scope.socket.on "message", (message) ->
#TODO: Append all incoming messages to an array for display / unit tests.
console.log "message received", message
$scope.debug = ->
$scope.socket.emit "message", JSON.parse($scope.message), (data) ->
console.log data
]

View File

@ -1,89 +1,28 @@
# The overview controller provides an indepth view of a device as well as fine-
# grained controll options. Needs a better name.
# TODO: Network status indicator
# TODO: Device selection
# Run this in the command line for diagnostics.
# ======
# curl -X GET http://skynet.im/subscribe/713c69b1-e36a-11e3-93f8-f3e7e8d1cce9?token=0waw1l97lbwc23xrh0oem7d8rbai3sor --header "skynet_auth_uuid: 4bb4a961-e8e6-11e3-93f8-f3e7e8d1cce9" --header "skynet_auth_token: jce90gf7szxxyldihii1m3xv5d9jatt9"
# The deivce settings controller mostly handles SkyNet configuration options.
# If you're storing things related to a particular device and it's not an action
# it probably belongs in here.
app = angular.module('FarmBot')
angular.module('FarmBot').controller "OverviewController", [
'$scope'
'Restangular'
($scope, Restangular, Skynet) ->
controller = ($scope, Restangular) ->
$scope.devices = Restangular.all('devices').getList().$object
$scope.x = 0
$scope.y = 0
$scope.z = 0
$scope.device = {}
$scope.upx = ->
$scope.x = $scope.x + 5
$scope.upy = ->
$scope.y = $scope.y + 5
$scope.upz = ->
$scope.z = $scope.z + 5
$scope.downx = ->
$scope.x = $scope.x - 5
$scope.downy = ->
$scope.y = $scope.y - 5
$scope.downz = ->
$scope.z = $scope.z - 5
$scope.removeDevice = (device) ->
device.remove().then ->
$scope.devices = _.without($scope.devices, device);
Restangular.all('devices').getList().then (data) ->
$scope.devices = data
$scope.device = data[0]
$scope.connectToSkyNet()
$scope.selectDevice = (device) ->
$scope.device = device
$scope.goHome = ->
$scope.socket.emit "message",
devices: $scope.device.uuid
payload:
message_type: 'single_command'
time_stamp: new Date()
command:
action: 'MOVE ABSOLUTE'
x: 0
y: 0
z: 0
speed: 100 # Not sure about this one.
amount: 0 # Is this for "DOSE WATER"?
delay: 0
, (data) ->
console.log data
return true
$scope.createDevice = ->
if typeof($scope.device._id) != 'undefined'
$scope.device.put().then (data) ->
$scope.device = {}
else
$scope.devices.post($scope.device).then (data) ->
$scope.devices.push(data)
$scope.device = {}
$scope.goAbs = ->
$scope.socket.emit "message",
devices: $scope.device.uuid
payload:
message_type: 'single_command'
time_stamp: new Date()
command:
action: 'MOVE ABSOLUTE'
x: $scope.x
y: $scope.y
z: $scope.z
speed: 100 # Not sure about this one.
amount: 0 # Is this for "DOSE WATER"?
delay: 0
, (data) ->
console.log data
return true
$scope.connectToSkyNet = ->
config =
type: "farmbotdss"
uuid: "901ba251-ed7a-11e3-995a-b7667747c514"
token: "32pwbkzd7qp06bt9zznee5xjhc7kfbt9"
protocol: "websocket"
skynet config, (e, socket) ->
throw e if e
$scope.socket = socket
$scope.socket.on "message", (message) ->
console.log "message received", message
$scope.debug = ->
$scope.socket.emit "message", JSON.parse($scope.message), (data) ->
console.log data
]
app.controller "SettingsController", ['$scope', 'Restangular', controller]