Bluetooth UART support for the Adafruit BluefruitLE SPI, for the University of York Engineering Stage 1 project

Committer:
ajp109
Date:
Sat Feb 06 20:58:22 2021 +0000
Revision:
0:a80552d32b80
Child:
1:6ff0eee2da9c
Initial commit (not working)

Who changed what in which revision?

UserRevisionLine numberNew contents of line
ajp109 0:a80552d32b80 1 /**************************************************************************/
ajp109 0:a80552d32b80 2 /*!
ajp109 0:a80552d32b80 3 @file TimeoutTimer.h
ajp109 0:a80552d32b80 4 @author hathach
ajp109 0:a80552d32b80 5
ajp109 0:a80552d32b80 6 @section LICENSE
ajp109 0:a80552d32b80 7
ajp109 0:a80552d32b80 8 Software License Agreement (BSD License)
ajp109 0:a80552d32b80 9
ajp109 0:a80552d32b80 10 Copyright (c) 2014, Adafruit Industries (adafruit.com)
ajp109 0:a80552d32b80 11 All rights reserved.
ajp109 0:a80552d32b80 12
ajp109 0:a80552d32b80 13 Redistribution and use in source and binary forms, with or without
ajp109 0:a80552d32b80 14 modification, are permitted provided that the following conditions are met:
ajp109 0:a80552d32b80 15 1. Redistributions of source code must retain the above copyright
ajp109 0:a80552d32b80 16 notice, this list of conditions and the following disclaimer.
ajp109 0:a80552d32b80 17 2. Redistributions in binary form must reproduce the above copyright
ajp109 0:a80552d32b80 18 notice, this list of conditions and the following disclaimer in the
ajp109 0:a80552d32b80 19 documentation and/or other materials provided with the distribution.
ajp109 0:a80552d32b80 20 3. Neither the name of the copyright holders nor the
ajp109 0:a80552d32b80 21 names of its contributors may be used to endorse or promote products
ajp109 0:a80552d32b80 22 derived from this software without specific prior written permission.
ajp109 0:a80552d32b80 23
ajp109 0:a80552d32b80 24 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ''AS IS'' AND ANY
ajp109 0:a80552d32b80 25 EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
ajp109 0:a80552d32b80 26 WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
ajp109 0:a80552d32b80 27 DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER BE LIABLE FOR ANY
ajp109 0:a80552d32b80 28 DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
ajp109 0:a80552d32b80 29 (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
ajp109 0:a80552d32b80 30 LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
ajp109 0:a80552d32b80 31 ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
ajp109 0:a80552d32b80 32 (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
ajp109 0:a80552d32b80 33 SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
ajp109 0:a80552d32b80 34 */
ajp109 0:a80552d32b80 35 /**************************************************************************/
ajp109 0:a80552d32b80 36
ajp109 0:a80552d32b80 37 /**
ajp109 0:a80552d32b80 38 * @{
ajp109 0:a80552d32b80 39 */
ajp109 0:a80552d32b80 40
ajp109 0:a80552d32b80 41 #ifndef _TIMEOUT_TIMER_H_
ajp109 0:a80552d32b80 42 #define _TIMEOUT_TIMER_H_
ajp109 0:a80552d32b80 43
ajp109 0:a80552d32b80 44 class TimeoutTimer
ajp109 0:a80552d32b80 45 {
ajp109 0:a80552d32b80 46 private:
ajp109 0:a80552d32b80 47 Timer timer;
ajp109 0:a80552d32b80 48 chrono::milliseconds next, interval;
ajp109 0:a80552d32b80 49
ajp109 0:a80552d32b80 50 public:
ajp109 0:a80552d32b80 51 TimeoutTimer() { set(0); }
ajp109 0:a80552d32b80 52 TimeoutTimer(uint32_t msec) { set(msec); }
ajp109 0:a80552d32b80 53
ajp109 0:a80552d32b80 54 void set(uint32_t msec) { timer.reset(); next = msec * 1ms; interval = msec * 1ms; }
ajp109 0:a80552d32b80 55 bool expired(void) const { return (timer.elapsed_time() >= next); }
ajp109 0:a80552d32b80 56 void restart(void) { timer.reset(); next = interval; }
ajp109 0:a80552d32b80 57 void reset(void) { next += interval; } // used for periodic invoke to prevent drift
ajp109 0:a80552d32b80 58 };
ajp109 0:a80552d32b80 59
ajp109 0:a80552d32b80 60 #endif /* _TIMEOUT_TIMER_H_ */
ajp109 0:a80552d32b80 61
ajp109 0:a80552d32b80 62 /** @} */