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: USBDevice max32630fthr
Utilities/LEDStatus.h@6:85ac8bf9955e, 2018-05-24 (annotated)
- Committer:
 - Shaun Kelsey 
 - Date:
 - Thu May 24 14:45:27 2018 -0700
 - Revision:
 - 6:85ac8bf9955e
 
Add LEDStatus and EventStats
Who changed what in which revision?
| User | Revision | Line number | New contents of line | 
|---|---|---|---|
| Shaun Kelsey  | 
6:85ac8bf9955e | 1 | /******************************************************************************* | 
| Shaun Kelsey  | 
6:85ac8bf9955e | 2 | * Author: Shaun Kelsey, shaun.kelsey@maximintegrated.com | 
| Shaun Kelsey  | 
6:85ac8bf9955e | 3 | * Copyright (C) 2018 Maxim Integrated Products, Inc., All Rights Reserved. | 
| Shaun Kelsey  | 
6:85ac8bf9955e | 4 | * | 
| Shaun Kelsey  | 
6:85ac8bf9955e | 5 | * Permission is hereby granted, free of charge, to any person obtaining a | 
| Shaun Kelsey  | 
6:85ac8bf9955e | 6 | * copy of this software and associated documentation files (the "Software"), | 
| Shaun Kelsey  | 
6:85ac8bf9955e | 7 | * to deal in the Software without restriction, including without limitation | 
| Shaun Kelsey  | 
6:85ac8bf9955e | 8 | * the rights to use, copy, modify, merge, publish, distribute, sublicense, | 
| Shaun Kelsey  | 
6:85ac8bf9955e | 9 | * and/or sell copies of the Software, and to permit persons to whom the | 
| Shaun Kelsey  | 
6:85ac8bf9955e | 10 | * Software is furnished to do so, subject to the following conditions: | 
| Shaun Kelsey  | 
6:85ac8bf9955e | 11 | * | 
| Shaun Kelsey  | 
6:85ac8bf9955e | 12 | * The above copyright notice and this permission notice shall be included | 
| Shaun Kelsey  | 
6:85ac8bf9955e | 13 | * in all copies or substantial portions of the Software. | 
| Shaun Kelsey  | 
6:85ac8bf9955e | 14 | * | 
| Shaun Kelsey  | 
6:85ac8bf9955e | 15 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS | 
| Shaun Kelsey  | 
6:85ac8bf9955e | 16 | * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF | 
| Shaun Kelsey  | 
6:85ac8bf9955e | 17 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. | 
| Shaun Kelsey  | 
6:85ac8bf9955e | 18 | * IN NO EVENT SHALL MAXIM INTEGRATED BE LIABLE FOR ANY CLAIM, DAMAGES | 
| Shaun Kelsey  | 
6:85ac8bf9955e | 19 | * OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, | 
| Shaun Kelsey  | 
6:85ac8bf9955e | 20 | * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR | 
| Shaun Kelsey  | 
6:85ac8bf9955e | 21 | * OTHER DEALINGS IN THE SOFTWARE. | 
| Shaun Kelsey  | 
6:85ac8bf9955e | 22 | * | 
| Shaun Kelsey  | 
6:85ac8bf9955e | 23 | * Except as contained in this notice, the name of Maxim Integrated | 
| Shaun Kelsey  | 
6:85ac8bf9955e | 24 | * Products, Inc. shall not be used except as stated in the Maxim Integrated | 
| Shaun Kelsey  | 
6:85ac8bf9955e | 25 | * Products, Inc. Branding Policy. | 
| Shaun Kelsey  | 
6:85ac8bf9955e | 26 | * | 
| Shaun Kelsey  | 
6:85ac8bf9955e | 27 | * The mere transfer of this software does not imply any licenses | 
| Shaun Kelsey  | 
6:85ac8bf9955e | 28 | * of trade secrets, proprietary technology, copyrights, patents, | 
| Shaun Kelsey  | 
6:85ac8bf9955e | 29 | * trademarks, maskwork rights, or any other form of intellectual | 
| Shaun Kelsey  | 
6:85ac8bf9955e | 30 | * property whatsoever. Maxim Integrated Products, Inc. retains all | 
| Shaun Kelsey  | 
6:85ac8bf9955e | 31 | * ownership rights. | 
| Shaun Kelsey  | 
6:85ac8bf9955e | 32 | ******************************************************************************* | 
| Shaun Kelsey  | 
6:85ac8bf9955e | 33 | */ | 
| Shaun Kelsey  | 
6:85ac8bf9955e | 34 | #ifndef _LEDSTATUS_H_ | 
| Shaun Kelsey  | 
6:85ac8bf9955e | 35 | #define _LEDSTATUS_H_ | 
| Shaun Kelsey  | 
6:85ac8bf9955e | 36 | #include "mbed.h" | 
| Shaun Kelsey  | 
6:85ac8bf9955e | 37 | |
| Shaun Kelsey  | 
6:85ac8bf9955e | 38 | class LEDStatus | 
| Shaun Kelsey  | 
6:85ac8bf9955e | 39 | { | 
| Shaun Kelsey  | 
6:85ac8bf9955e | 40 | public: | 
| Shaun Kelsey  | 
6:85ac8bf9955e | 41 | |
| Shaun Kelsey  | 
6:85ac8bf9955e | 42 | /** Create an LED_Status controller | 
| Shaun Kelsey  | 
6:85ac8bf9955e | 43 | * | 
| Shaun Kelsey  | 
6:85ac8bf9955e | 44 | * @param red PinName of red LED | 
| Shaun Kelsey  | 
6:85ac8bf9955e | 45 | * @param rstate Initial state of red LED | 
| Shaun Kelsey  | 
6:85ac8bf9955e | 46 | * @param green PinName of green LED | 
| Shaun Kelsey  | 
6:85ac8bf9955e | 47 | * @param gstate Initial state of green LED | 
| Shaun Kelsey  | 
6:85ac8bf9955e | 48 | * @param blue PinName of blue LED | 
| Shaun Kelsey  | 
6:85ac8bf9955e | 49 | * @param bstate Initial state of blue LED | 
| Shaun Kelsey  | 
6:85ac8bf9955e | 50 | */ | 
| Shaun Kelsey  | 
6:85ac8bf9955e | 51 | LEDStatus(PinName red, int rstate, PinName green, int gstate, PinName blue, int bstate); | 
| Shaun Kelsey  | 
6:85ac8bf9955e | 52 | |
| Shaun Kelsey  | 
6:85ac8bf9955e | 53 | /** Set the active state of each LED | 
| Shaun Kelsey  | 
6:85ac8bf9955e | 54 | * | 
| Shaun Kelsey  | 
6:85ac8bf9955e | 55 | * @param rstate active state of red LED | 
| Shaun Kelsey  | 
6:85ac8bf9955e | 56 | * @param gstate active state of green LED | 
| Shaun Kelsey  | 
6:85ac8bf9955e | 57 | * @param bstate active state of blue LED | 
| Shaun Kelsey  | 
6:85ac8bf9955e | 58 | */ | 
| Shaun Kelsey  | 
6:85ac8bf9955e | 59 | void set_state(int rstate, int gstate, int bstate); | 
| Shaun Kelsey  | 
6:85ac8bf9955e | 60 | |
| Shaun Kelsey  | 
6:85ac8bf9955e | 61 | /** Set and keep the LEDs in their active state */ | 
| Shaun Kelsey  | 
6:85ac8bf9955e | 62 | void solid(); | 
| Shaun Kelsey  | 
6:85ac8bf9955e | 63 | |
| Shaun Kelsey  | 
6:85ac8bf9955e | 64 | /** Set the LEDs to toggle between their active state and their off state | 
| Shaun Kelsey  | 
6:85ac8bf9955e | 65 | * | 
| Shaun Kelsey  | 
6:85ac8bf9955e | 66 | * @param ontime The amount of time (in milliseconds) to remain in the active state | 
| Shaun Kelsey  | 
6:85ac8bf9955e | 67 | * @param offtime The amount of time (in milliseconds) to remain off | 
| Shaun Kelsey  | 
6:85ac8bf9955e | 68 | * @param nb The number of times to blink before remaining in the off state | 
| Shaun Kelsey  | 
6:85ac8bf9955e | 69 | * Set to -1 to blink indefinitely | 
| Shaun Kelsey  | 
6:85ac8bf9955e | 70 | * | 
| Shaun Kelsey  | 
6:85ac8bf9955e | 71 | */ | 
| Shaun Kelsey  | 
6:85ac8bf9955e | 72 | void blink(int ontime, int offtime, int nb = -1); | 
| Shaun Kelsey  | 
6:85ac8bf9955e | 73 | |
| Shaun Kelsey  | 
6:85ac8bf9955e | 74 | /** Set the LEDs to toggle between their active state and their off state | 
| Shaun Kelsey  | 
6:85ac8bf9955e | 75 | * | 
| Shaun Kelsey  | 
6:85ac8bf9955e | 76 | * @param period The period of each blink (in milliseconds) | 
| Shaun Kelsey  | 
6:85ac8bf9955e | 77 | * @param offtime The percentage of the period during which the LEDs will be in their active state | 
| Shaun Kelsey  | 
6:85ac8bf9955e | 78 | * @param nb The number of times to blink before remaining in the off state | 
| Shaun Kelsey  | 
6:85ac8bf9955e | 79 | * Set to -1 to blink indefinitely | 
| Shaun Kelsey  | 
6:85ac8bf9955e | 80 | */ | 
| Shaun Kelsey  | 
6:85ac8bf9955e | 81 | void blink(int period, float duty, int nb = -1); | 
| Shaun Kelsey  | 
6:85ac8bf9955e | 82 | |
| Shaun Kelsey  | 
6:85ac8bf9955e | 83 | /** Get whether LEDState is in the blinking state | 
| Shaun Kelsey  | 
6:85ac8bf9955e | 84 | */ | 
| Shaun Kelsey  | 
6:85ac8bf9955e | 85 | bool is_blinking(); | 
| Shaun Kelsey  | 
6:85ac8bf9955e | 86 | |
| Shaun Kelsey  | 
6:85ac8bf9955e | 87 | /** Called in main loop of program to advance the state of the class | 
| Shaun Kelsey  | 
6:85ac8bf9955e | 88 | * @detail Instead of using a Ticker and generating additional interrupts and overhead, | 
| Shaun Kelsey  | 
6:85ac8bf9955e | 89 | * LEDStatus relies on update being called at a decent interval in order | 
| Shaun Kelsey  | 
6:85ac8bf9955e | 90 | * to advance its interval time keeping and blink LEDs and the correct rate. | 
| Shaun Kelsey  | 
6:85ac8bf9955e | 91 | * If only using solid() mode, update() does not need to be called. | 
| Shaun Kelsey  | 
6:85ac8bf9955e | 92 | */ | 
| Shaun Kelsey  | 
6:85ac8bf9955e | 93 | void update(); | 
| Shaun Kelsey  | 
6:85ac8bf9955e | 94 | |
| Shaun Kelsey  | 
6:85ac8bf9955e | 95 | private: | 
| Shaun Kelsey  | 
6:85ac8bf9955e | 96 | |
| Shaun Kelsey  | 
6:85ac8bf9955e | 97 | DigitalOut rLED; | 
| Shaun Kelsey  | 
6:85ac8bf9955e | 98 | DigitalOut gLED; | 
| Shaun Kelsey  | 
6:85ac8bf9955e | 99 | DigitalOut bLED; | 
| Shaun Kelsey  | 
6:85ac8bf9955e | 100 | |
| Shaun Kelsey  | 
6:85ac8bf9955e | 101 | int r_act; | 
| Shaun Kelsey  | 
6:85ac8bf9955e | 102 | int g_act; | 
| Shaun Kelsey  | 
6:85ac8bf9955e | 103 | int b_act; | 
| Shaun Kelsey  | 
6:85ac8bf9955e | 104 | |
| Shaun Kelsey  | 
6:85ac8bf9955e | 105 | bool blinking; | 
| Shaun Kelsey  | 
6:85ac8bf9955e | 106 | bool bs; | 
| Shaun Kelsey  | 
6:85ac8bf9955e | 107 | int count; | 
| Shaun Kelsey  | 
6:85ac8bf9955e | 108 | int total; | 
| Shaun Kelsey  | 
6:85ac8bf9955e | 109 | |
| Shaun Kelsey  | 
6:85ac8bf9955e | 110 | uint64_t ont_us; | 
| Shaun Kelsey  | 
6:85ac8bf9955e | 111 | uint64_t offt_us; | 
| Shaun Kelsey  | 
6:85ac8bf9955e | 112 | |
| Shaun Kelsey  | 
6:85ac8bf9955e | 113 | Timer timer; | 
| Shaun Kelsey  | 
6:85ac8bf9955e | 114 | |
| Shaun Kelsey  | 
6:85ac8bf9955e | 115 | }; | 
| Shaun Kelsey  | 
6:85ac8bf9955e | 116 | |
| Shaun Kelsey  | 
6:85ac8bf9955e | 117 | #endif | 
            Heart Rate SpO2 Algorithm EvKit Health Monitor Development System Board MAXREFDES220