summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--actuators/motor-controller.vala4
-rw-r--r--actuators/motor/atmostripe.vala34
-rw-r--r--hw/serial-device.vala27
3 files changed, 57 insertions, 8 deletions
diff --git a/actuators/motor-controller.vala b/actuators/motor-controller.vala
index d348e53..b638e06 100644
--- a/actuators/motor-controller.vala
+++ b/actuators/motor-controller.vala
@@ -18,6 +18,6 @@ public interface MotorController : Device {
public abstract uint8 max { get ; }
public abstract void init(KeyFile cfg) throws Error;
- public abstract void set_single(uint8 m, uint8 v);
- public abstract void set_all(uint8 v);
+ public abstract bool set_single(uint8 m, uint8 v);
+ public abstract bool set_all(uint8 v);
}
diff --git a/actuators/motor/atmostripe.vala b/actuators/motor/atmostripe.vala
index ad996e7..23f0fda 100644
--- a/actuators/motor/atmostripe.vala
+++ b/actuators/motor/atmostripe.vala
@@ -23,15 +23,39 @@ public class AtmostripeMotorController : SerialDevice, MotorController {
}
public void init(KeyFile cfg) throws Error {
- /* */
+ var device = cfg.get_string("AtmostripeMotorController", "device");
+ setup(device);
}
- public void set_single(uint8 m, uint8 v) {
- /* */
+ public bool set_single(uint8 engine, uint8 speed) {
+ uint8[2] buf = new uint8[2];
+ buf[0] = engine;
+ buf[1] = speed;
+
+ if(engine > 5)
+ return false;
+
+ write(buf, 2);
+ read(buf, 2);
+
+ if(buf[0] == '.')
+ return true;
+ else
+ return false;
}
- public void set_all(uint8 v) {
- /* */
+ public bool set_all(uint8 speed) {
+ uint8[2] buf = new uint8[2];
+ buf[0] = 6;
+ buf[1] = speed;
+
+ write(buf, 2);
+ read(buf, 2);
+
+ if(buf[0] == '.')
+ return true;
+ else
+ return false;
}
}
diff --git a/hw/serial-device.vala b/hw/serial-device.vala
index bbd7698..cff68b9 100644
--- a/hw/serial-device.vala
+++ b/hw/serial-device.vala
@@ -13,8 +13,33 @@
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/
+public errordomain SerialError {
+ IO_ERROR,
+ ERRNO,
+}
+
public class SerialDevice : Device {
+ private int fd;
+
+ public void setup(string device) throws SerialError {
+ fd = Posix.open(device, Posix.O_RDWR);
+
+ if(fd < 0)
+ throw new SerialError.IO_ERROR("Could not open device!");
+
+ /* TODO */
+ }
+
+ ~I2CDevice() {
+ Posix.close(fd);
+ }
- /* TODO */
+ protected ssize_t read(void *buf, size_t count) {
+ return Posix.read(fd, buf, count);
+ }
+ protected ssize_t write(void *buf, size_t count) {
+ ssize_t size = Posix.write(fd, buf, count);
+ return size;
+ }
}