Shinya Matsuyama
/
MF_FUJIKO_BASE
update from matsu
DoorController.h@6:fd9d4fed9946, 2019-03-16 (annotated)
- Committer:
- shinyamatsuyama
- Date:
- Sat Mar 16 15:42:24 2019 +0000
- Revision:
- 6:fd9d4fed9946
- Parent:
- 0:bed71d1853ef
091_sendfix; 11_udpread
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
poipoi | 0:bed71d1853ef | 1 | #pragma once |
poipoi | 0:bed71d1853ef | 2 | |
poipoi | 0:bed71d1853ef | 3 | #include "mbed.h" |
poipoi | 0:bed71d1853ef | 4 | #include "I2CMotorDriver.h" |
poipoi | 0:bed71d1853ef | 5 | |
poipoi | 0:bed71d1853ef | 6 | class DoorController { |
poipoi | 0:bed71d1853ef | 7 | public: |
poipoi | 0:bed71d1853ef | 8 | enum DoorState { |
poipoi | 0:bed71d1853ef | 9 | DOOR_OPENED, |
poipoi | 0:bed71d1853ef | 10 | DOOR_CLOSED, |
poipoi | 0:bed71d1853ef | 11 | }; |
poipoi | 0:bed71d1853ef | 12 | I2CMotorDriver* p_motor; |
poipoi | 0:bed71d1853ef | 13 | DoorState state; |
poipoi | 0:bed71d1853ef | 14 | |
poipoi | 0:bed71d1853ef | 15 | DoorController(I2CMotorDriver& motor) { |
poipoi | 0:bed71d1853ef | 16 | p_motor = &motor; |
poipoi | 0:bed71d1853ef | 17 | state = DOOR_CLOSED; |
poipoi | 0:bed71d1853ef | 18 | } |
poipoi | 0:bed71d1853ef | 19 | |
poipoi | 0:bed71d1853ef | 20 | void open() { |
poipoi | 0:bed71d1853ef | 21 | if (state == DOOR_OPENED) return; |
poipoi | 0:bed71d1853ef | 22 | |
poipoi | 0:bed71d1853ef | 23 | p_motor->step(-45, 1, 1); |
poipoi | 0:bed71d1853ef | 24 | state = DOOR_OPENED; |
poipoi | 0:bed71d1853ef | 25 | } |
poipoi | 0:bed71d1853ef | 26 | |
poipoi | 0:bed71d1853ef | 27 | void close() { |
poipoi | 0:bed71d1853ef | 28 | if (state == DOOR_CLOSED) return; |
poipoi | 0:bed71d1853ef | 29 | |
poipoi | 0:bed71d1853ef | 30 | p_motor->step(50, 1, 1); |
poipoi | 0:bed71d1853ef | 31 | state = DOOR_CLOSED; |
poipoi | 0:bed71d1853ef | 32 | } |
poipoi | 0:bed71d1853ef | 33 | |
poipoi | 0:bed71d1853ef | 34 | void forceClose() { |
poipoi | 0:bed71d1853ef | 35 | p_motor->step(100, 1, 1); |
poipoi | 0:bed71d1853ef | 36 | state = DOOR_CLOSED; |
poipoi | 0:bed71d1853ef | 37 | } |
poipoi | 0:bed71d1853ef | 38 | }; |