Solution to the Bluetooth animation service exercise
Fork of microbit-animator by
Animator.h@7:1878a4427199, 2017-02-06 (annotated)
- Committer:
- bluetooth_mdw
- Date:
- Mon Feb 06 09:44:09 2017 +0000
- Revision:
- 7:1878a4427199
- Parent:
- 0:394f7f99082b
Solution for Bluetooth SIG hands-on training course
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
bluetooth_mdw | 0:394f7f99082b | 1 | /* |
bluetooth_mdw | 0:394f7f99082b | 2 | The MIT License (MIT) |
bluetooth_mdw | 0:394f7f99082b | 3 | |
bluetooth_mdw | 0:394f7f99082b | 4 | Copyright (c) 2016 British Broadcasting Corporation. |
bluetooth_mdw | 0:394f7f99082b | 5 | This software is provided by Lancaster University by arrangement with the BBC. |
bluetooth_mdw | 0:394f7f99082b | 6 | |
bluetooth_mdw | 0:394f7f99082b | 7 | Permission is hereby granted, free of charge, to any person obtaining a |
bluetooth_mdw | 0:394f7f99082b | 8 | copy of this software and associated documentation files (the "Software"), |
bluetooth_mdw | 0:394f7f99082b | 9 | to deal in the Software without restriction, including without limitation |
bluetooth_mdw | 0:394f7f99082b | 10 | the rights to use, copy, modify, merge, publish, distribute, sublicense, |
bluetooth_mdw | 0:394f7f99082b | 11 | and/or sell copies of the Software, and to permit persons to whom the |
bluetooth_mdw | 0:394f7f99082b | 12 | Software is furnished to do so, subject to the following conditions: |
bluetooth_mdw | 0:394f7f99082b | 13 | |
bluetooth_mdw | 0:394f7f99082b | 14 | The above copyright notice and this permission notice shall be included in |
bluetooth_mdw | 0:394f7f99082b | 15 | all copies or substantial portions of the Software. |
bluetooth_mdw | 0:394f7f99082b | 16 | |
bluetooth_mdw | 0:394f7f99082b | 17 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
bluetooth_mdw | 0:394f7f99082b | 18 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
bluetooth_mdw | 0:394f7f99082b | 19 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO Animation SHALL |
bluetooth_mdw | 0:394f7f99082b | 20 | THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
bluetooth_mdw | 0:394f7f99082b | 21 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING |
bluetooth_mdw | 0:394f7f99082b | 22 | FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER |
bluetooth_mdw | 0:394f7f99082b | 23 | DEALINGS IN THE SOFTWARE. |
bluetooth_mdw | 0:394f7f99082b | 24 | */ |
bluetooth_mdw | 0:394f7f99082b | 25 | |
bluetooth_mdw | 0:394f7f99082b | 26 | #ifndef ANIMATOR_H |
bluetooth_mdw | 0:394f7f99082b | 27 | #define ANIMATOR_H |
bluetooth_mdw | 0:394f7f99082b | 28 | |
bluetooth_mdw | 0:394f7f99082b | 29 | /* |
bluetooth_mdw | 0:394f7f99082b | 30 | * Class definition for an Animator |
bluetooth_mdw | 0:394f7f99082b | 31 | */ |
bluetooth_mdw | 0:394f7f99082b | 32 | |
bluetooth_mdw | 0:394f7f99082b | 33 | #include "MicroBitDisplay.h" |
bluetooth_mdw | 0:394f7f99082b | 34 | |
bluetooth_mdw | 0:394f7f99082b | 35 | #define NUMBER_OF_ANIMATIONS 0x03 |
bluetooth_mdw | 0:394f7f99082b | 36 | |
bluetooth_mdw | 0:394f7f99082b | 37 | #define ANIMATION_CONTROL_EVENT 9100 |
bluetooth_mdw | 0:394f7f99082b | 38 | #define ANIMATION_CONTROL_START 0x01 |
bluetooth_mdw | 0:394f7f99082b | 39 | #define ANIMATION_CONTROL_STOP 0x02 |
bluetooth_mdw | 0:394f7f99082b | 40 | |
bluetooth_mdw | 0:394f7f99082b | 41 | #define ANIMATION_TYPE_EVENT 9101 |
bluetooth_mdw | 0:394f7f99082b | 42 | #define ANIMATION_TYPE_FLASH 0x01 |
bluetooth_mdw | 0:394f7f99082b | 43 | #define ANIMATION_TYPE_RIPPLE 0x02 |
bluetooth_mdw | 0:394f7f99082b | 44 | #define ANIMATION_TYPE_SPIRAL 0x03 |
bluetooth_mdw | 0:394f7f99082b | 45 | |
bluetooth_mdw | 0:394f7f99082b | 46 | #define ANIMATION_STATUS_EVENT 9101 |
bluetooth_mdw | 0:394f7f99082b | 47 | #define ANIMATION_STATUS_FREE 0x00 |
bluetooth_mdw | 0:394f7f99082b | 48 | #define ANIMATION_STATUS_BUSY 0x01 |
bluetooth_mdw | 0:394f7f99082b | 49 | |
bluetooth_mdw | 0:394f7f99082b | 50 | class Animator |
bluetooth_mdw | 0:394f7f99082b | 51 | { |
bluetooth_mdw | 0:394f7f99082b | 52 | |
bluetooth_mdw | 0:394f7f99082b | 53 | public: |
bluetooth_mdw | 0:394f7f99082b | 54 | |
bluetooth_mdw | 0:394f7f99082b | 55 | int playing; |
bluetooth_mdw | 0:394f7f99082b | 56 | int current_animation; |
bluetooth_mdw | 0:394f7f99082b | 57 | int sleep_time; |
bluetooth_mdw | 0:394f7f99082b | 58 | |
bluetooth_mdw | 0:394f7f99082b | 59 | Animator(MicroBitDisplay &_display); |
bluetooth_mdw | 0:394f7f99082b | 60 | |
bluetooth_mdw | 0:394f7f99082b | 61 | void setAnimationType(uint16_t animation); |
bluetooth_mdw | 0:394f7f99082b | 62 | |
bluetooth_mdw | 0:394f7f99082b | 63 | void start(); |
bluetooth_mdw | 0:394f7f99082b | 64 | |
bluetooth_mdw | 0:394f7f99082b | 65 | void stop(); |
bluetooth_mdw | 0:394f7f99082b | 66 | |
bluetooth_mdw | 0:394f7f99082b | 67 | void faster(); |
bluetooth_mdw | 0:394f7f99082b | 68 | |
bluetooth_mdw | 0:394f7f99082b | 69 | void slower(); |
bluetooth_mdw | 0:394f7f99082b | 70 | |
bluetooth_mdw | 0:394f7f99082b | 71 | void ripple(); |
bluetooth_mdw | 0:394f7f99082b | 72 | |
bluetooth_mdw | 0:394f7f99082b | 73 | void spiral(); |
bluetooth_mdw | 0:394f7f99082b | 74 | |
bluetooth_mdw | 0:394f7f99082b | 75 | void flash(); |
bluetooth_mdw | 0:394f7f99082b | 76 | |
bluetooth_mdw | 0:394f7f99082b | 77 | void animationLoop(); |
bluetooth_mdw | 0:394f7f99082b | 78 | |
bluetooth_mdw | 0:394f7f99082b | 79 | private: |
bluetooth_mdw | 0:394f7f99082b | 80 | |
bluetooth_mdw | 0:394f7f99082b | 81 | MicroBitDisplay &display; |
bluetooth_mdw | 0:394f7f99082b | 82 | |
bluetooth_mdw | 0:394f7f99082b | 83 | }; |
bluetooth_mdw | 0:394f7f99082b | 84 | |
bluetooth_mdw | 0:394f7f99082b | 85 | #endif |