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.
Dependencies: XBeeLib mbed HvZAlphaNumLib HvZServerLib
Stun.hpp
00001 #ifndef _Stun 00002 #define _Stun 00003 00004 #include "mbed.h" 00005 00006 class Stun { 00007 private: 00008 00009 // Tag status and timing 00010 bool m_is_stunned; //< Whether currently stunned or not 00011 // Game options 00012 unsigned m_stun_time; //< Total duration of current stun 00013 Timer m_stun_timer; //< Current amount of stun 00014 Timeout m_stun_timeout; //< Triggers when the stun is over 00015 Ticker m_stun_ticker; //< Ticks for the duration of the stun 00016 00017 // Tag LED 00018 DigitalOut m_stun_led; 00019 00020 public: 00021 inline Stun(PinName stun_led) 00022 : m_is_stunned(false), m_stun_time(0), m_stun_led(stun_led) 00023 { 00024 } 00025 00026 /// Get the stun status 00027 inline bool stunned() { return m_is_stunned; } 00028 00029 /// Get the stun time remaining 00030 inline int stunleft() 00031 { 00032 if (!m_is_stunned) return 0; 00033 return m_stun_time - m_stun_timer.read(); 00034 } 00035 00036 /* Actions */ 00037 inline void stun(unsigned duration) 00038 { 00039 m_is_stunned = true; 00040 m_stun_time = duration; 00041 m_stun_timeout.attach(this, &Stun::stun_expire, m_stun_time); 00042 m_stun_ticker.attach(this, &Stun::stun_tick, 1); 00043 m_stun_timer.start(); 00044 m_stun_led = 1; 00045 } 00046 00047 private: 00048 inline void stun_tick() 00049 { 00050 00051 } 00052 00053 inline void stun_expire() 00054 { 00055 m_is_stunned = false; 00056 m_stun_ticker.detach(); 00057 m_stun_timer.stop(); 00058 m_stun_timer.reset(); 00059 m_stun_led = 0; 00060 m_stun_time = 0; 00061 00062 } 00063 }; 00064 00065 00066 #endif
Generated on Wed Jul 13 2022 16:17:46 by
1.7.2