Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Diff: DoorController.h
- Revision:
 - 0:bed71d1853ef
 
diff -r 000000000000 -r bed71d1853ef DoorController.h
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/DoorController.h	Wed Jan 30 05:20:36 2019 +0000
@@ -0,0 +1,38 @@
+#pragma once
+
+#include "mbed.h"
+#include "I2CMotorDriver.h"
+
+class DoorController {
+public:
+    enum DoorState {
+        DOOR_OPENED,
+        DOOR_CLOSED,
+    };
+    I2CMotorDriver* p_motor;
+    DoorState state;
+    
+    DoorController(I2CMotorDriver& motor) {
+        p_motor = &motor;
+        state = DOOR_CLOSED;
+    }
+    
+    void open() {
+        if (state == DOOR_OPENED) return;
+        
+        p_motor->step(-45, 1, 1);
+        state = DOOR_OPENED;
+    }
+    
+    void close() {
+        if (state == DOOR_CLOSED) return;
+        
+        p_motor->step(50, 1, 1);
+        state = DOOR_CLOSED;
+    }
+    
+    void forceClose() {
+        p_motor->step(100, 1, 1);
+        state = DOOR_CLOSED;
+    }
+};