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.cpp@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 | |
| Shaun Kelsey |
6:85ac8bf9955e | 35 | #include "LEDStatus.h" |
| Shaun Kelsey |
6:85ac8bf9955e | 36 | #include "Peripherals.h" |
| Shaun Kelsey |
6:85ac8bf9955e | 37 | |
| Shaun Kelsey |
6:85ac8bf9955e | 38 | LEDStatus::LEDStatus(PinName red, int rstate, PinName green, int gstate, PinName blue, int bstate): |
| Shaun Kelsey |
6:85ac8bf9955e | 39 | rLED(red, rstate), gLED(green, gstate), bLED(blue, bstate), blinking(false), timer() |
| Shaun Kelsey |
6:85ac8bf9955e | 40 | { |
| Shaun Kelsey |
6:85ac8bf9955e | 41 | } |
| Shaun Kelsey |
6:85ac8bf9955e | 42 | |
| Shaun Kelsey |
6:85ac8bf9955e | 43 | void LEDStatus::set_state(int rstate, int gstate, int bstate) |
| Shaun Kelsey |
6:85ac8bf9955e | 44 | { |
| Shaun Kelsey |
6:85ac8bf9955e | 45 | r_act = rstate; |
| Shaun Kelsey |
6:85ac8bf9955e | 46 | g_act = gstate; |
| Shaun Kelsey |
6:85ac8bf9955e | 47 | b_act = bstate; |
| Shaun Kelsey |
6:85ac8bf9955e | 48 | |
| Shaun Kelsey |
6:85ac8bf9955e | 49 | if (!blinking) { |
| Shaun Kelsey |
6:85ac8bf9955e | 50 | rLED = r_act; |
| Shaun Kelsey |
6:85ac8bf9955e | 51 | gLED = g_act; |
| Shaun Kelsey |
6:85ac8bf9955e | 52 | bLED = b_act; |
| Shaun Kelsey |
6:85ac8bf9955e | 53 | } |
| Shaun Kelsey |
6:85ac8bf9955e | 54 | } |
| Shaun Kelsey |
6:85ac8bf9955e | 55 | |
| Shaun Kelsey |
6:85ac8bf9955e | 56 | void LEDStatus::solid() |
| Shaun Kelsey |
6:85ac8bf9955e | 57 | { |
| Shaun Kelsey |
6:85ac8bf9955e | 58 | blinking = false; |
| Shaun Kelsey |
6:85ac8bf9955e | 59 | rLED = r_act; |
| Shaun Kelsey |
6:85ac8bf9955e | 60 | gLED = g_act; |
| Shaun Kelsey |
6:85ac8bf9955e | 61 | bLED = b_act; |
| Shaun Kelsey |
6:85ac8bf9955e | 62 | |
| Shaun Kelsey |
6:85ac8bf9955e | 63 | timer.stop(); |
| Shaun Kelsey |
6:85ac8bf9955e | 64 | } |
| Shaun Kelsey |
6:85ac8bf9955e | 65 | |
| Shaun Kelsey |
6:85ac8bf9955e | 66 | void LEDStatus::blink(int ontime, int offtime, int nb) |
| Shaun Kelsey |
6:85ac8bf9955e | 67 | { |
| Shaun Kelsey |
6:85ac8bf9955e | 68 | ont_us = 1000 * ontime; |
| Shaun Kelsey |
6:85ac8bf9955e | 69 | offt_us = 1000 * offtime; |
| Shaun Kelsey |
6:85ac8bf9955e | 70 | count = 1; |
| Shaun Kelsey |
6:85ac8bf9955e | 71 | total = nb; |
| Shaun Kelsey |
6:85ac8bf9955e | 72 | blinking = true; |
| Shaun Kelsey |
6:85ac8bf9955e | 73 | |
| Shaun Kelsey |
6:85ac8bf9955e | 74 | rLED = r_act; |
| Shaun Kelsey |
6:85ac8bf9955e | 75 | gLED = g_act; |
| Shaun Kelsey |
6:85ac8bf9955e | 76 | bLED = b_act; |
| Shaun Kelsey |
6:85ac8bf9955e | 77 | bs = true; |
| Shaun Kelsey |
6:85ac8bf9955e | 78 | |
| Shaun Kelsey |
6:85ac8bf9955e | 79 | timer.reset(); |
| Shaun Kelsey |
6:85ac8bf9955e | 80 | timer.start(); |
| Shaun Kelsey |
6:85ac8bf9955e | 81 | } |
| Shaun Kelsey |
6:85ac8bf9955e | 82 | |
| Shaun Kelsey |
6:85ac8bf9955e | 83 | void LEDStatus::blink(int period, float duty, int nb) |
| Shaun Kelsey |
6:85ac8bf9955e | 84 | { |
| Shaun Kelsey |
6:85ac8bf9955e | 85 | ont_us = 1000 * period * duty; |
| Shaun Kelsey |
6:85ac8bf9955e | 86 | offt_us = (1000 * period) - ont_us; |
| Shaun Kelsey |
6:85ac8bf9955e | 87 | count = 1; |
| Shaun Kelsey |
6:85ac8bf9955e | 88 | total = nb; |
| Shaun Kelsey |
6:85ac8bf9955e | 89 | blinking = true; |
| Shaun Kelsey |
6:85ac8bf9955e | 90 | |
| Shaun Kelsey |
6:85ac8bf9955e | 91 | rLED = r_act; |
| Shaun Kelsey |
6:85ac8bf9955e | 92 | gLED = g_act; |
| Shaun Kelsey |
6:85ac8bf9955e | 93 | bLED = b_act; |
| Shaun Kelsey |
6:85ac8bf9955e | 94 | bs = true; |
| Shaun Kelsey |
6:85ac8bf9955e | 95 | |
| Shaun Kelsey |
6:85ac8bf9955e | 96 | timer.reset(); |
| Shaun Kelsey |
6:85ac8bf9955e | 97 | } |
| Shaun Kelsey |
6:85ac8bf9955e | 98 | |
| Shaun Kelsey |
6:85ac8bf9955e | 99 | bool LEDStatus::is_blinking() |
| Shaun Kelsey |
6:85ac8bf9955e | 100 | { |
| Shaun Kelsey |
6:85ac8bf9955e | 101 | return blinking; |
| Shaun Kelsey |
6:85ac8bf9955e | 102 | } |
| Shaun Kelsey |
6:85ac8bf9955e | 103 | |
| Shaun Kelsey |
6:85ac8bf9955e | 104 | void LEDStatus::update() |
| Shaun Kelsey |
6:85ac8bf9955e | 105 | { |
| Shaun Kelsey |
6:85ac8bf9955e | 106 | uint64_t time = timer.read_high_resolution_us(); |
| Shaun Kelsey |
6:85ac8bf9955e | 107 | uint64_t frame_time = time % (ont_us + offt_us); |
| Shaun Kelsey |
6:85ac8bf9955e | 108 | |
| Shaun Kelsey |
6:85ac8bf9955e | 109 | if (bs && (frame_time > ont_us)) { |
| Shaun Kelsey |
6:85ac8bf9955e | 110 | bs = false; |
| Shaun Kelsey |
6:85ac8bf9955e | 111 | rLED = LED_OFF; |
| Shaun Kelsey |
6:85ac8bf9955e | 112 | gLED = LED_OFF; |
| Shaun Kelsey |
6:85ac8bf9955e | 113 | bLED = LED_OFF; |
| Shaun Kelsey |
6:85ac8bf9955e | 114 | count++; |
| Shaun Kelsey |
6:85ac8bf9955e | 115 | |
| Shaun Kelsey |
6:85ac8bf9955e | 116 | } else if (!bs && (frame_time <= ont_us)) { |
| Shaun Kelsey |
6:85ac8bf9955e | 117 | bs = true; |
| Shaun Kelsey |
6:85ac8bf9955e | 118 | rLED = r_act; |
| Shaun Kelsey |
6:85ac8bf9955e | 119 | gLED = g_act; |
| Shaun Kelsey |
6:85ac8bf9955e | 120 | bLED = b_act; |
| Shaun Kelsey |
6:85ac8bf9955e | 121 | |
| Shaun Kelsey |
6:85ac8bf9955e | 122 | if (total > 0 && count >= total) { |
| Shaun Kelsey |
6:85ac8bf9955e | 123 | blinking = false; |
| Shaun Kelsey |
6:85ac8bf9955e | 124 | timer.stop(); |
| Shaun Kelsey |
6:85ac8bf9955e | 125 | } |
| Shaun Kelsey |
6:85ac8bf9955e | 126 | } |
| Shaun Kelsey |
6:85ac8bf9955e | 127 | } |
Heart Rate SpO2 Algorithm EvKit Health Monitor Development System Board MAXREFDES220