improve execute of stty. before stty executed always, when write byte to ttyacm, now once when mc connected

This commit is contained in:
MaximZaitsev
2016-08-16 16:41:51 +03:00
parent ab85ccb5d8
commit 4c24366c54
2 changed files with 17 additions and 29 deletions
+14 -29
View File
@@ -5,9 +5,7 @@ import carControl.RouteExecutorImpl.MoveDirection
/** /**
* Created by user on 7/27/16. * Created by user on 7/27/16.
*/ */
class Car constructor(routeExecutor: RouteExecutor, controller: Control) { class Car constructor(val routeExecutor: RouteExecutor, val controller: Control) {
val exec: dynamic
val velocityMove = 0.3278 val velocityMove = 0.3278
val velocityRotation = 12.3 val velocityRotation = 12.3
@@ -19,16 +17,11 @@ class Car constructor(routeExecutor: RouteExecutor, controller: Control) {
var moveDirection: MoveDirection = MoveDirection.STOP var moveDirection: MoveDirection = MoveDirection.STOP
val routeExecutor: RouteExecutor
val controller: Control
init { init {
this.routeExecutor = routeExecutor
this.controller = controller
this.x = 0.0 this.x = 0.0
this.y = 0.0 this.y = 0.0
this.angle = 0.0 this.angle = 0.0
this.exec = require("child_process").exec
} }
fun stopCar() { fun stopCar() {
@@ -61,29 +54,21 @@ class Car constructor(routeExecutor: RouteExecutor, controller: Control) {
fun move(moveDirection: MoveDirection, value: Int, callBack: () -> Unit) { fun move(moveDirection: MoveDirection, value: Int, callBack: () -> Unit) {
//value - angle for rotation command and distance for forward/backward command //value - angle for rotation command and distance for forward/backward command
val functionAfterStty = { error: dynamic, stdOut: dynamic, stdErr: dynamic -> this.moveDirection = moveDirection
if (error != null) { when (moveDirection) {
println("error in execute stty\n" + error.toString()) MoveDirection.STOP -> controller.stopCar()
} MoveDirection.FORWARD -> controller.moveCarForward()
this.moveDirection = moveDirection MoveDirection.BACKWARD -> controller.moveCarBackward()
when (moveDirection) { MoveDirection.LEFT -> controller.moveCarLeft()
MoveDirection.STOP -> controller.stopCar() MoveDirection.RIGHT -> controller.moveCarRight()
MoveDirection.FORWARD -> controller.moveCarForward() }
MoveDirection.BACKWARD -> controller.moveCarBackward() if (moveDirection != MoveDirection.STOP) {
MoveDirection.LEFT -> controller.moveCarLeft() if (moveDirection == MoveDirection.FORWARD || moveDirection == MoveDirection.BACKWARD) {
MoveDirection.RIGHT -> controller.moveCarRight() controller.delay(getTimeForMoving(value, velocityMove), callBack)
} } else {
if (moveDirection != MoveDirection.STOP) { controller.delay(getTimeForMoving(value, velocityRotation), callBack)
if (moveDirection == MoveDirection.FORWARD || moveDirection == MoveDirection.BACKWARD) {
controller.delay(getTimeForMoving(value, velocityMove), callBack)
} else {
controller.delay(getTimeForMoving(value, velocityRotation), callBack)
}
} }
} }
exec("stty -F ${MicroController.instance.transportFilePath} raw -echo -echoe -echok", functionAfterStty)
} }
fun getTimeForMoving(value: Int, velocity: Double): Int { fun getTimeForMoving(value: Int, velocity: Double): Int {
+3
View File
@@ -4,9 +4,11 @@
class Udev { class Udev {
val udev: dynamic val udev: dynamic
val exec: dynamic
init { init {
udev = require("udev") udev = require("udev")
exec = require("child_process").execSync
} }
fun start() { fun start() {
@@ -18,6 +20,7 @@ class Udev {
println("mc connected. transport file is " + device.DEVNAME) println("mc connected. transport file is " + device.DEVNAME)
microController.transportFilePath = device.DEVNAME; microController.transportFilePath = device.DEVNAME;
mcTransport.initStreams(device.DEVNAME) mcTransport.initStreams(device.DEVNAME)
exec("stty -F ${MicroController.instance.transportFilePath} raw -echo -echoe -echok")
} }
}) })