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.
Command.h@11:6c56d8ca6e99, 2015-11-29 (annotated)
- Committer:
- Xiaofei
- Date:
- Sun Nov 29 00:15:41 2015 +0000
- Revision:
- 11:6c56d8ca6e99
- Parent:
- 10:6e32b53f04c3
C
Who changed what in which revision?
| User | Revision | Line number | New contents of line |
|---|---|---|---|
| Xiaofei | 0:4bc34a5fcc29 | 1 | #pragma once |
| Xiaofei | 0:4bc34a5fcc29 | 2 | #include <cstdint> |
| Xiaofei | 0:4bc34a5fcc29 | 3 | |
| Xiaofei | 7:3dee2b884e1f | 4 | /** Command class. |
| Xiaofei | 7:3dee2b884e1f | 5 | * Author Xiaofei Qiu |
| Xiaofei | 7:3dee2b884e1f | 6 | */ |
| Xiaofei | 0:4bc34a5fcc29 | 7 | class Command |
| Xiaofei | 0:4bc34a5fcc29 | 8 | { |
| Xiaofei | 0:4bc34a5fcc29 | 9 | public: |
| Xiaofei | 1:13c4bf8989d5 | 10 | Command(); |
| Xiaofei | 7:3dee2b884e1f | 11 | |
| Xiaofei | 0:4bc34a5fcc29 | 12 | Command(const Command&); |
| Xiaofei | 7:3dee2b884e1f | 13 | |
| Xiaofei | 0:4bc34a5fcc29 | 14 | virtual ~Command(){} |
| Xiaofei | 7:3dee2b884e1f | 15 | |
| Xiaofei | 7:3dee2b884e1f | 16 | /** Uses vitual function for dynamic binding */ |
| Xiaofei | 0:4bc34a5fcc29 | 17 | virtual void execute() = 0; |
| Xiaofei | 7:3dee2b884e1f | 18 | |
| Xiaofei | 8:0752270a196e | 19 | /** Sets Speed, if is_negative is true, then speed will be negative. otherwaise, speed is posotive */ |
| Xiaofei | 7:3dee2b884e1f | 20 | void setSpeed(const std::int8_t& sp, const std::int8_t& is_negative = 0); |
| Xiaofei | 0:4bc34a5fcc29 | 21 | |
| Xiaofei | 0:4bc34a5fcc29 | 22 | protected: |
| Xiaofei | 9:a4334ac1435f | 23 | /** Motor speed */ |
| Xiaofei | 3:97a5a3744481 | 24 | float _SPEED; |
| Xiaofei | 7:3dee2b884e1f | 25 | |
| Xiaofei | 7:3dee2b884e1f | 26 | /** Direction of the motor speed */ |
| Xiaofei | 3:97a5a3744481 | 27 | bool _IS_NEGATIVE; |
| Xiaofei | 0:4bc34a5fcc29 | 28 | }; |
| Xiaofei | 0:4bc34a5fcc29 | 29 | |
| Xiaofei | 0:4bc34a5fcc29 | 30 | class LedCommand : public Command |
| Xiaofei | 0:4bc34a5fcc29 | 31 | { |
| Xiaofei | 0:4bc34a5fcc29 | 32 | public: |
| Xiaofei | 0:4bc34a5fcc29 | 33 | LedCommand(){} |
| Xiaofei | 0:4bc34a5fcc29 | 34 | virtual void execute(); |
| Xiaofei | 0:4bc34a5fcc29 | 35 | }; |
| Xiaofei | 0:4bc34a5fcc29 | 36 | |
| Xiaofei | 0:4bc34a5fcc29 | 37 | class TurnLeftCommand : public Command |
| Xiaofei | 0:4bc34a5fcc29 | 38 | { |
| Xiaofei | 0:4bc34a5fcc29 | 39 | public: |
| Xiaofei | 0:4bc34a5fcc29 | 40 | TurnLeftCommand(){} |
| Xiaofei | 0:4bc34a5fcc29 | 41 | virtual void execute(); |
| Xiaofei | 0:4bc34a5fcc29 | 42 | }; |
| Xiaofei | 0:4bc34a5fcc29 | 43 | |
| Xiaofei | 0:4bc34a5fcc29 | 44 | class TurnRightCommand : public Command |
| Xiaofei | 0:4bc34a5fcc29 | 45 | { |
| Xiaofei | 0:4bc34a5fcc29 | 46 | public: |
| Xiaofei | 0:4bc34a5fcc29 | 47 | TurnRightCommand(){} |
| Xiaofei | 0:4bc34a5fcc29 | 48 | virtual void execute(); |
| Xiaofei | 0:4bc34a5fcc29 | 49 | }; |
| Xiaofei | 0:4bc34a5fcc29 | 50 | |
| Xiaofei | 10:6e32b53f04c3 | 51 | class GoStraightCommand : public Command |
| Xiaofei | 10:6e32b53f04c3 | 52 | { |
| Xiaofei | 10:6e32b53f04c3 | 53 | public: |
| Xiaofei | 10:6e32b53f04c3 | 54 | GoStraightCommand(){} |
| Xiaofei | 10:6e32b53f04c3 | 55 | virtual void execute(); |
| Xiaofei | 10:6e32b53f04c3 | 56 | }; |
| Xiaofei | 10:6e32b53f04c3 | 57 | |
| Xiaofei | 0:4bc34a5fcc29 | 58 | class StopCommand : public Command |
| Xiaofei | 0:4bc34a5fcc29 | 59 | { |
| Xiaofei | 0:4bc34a5fcc29 | 60 | public: |
| Xiaofei | 0:4bc34a5fcc29 | 61 | StopCommand(){} |
| Xiaofei | 0:4bc34a5fcc29 | 62 | virtual void execute(); |
| Xiaofei | 1:13c4bf8989d5 | 63 | }; |