TEST

Dependencies:   max32630fthr Adafruit_FeatherOLED USBDevice

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?

UserRevisionLine numberNew 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 #ifndef _LEDSTATUS_H_
gmehmet 1:f60eafbf009a 36 #define _LEDSTATUS_H_
gmehmet 1:f60eafbf009a 37 #include "mbed.h"
gmehmet 1:f60eafbf009a 38
gmehmet 1:f60eafbf009a 39 class LEDStatus
gmehmet 1:f60eafbf009a 40 {
gmehmet 1:f60eafbf009a 41 public:
gmehmet 1:f60eafbf009a 42
gmehmet 1:f60eafbf009a 43 /** Create an LED_Status controller
gmehmet 1:f60eafbf009a 44 *
gmehmet 1:f60eafbf009a 45 * @param red PinName of red LED
gmehmet 1:f60eafbf009a 46 * @param rstate Initial state of red LED
gmehmet 1:f60eafbf009a 47 * @param green PinName of green LED
gmehmet 1:f60eafbf009a 48 * @param gstate Initial state of green LED
gmehmet 1:f60eafbf009a 49 * @param blue PinName of blue LED
gmehmet 1:f60eafbf009a 50 * @param bstate Initial state of blue LED
gmehmet 1:f60eafbf009a 51 */
gmehmet 1:f60eafbf009a 52 LEDStatus(PinName red, int rstate, PinName green, int gstate, PinName blue, int bstate);
gmehmet 1:f60eafbf009a 53
gmehmet 1:f60eafbf009a 54 /** Set the active state of each LED
gmehmet 1:f60eafbf009a 55 *
gmehmet 1:f60eafbf009a 56 * @param rstate active state of red LED
gmehmet 1:f60eafbf009a 57 * @param gstate active state of green LED
gmehmet 1:f60eafbf009a 58 * @param bstate active state of blue LED
gmehmet 1:f60eafbf009a 59 */
gmehmet 1:f60eafbf009a 60 void set_state(int rstate, int gstate, int bstate);
gmehmet 1:f60eafbf009a 61
gmehmet 1:f60eafbf009a 62 /** Set and keep the LEDs in their active state */
gmehmet 1:f60eafbf009a 63 void solid();
gmehmet 1:f60eafbf009a 64
gmehmet 1:f60eafbf009a 65 /** Set the LEDs to toggle between their active state and their off state
gmehmet 1:f60eafbf009a 66 *
gmehmet 1:f60eafbf009a 67 * @param ontime The amount of time (in milliseconds) to remain in the active state
gmehmet 1:f60eafbf009a 68 * @param offtime The amount of time (in milliseconds) to remain off
gmehmet 1:f60eafbf009a 69 * @param nb The number of times to blink before remaining in the off state
gmehmet 1:f60eafbf009a 70 * Set to -1 to blink indefinitely
gmehmet 1:f60eafbf009a 71 *
gmehmet 1:f60eafbf009a 72 */
gmehmet 1:f60eafbf009a 73 void blink(int ontime, int offtime, int nb = -1);
gmehmet 1:f60eafbf009a 74
gmehmet 1:f60eafbf009a 75 /** Set the LEDs to toggle between their active state and their off state
gmehmet 1:f60eafbf009a 76 *
gmehmet 1:f60eafbf009a 77 * @param period The period of each blink (in milliseconds)
gmehmet 1:f60eafbf009a 78 * @param offtime The percentage of the period during which the LEDs will be in their active state
gmehmet 1:f60eafbf009a 79 * @param nb The number of times to blink before remaining in the off state
gmehmet 1:f60eafbf009a 80 * Set to -1 to blink indefinitely
gmehmet 1:f60eafbf009a 81 */
gmehmet 1:f60eafbf009a 82 void blink(int period, float duty, int nb = -1);
gmehmet 1:f60eafbf009a 83
gmehmet 1:f60eafbf009a 84 /** Get whether LEDState is in the blinking state
gmehmet 1:f60eafbf009a 85 */
gmehmet 1:f60eafbf009a 86 bool is_blinking();
gmehmet 1:f60eafbf009a 87
gmehmet 1:f60eafbf009a 88 /** Called in main loop of program to advance the state of the class
gmehmet 1:f60eafbf009a 89 * @detail Instead of using a Ticker and generating additional interrupts and overhead,
gmehmet 1:f60eafbf009a 90 * LEDStatus relies on update being called at a decent interval in order
gmehmet 1:f60eafbf009a 91 * to advance its interval time keeping and blink LEDs and the correct rate.
gmehmet 1:f60eafbf009a 92 * If only using solid() mode, update() does not need to be called.
gmehmet 1:f60eafbf009a 93 */
gmehmet 1:f60eafbf009a 94 void update();
gmehmet 1:f60eafbf009a 95
gmehmet 1:f60eafbf009a 96 private:
gmehmet 1:f60eafbf009a 97
gmehmet 1:f60eafbf009a 98 DigitalOut rLED;
gmehmet 1:f60eafbf009a 99 DigitalOut gLED;
gmehmet 1:f60eafbf009a 100 DigitalOut bLED;
gmehmet 1:f60eafbf009a 101
gmehmet 1:f60eafbf009a 102 int r_act;
gmehmet 1:f60eafbf009a 103 int g_act;
gmehmet 1:f60eafbf009a 104 int b_act;
gmehmet 1:f60eafbf009a 105
gmehmet 1:f60eafbf009a 106 bool blinking;
gmehmet 1:f60eafbf009a 107 bool bs;
gmehmet 1:f60eafbf009a 108 int count;
gmehmet 1:f60eafbf009a 109 int total;
gmehmet 1:f60eafbf009a 110
gmehmet 1:f60eafbf009a 111 uint64_t ont_us;
gmehmet 1:f60eafbf009a 112 uint64_t offt_us;
gmehmet 1:f60eafbf009a 113
gmehmet 1:f60eafbf009a 114 Timer timer;
gmehmet 1:f60eafbf009a 115
gmehmet 1:f60eafbf009a 116 };
gmehmet 1:f60eafbf009a 117
gmehmet 1:f60eafbf009a 118 #endif
gmehmet 1:f60eafbf009a 119