From d7c0a3b482ca0b564412a4f622876802cf571bd1 Mon Sep 17 00:00:00 2001 From: Sebastian Reichel Date: Sun, 12 Aug 2012 20:37:54 +0200 Subject: new atmostripe protocol --- actuators/motor-controller.vala | 2 ++ actuators/motor/atmostripe.vala | 52 +++++++++++++++++++++++++++++++++++++++-- 2 files changed, 52 insertions(+), 2 deletions(-) diff --git a/actuators/motor-controller.vala b/actuators/motor-controller.vala index b638e06..9fe0040 100644 --- a/actuators/motor-controller.vala +++ b/actuators/motor-controller.vala @@ -20,4 +20,6 @@ public interface MotorController : Device { public abstract void init(KeyFile cfg) throws Error; public abstract bool set_single(uint8 m, uint8 v); public abstract bool set_all(uint8 v); + public abstract bool disable(); + public abstract bool enable(); } diff --git a/actuators/motor/atmostripe.vala b/actuators/motor/atmostripe.vala index 7cc9146..b20cc44 100644 --- a/actuators/motor/atmostripe.vala +++ b/actuators/motor/atmostripe.vala @@ -25,11 +25,59 @@ public class AtmostripeMotorController : SerialDevice, MotorController { public void init(KeyFile cfg) throws Error { var device = cfg.get_string("AtmostripeMotorController", "device"); setup(device, 9600, 8, 1); + nop(); + nop(); + nop(); + } + + public bool disable() { + uint8[4] buf = new uint8[4]; + buf[0] = 0xDE; + buf[1] = 0xAD; + buf[2] = 0xBA; + buf[3] = 0xBE; + + write(buf, 4); + read(buf, 1); + + if(buf[0] == '.') + return true; + else + return false; + } + + public bool enable() { + uint8[4] buf = new uint8[4]; + buf[0] = 0xCA; + buf[1] = 0xFE; + buf[2] = 0xBA; + buf[3] = 0xBE; + + write(buf, 4); + read(buf, 1); + + if(buf[0] == '.') + return true; + else + return false; + } + + public bool nop() { + uint8[1] buf = new uint8[1]; + buf[0] = 0x00; + + write(buf, 1); + read(buf, 1); + + if(buf[0] == '.') + return true; + else + return false; } public bool set_single(uint8 engine, uint8 speed) { uint8[2] buf = new uint8[2]; - buf[0] = engine; + buf[0] = engine+1; buf[1] = speed; if(engine > 5) @@ -46,7 +94,7 @@ public class AtmostripeMotorController : SerialDevice, MotorController { public bool set_all(uint8 speed) { uint8[2] buf = new uint8[2]; - buf[0] = 6; + buf[0] = 0xff; buf[1] = speed; write(buf, 2); -- cgit v1.2.3