TEST
Dependencies: max32630fthr Adafruit_FeatherOLED USBDevice
Utilities/LEDStatus.cpp@4:291477e8690d, 2020-04-19 (annotated)
- Committer:
- wwwarunraj
- Date:
- Sun Apr 19 11:19:57 2020 +0000
- Revision:
- 4:291477e8690d
- Parent:
- 1:f60eafbf009a
19/04
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
gmehmet | 1:f60eafbf009a | 1 | /******************************************************************************* |
gmehmet | 1:f60eafbf009a | 2 | * Author: Shaun Kelsey, shaun.kelsey@maximintegrated.com |
gmehmet | 1:f60eafbf009a | 3 | * Copyright (C) 2018 Maxim Integrated Products, Inc., All Rights Reserved. |
gmehmet | 1:f60eafbf009a | 4 | * |
gmehmet | 1:f60eafbf009a | 5 | * Permission is hereby granted, free of charge, to any person obtaining a |
gmehmet | 1:f60eafbf009a | 6 | * copy of this software and associated documentation files (the "Software"), |
gmehmet | 1:f60eafbf009a | 7 | * to deal in the Software without restriction, including without limitation |
gmehmet | 1:f60eafbf009a | 8 | * the rights to use, copy, modify, merge, publish, distribute, sublicense, |
gmehmet | 1:f60eafbf009a | 9 | * and/or sell copies of the Software, and to permit persons to whom the |
gmehmet | 1:f60eafbf009a | 10 | * Software is furnished to do so, subject to the following conditions: |
gmehmet | 1:f60eafbf009a | 11 | * |
gmehmet | 1:f60eafbf009a | 12 | * The above copyright notice and this permission notice shall be included |
gmehmet | 1:f60eafbf009a | 13 | * in all copies or substantial portions of the Software. |
gmehmet | 1:f60eafbf009a | 14 | * |
gmehmet | 1:f60eafbf009a | 15 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS |
gmehmet | 1:f60eafbf009a | 16 | * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF |
gmehmet | 1:f60eafbf009a | 17 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. |
gmehmet | 1:f60eafbf009a | 18 | * IN NO EVENT SHALL MAXIM INTEGRATED BE LIABLE FOR ANY CLAIM, DAMAGES |
gmehmet | 1:f60eafbf009a | 19 | * OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, |
gmehmet | 1:f60eafbf009a | 20 | * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR |
gmehmet | 1:f60eafbf009a | 21 | * OTHER DEALINGS IN THE SOFTWARE. |
gmehmet | 1:f60eafbf009a | 22 | * |
gmehmet | 1:f60eafbf009a | 23 | * Except as contained in this notice, the name of Maxim Integrated |
gmehmet | 1:f60eafbf009a | 24 | * Products, Inc. shall not be used except as stated in the Maxim Integrated |
gmehmet | 1:f60eafbf009a | 25 | * Products, Inc. Branding Policy. |
gmehmet | 1:f60eafbf009a | 26 | * |
gmehmet | 1:f60eafbf009a | 27 | * The mere transfer of this software does not imply any licenses |
gmehmet | 1:f60eafbf009a | 28 | * of trade secrets, proprietary technology, copyrights, patents, |
gmehmet | 1:f60eafbf009a | 29 | * trademarks, maskwork rights, or any other form of intellectual |
gmehmet | 1:f60eafbf009a | 30 | * property whatsoever. Maxim Integrated Products, Inc. retains all |
gmehmet | 1:f60eafbf009a | 31 | * ownership rights. |
gmehmet | 1:f60eafbf009a | 32 | ******************************************************************************* |
gmehmet | 1:f60eafbf009a | 33 | */ |
gmehmet | 1:f60eafbf009a | 34 | |
gmehmet | 1:f60eafbf009a | 35 | #include "LEDStatus.h" |
gmehmet | 1:f60eafbf009a | 36 | #include "Peripherals.h" |
gmehmet | 1:f60eafbf009a | 37 | |
gmehmet | 1:f60eafbf009a | 38 | LEDStatus::LEDStatus(PinName red, int rstate, PinName green, int gstate, PinName blue, int bstate): |
gmehmet | 1:f60eafbf009a | 39 | rLED(red, rstate), gLED(green, gstate), bLED(blue, bstate), blinking(false), timer() |
gmehmet | 1:f60eafbf009a | 40 | { |
gmehmet | 1:f60eafbf009a | 41 | } |
gmehmet | 1:f60eafbf009a | 42 | |
gmehmet | 1:f60eafbf009a | 43 | void LEDStatus::set_state(int rstate, int gstate, int bstate) |
gmehmet | 1:f60eafbf009a | 44 | { |
gmehmet | 1:f60eafbf009a | 45 | r_act = rstate; |
gmehmet | 1:f60eafbf009a | 46 | g_act = gstate; |
gmehmet | 1:f60eafbf009a | 47 | b_act = bstate; |
gmehmet | 1:f60eafbf009a | 48 | |
gmehmet | 1:f60eafbf009a | 49 | if (!blinking) { |
gmehmet | 1:f60eafbf009a | 50 | rLED = r_act; |
gmehmet | 1:f60eafbf009a | 51 | gLED = g_act; |
gmehmet | 1:f60eafbf009a | 52 | bLED = b_act; |
gmehmet | 1:f60eafbf009a | 53 | } |
gmehmet | 1:f60eafbf009a | 54 | } |
gmehmet | 1:f60eafbf009a | 55 | |
gmehmet | 1:f60eafbf009a | 56 | void LEDStatus::solid() |
gmehmet | 1:f60eafbf009a | 57 | { |
gmehmet | 1:f60eafbf009a | 58 | blinking = false; |
gmehmet | 1:f60eafbf009a | 59 | rLED = r_act; |
gmehmet | 1:f60eafbf009a | 60 | gLED = g_act; |
gmehmet | 1:f60eafbf009a | 61 | bLED = b_act; |
gmehmet | 1:f60eafbf009a | 62 | |
gmehmet | 1:f60eafbf009a | 63 | timer.stop(); |
gmehmet | 1:f60eafbf009a | 64 | } |
gmehmet | 1:f60eafbf009a | 65 | |
gmehmet | 1:f60eafbf009a | 66 | void LEDStatus::blink(int ontime, int offtime, int nb) |
gmehmet | 1:f60eafbf009a | 67 | { |
gmehmet | 1:f60eafbf009a | 68 | ont_us = 1000 * ontime; |
gmehmet | 1:f60eafbf009a | 69 | offt_us = 1000 * offtime; |
gmehmet | 1:f60eafbf009a | 70 | count = 1; |
gmehmet | 1:f60eafbf009a | 71 | total = nb; |
gmehmet | 1:f60eafbf009a | 72 | blinking = true; |
gmehmet | 1:f60eafbf009a | 73 | |
gmehmet | 1:f60eafbf009a | 74 | rLED = r_act; |
gmehmet | 1:f60eafbf009a | 75 | gLED = g_act; |
gmehmet | 1:f60eafbf009a | 76 | bLED = b_act; |
gmehmet | 1:f60eafbf009a | 77 | bs = true; |
gmehmet | 1:f60eafbf009a | 78 | |
gmehmet | 1:f60eafbf009a | 79 | timer.reset(); |
gmehmet | 1:f60eafbf009a | 80 | timer.start(); |
gmehmet | 1:f60eafbf009a | 81 | } |
gmehmet | 1:f60eafbf009a | 82 | |
gmehmet | 1:f60eafbf009a | 83 | void LEDStatus::blink(int period, float duty, int nb) |
gmehmet | 1:f60eafbf009a | 84 | { |
gmehmet | 1:f60eafbf009a | 85 | ont_us = 1000 * period * duty; |
gmehmet | 1:f60eafbf009a | 86 | offt_us = (1000 * period) - ont_us; |
gmehmet | 1:f60eafbf009a | 87 | count = 1; |
gmehmet | 1:f60eafbf009a | 88 | total = nb; |
gmehmet | 1:f60eafbf009a | 89 | blinking = true; |
gmehmet | 1:f60eafbf009a | 90 | |
gmehmet | 1:f60eafbf009a | 91 | rLED = r_act; |
gmehmet | 1:f60eafbf009a | 92 | gLED = g_act; |
gmehmet | 1:f60eafbf009a | 93 | bLED = b_act; |
gmehmet | 1:f60eafbf009a | 94 | bs = true; |
gmehmet | 1:f60eafbf009a | 95 | |
gmehmet | 1:f60eafbf009a | 96 | timer.reset(); |
gmehmet | 1:f60eafbf009a | 97 | } |
gmehmet | 1:f60eafbf009a | 98 | |
gmehmet | 1:f60eafbf009a | 99 | bool LEDStatus::is_blinking() |
gmehmet | 1:f60eafbf009a | 100 | { |
gmehmet | 1:f60eafbf009a | 101 | return blinking; |
gmehmet | 1:f60eafbf009a | 102 | } |
gmehmet | 1:f60eafbf009a | 103 | |
gmehmet | 1:f60eafbf009a | 104 | void LEDStatus::update() |
gmehmet | 1:f60eafbf009a | 105 | { |
gmehmet | 1:f60eafbf009a | 106 | uint64_t time = timer.read_high_resolution_us(); |
gmehmet | 1:f60eafbf009a | 107 | uint64_t frame_time = time % (ont_us + offt_us); |
gmehmet | 1:f60eafbf009a | 108 | |
gmehmet | 1:f60eafbf009a | 109 | if (bs && (frame_time > ont_us)) { |
gmehmet | 1:f60eafbf009a | 110 | bs = false; |
gmehmet | 1:f60eafbf009a | 111 | rLED = LED_OFF; |
gmehmet | 1:f60eafbf009a | 112 | gLED = LED_OFF; |
gmehmet | 1:f60eafbf009a | 113 | bLED = LED_OFF; |
gmehmet | 1:f60eafbf009a | 114 | count++; |
gmehmet | 1:f60eafbf009a | 115 | |
gmehmet | 1:f60eafbf009a | 116 | } else if (!bs && (frame_time <= ont_us)) { |
gmehmet | 1:f60eafbf009a | 117 | bs = true; |
gmehmet | 1:f60eafbf009a | 118 | rLED = r_act; |
gmehmet | 1:f60eafbf009a | 119 | gLED = g_act; |
gmehmet | 1:f60eafbf009a | 120 | bLED = b_act; |
gmehmet | 1:f60eafbf009a | 121 | |
gmehmet | 1:f60eafbf009a | 122 | if (total > 0 && count >= total) { |
gmehmet | 1:f60eafbf009a | 123 | blinking = false; |
gmehmet | 1:f60eafbf009a | 124 | timer.stop(); |
gmehmet | 1:f60eafbf009a | 125 | } |
gmehmet | 1:f60eafbf009a | 126 | } |
gmehmet | 1:f60eafbf009a | 127 | } |
gmehmet | 1:f60eafbf009a | 128 |