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.
Revision 6:02df5c1108f1, committed 2020-04-09
- Comitter:
- kabukistarship
- Date:
- Thu Apr 09 22:40:13 2020 +0000
- Parent:
- 5:4136e9141bde
- Commit message:
- Renamed StatusLED to StatusIndicator.
Changed in this revision
--- a/ErrorList.h Wed Apr 08 12:36:17 2020 +0000 +++ b/ErrorList.h Thu Apr 09 22:40:13 2020 +0000 @@ -7,7 +7,7 @@ Public License, v. 2.0. If a copy of the MPL was not distributed with this file, You can obtain one at <https://mozilla.org/MPL/2.0/>. */ #pragma once -#include <mbedbug_config.h> +#include <mbedBugConfig.h> namespace mbedBug { /* An array of error strings.
--- a/LEDRGBStatus.h Wed Apr 08 12:36:17 2020 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,222 +0,0 @@ -/* mbedbug @version 0.x -@link https://github.com/KabukiStarship/mbedbug.git -@file /led_rgb_status.h -@author Cale McCollough <https://cale-mccollough.github.io> -@license Copyright 2016-20 (C) Kabuki Starship <kabukistarship.com>; all rights -reserved (R). This Source Code Form is subject to the terms of the Mozilla -Public License, v. 2.0. If a copy of the MPL was not distributed with this file, -You can obtain one at <https://mozilla.org/MPL/2.0/>. */ -#ifndef _mbedBug_RGBStatusLED_header -#define _mbedBug_RGBStatusLED_header -#include "mbed.h" -#include <stdint.h> -#define CREATE_RGB_STATUS_LED \ -static RGBStatusLED<0,1> Status (RED_LED, GREEN_LED, BLUE_LED);\ - -#define Assert(statement, message) {\ - if (!(statement)) {\ - printf("Assert: %s\r\n%s, line %d\r\n", #message, __FILE__, __LINE__)\ - Status.HandleAssert ()\ - while (true)\ - }\ -} - -namespace Primary { - -typedef enum { - ColorPresetBlack = 0, - ColorPresetRed = 1, - ColorPresetYellow = 2, - ColorPresetGreen = 3, - cColorPresetCyan = 4, - ColorPresetBlue = 5, - ColorPresetMagenta = 6, - cColorPresetWhite = 7 -} Color; -} //< namespace Primary - -namespace mbedbug { - -/* The onboard mbed RGB LED. -Some boards have PWM on the RGB LED, some don't. This class uses DigitalOut(s). -There are 8 potential combinations of Color without PWM (@see Wiki -"Color Space"). - -@code -RGBStatusLED<0, 1> stausLED (RED_LED, GREEN_LED, BLUE_LED); //< Use <0, 1> if you're LED is active low. -RGBStatusLED<1, 0> stausLED (p0, p1, p2); //< Use <0, 1> if you're LED is active high. - -statusLED.SetColorA (Color::); - -@endcode -*/ -template <int On, int Off> -class RGBStatusLED { - public: - - enum { - BrightnessDefault = 128 - }; - - float Frequency; //< The Frequency of the blinking. - - DigitalOut Red, //< ColorPresetRed LED on the mbed board. - Green, //< ColorPresetGreen LED on the mbed board. - Blue; //< ColorPresetBlue LED on the mbed board. - - Ticker Blinker; //< Ticker for blinking the LEDs. - - uint8_t Color, //< The current Color. - ColorA, //< Blink Color A. - ColorB; //< Blink Color B. - - /* Simple constructor. */ - RGBStatusLED (PinName RedLED, PinName GreenLED, PinName BlueLED, float BinkDelay = 0.2f) - : Frequency (Frequency), - Red (RedLED), - Green (GreenLED), - Blue (BlueLED), - Blinker (), - Color (Color::ColorPresetBlack), - ColorA (Color::ColorPresetBlack), - ColorB (Color::ColorPresetBlack) { - Red = Green = Blue = 1; - } - - /* Updates the RGB status LED "frame": Color. */ - void Update () { - switch (Color) { - case Color::ColorPresetBlack : Red = 1; Green = 1; Blue = 1; return; - case Color::ColorPresetRed : Red = 0; Green = 1; Blue = 1; return; - case Color::ColorPresetYellow : Red = 0; Green = 0; Blue = 1; return; - case Color::ColorPresetGreen : Red = 1; Green = 0; Blue = 1; return; - case Color::cColorPresetCyan : Red = 1; Green = 0; Blue = 0; return; - case Color::ColorPresetBlue : Red = 1; Green = 1; Blue = 0; return; - case Color::ColorPresetMagenta: Red = 0; Green = 1; Blue = 0; return; - case Color::cColorPresetWhite : Red = 0; Green = 0; Blue = 0; return; - } - } - - /* Sets ColorA. */ - void SetColorA (Primary::Color Value) { - ColorA = Value; - } - - /* Sets ColorB. */ - void SetColorB (Primary::Color Value) { - ColorB = Value; - } - - /* Turns off the Blinker. */ - void TurnOff () { - Red = Green = Blue = 1; - } - - /* Turns on the Blinker. */ - void TurnOn () { - Color = ColorA; - Update (); - } - - /* Sets the Color of the Blinker. */ - void ColorsSet (Primary::Color ColorA, Primary::Color ColorB = Primary::ColorPresetBlack) - { - ColorA = ColorA; - ColorB = ColorB; - } - - void FlashRedBlue () - /* Starts flashing Red and Blue lights. */ - { - ColorA = Primary::ColorPresetRed; - ColorB = Primary::ColorPresetBlue; - StartBlinking (); - } - - void StartBlinking () - /* Starts blinking. */ - { - Blinker.attach (this, &RGBStatusLED::Blink, Frequency); - Color = ColorA; - Update (); - } - - /* Stops blinking and turns off the LED. */ - void StopBlinking () { - TurnOff (); - Blinker.detach (); - Color = Primary::ColorPresetBlack; - Update (); - } - - /* Starts blinking and turns on Color A. */ - void StopBlinkingA () { - Color = ColorA; - Blinker.detach (); - } - - /* Starts blinking and turns on Color B. */ - void StopBlinkingB () { - Color = ColorB; - Blinker.detach (); - } - - - /* Sets the Blink Frequency. */ - void FrequencySet (float Value) { - Frequency = Value; - Blinker.attach (this, &RGBStatusLED::Blink, Value); - } - - /* Handler for the Assert macro. */ - void HandleAssert () { - FlashRedBlue () - } - - private: - - /* Blinks the status RGB LED on the mbed board between ColorA and ColorB. */ - void Blink () { - Color = (Color == ColorA) ? ColorB : ColorA; - Update (); - } -}; -} - -// _D_e_m_o_____________________________________________________________________ - -#if 0 //< Set to non-zero to run this demo. - -using namespace mbedbug; - -RGBStatusLED Status (LED_RED, LED_GREEN, LED_BLUE); -InterruptIn Switch3 (SW3); - -/* Interrupt handler for SW2. */ -void SW3Handler () { - static int counter = 16; - - if (++counter > 15) { - Status.FlashRedBlue (); counter = 0; - } - else if (counter & 1) { - Status.StopBlinking (); - } else { - Status.SetColorA ((Primary::Color)(counter >> 1)); - Status.SetColorB (Primary::ColorPresetBlack); - Status.StartBlinking (); - } -} - -int main() { - printf ("\r\nTesting mbed Utils.\r\n"); - PrintLine ('-'); - - Switch3.rise (&SW3Handler); - //Status.StartBlinking (); - - while (true); -} -#endif //< #if _Demo - -#endif
--- a/LEDStatus.h Wed Apr 08 12:36:17 2020 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,294 +0,0 @@ -/* mbedBug @version 0.x -@link https://github.com/KabukiStarship/mbedBug.git -@file /led_status.h -@author Cale McCollough <https://cale-mccollough.github.io> -@license Copyright 2016-20 (C) Kabuki Starship <kabukistarship.com>; all rights -reserved (R). This Source Code Form is subject to the terms of the Mozilla -Public License, v. 2.0. If a copy of the MPL was not distributed with this file, -You can obtain one at <https://mozilla.org/MPL/2.0/>. */ -#ifndef _mbedBug_StatusLED_header -#define _mbedBug_StatusLED_header -#define _Debug 0 //< Use this flag to turn this library into a debug example program. @see mbedBug.cpp:int main () -#include <mbed.h> -#include <stdint.h> -#define _CreateStatusLED \ -static StatusLED<0,1> Status (GREEN_LED);\ - -#define ASSERT(STATEMENT, MESSAGE) {\ - if (!(STATEMENT)) {\ - printf("ASSERT: %s\r\n%s, line %d\r\n", #MESSAGE, __FILE__, __LINE__)\ - Status.HandleAssert ()\ - while (true)\ - }\ -} - -namespace mbedBug { - -/* Outputs the firmware Status using the LED on the mbed board. -This class works by using strings with ASCII Mores Code. Each char in a -represents a pulse split into 4 lengths. - -| Frame | ASCII | Index | Duty Cycle | -|:-----:|:-----:|:-----:|:----------:| -| Off | ' ' | <= 44 | 0% | -| Long | '-' | 45 | 1/3 | -| Short | '.' | 46 | 1/3 | -| On | '_' | >= 47 | 100% | - -Off could be any value less than 44, and On could be any value greater than -47, but ASCII space (' ') and Period ('.') are used by convention because -they look like the pulse widths. - -## Terminology -* Frame - Each character in a char Sequence represents 3 timer interrupts. -* Pattern - A null-terminated string of frames. -* Sequence - A null-terminated string of const char*. - -@code -StatusLED<0, 1> stausLED (); //< Use <0, 1> if you're LED is active low. -StatusLED<1, 0> stausLED (LED_2); //< Use <0, 1> if you're LED is active high. - -const char* ExamplePattern[] = { - "... ", //< Blinks fast three times in a row. - "...---... ", //< SOS in Mores Code. - "____ ", //< Slowly blinks on and off. - 0 //< Must have null-termination pointer. -}; - -statusLED.SetPattern (exapmlePattern, 1.5f); - -@endcode -*/ -template <int On, int Off> -class StatusLED { - public: - - char Count, //< Counter counts from from 1-3. - Period; //< The current Period char. - - float Frequency; //< The Period length - - const char** Sequence; //< Null-terminated string of pointers. - - const char* Pattern, //< The current string in the Sequence. - * Cursor; //< The current char in the current string. - - DigitalOut Pin; //< Red LED on the mbed board. - - Ticker Blinker; //< Ticker for blinking the LEDs. - - static const float FrequencyDefault = 0.5f, //< Default Frequency in hertz. - FrequencyMin = 0.01f, //< Min Frequency in hertz. - FrequencyMax = 2.0f; //< Max Frequency in hertz. - - typedef enum { - Off = 0, - Short = 63, - Long = 127, - On = 255 - } Pulse; - - /* Simple constructor. */ - StatusLED (PinName LEDPin = LED1, float Frequency = FrequencyDefault) - : Count (0), - Period (0), - Sequence (0), - Pattern (0), - Cursor (0), - Frequency (Frequency), - Pin (LEDPin, Off) { - /// Nothing to do here. - } - - /* Sets the light blinking Sequence. */ - void SetSequence (char** SequenceNew) { - if (!SequenceNew) { - Sequence = 0; - StopBlinking (); - return; - } - - const char* TempString = Sequence[0]; - - if (TempString == 0 || TempString[0] == 0) { - #if _Debug - printf ("\r\n\nError: First Sequence and first char can't be null.\r\n\n"); - #endif - return; - } - Sequence = SequenceNew; - Pattern = SequenceNew[0]; - Cursor = Pattern; - CurrentByte = *Cursor; - Update (); - } - - /* Turns off the Blinker. */ - void TurnOff () { - Pin = Off; - } - - /* Turns on the Blinker. */ - void TurnOn () { - Color = ColorA; - Update (); - } - - /* Starts flashing the SOS Sequence. */ - void FlashSOS () { - Sequence = SoSPattern (); - Cursor = Sequence[0]; - Cursor = *Cursor; - Period = *Cursor; - } - - /* Starts blinking. */ - void StartBlinking () { - const char* _pattern = Sequence[0]; - Pattern = _pattern; - Cursor = _pattern; - Period = *_pattern; - - Blinker.attach (this, &StatusLED::blink, Frequency / 4); - Update (); - } - - /* Stops blinking and turns off the LED. */ - void StopBlinking () { - TurnOff (); - Blinker.detach (); - Pin = Off; - Update (); - } - - /* Sets the blink Frequency. */ - void FrequencySet (float Value) { - Frequency = Value; - Blinker.attach (this, &StatusLED::Blink, Value); - } - - /* Handler for the ASSERT macro. */ - void HandleAssert () { - SetPattern (SoSPattern ()); - } - - /* Pattern blinks three times in a row. */ - const char** Blink3TimesPattern () { - static const char** Sequence = { "... ", 0 }; - return &Sequence; - } - - /* Standard blink Sequence. */ - const char** SlowBlinkPattern () { - static const char** Sequence = { "__ ", 0 }; - return &Sequence; - } - - /* Standard blink Sequence. */ - const char** FastBlinkPattern () { - static const char** Sequence = { "_ ", 0 }; - return &Sequence; - } - - /* Standard SOS Sequence. */ - const char** SoSPattern () { - static const char** Sequence = { "...---... ", 0 }; - return &Sequence; - } - - /* Returns the next char in the Sequence. */ - inline char GetNextPeriod () { - /// We've already checked that the Sequence and Cursor and not null. - - char period_temp = *(++Cursor); - - if (period_temp == 0) { - const char* temp_pattern = *(Pattern + sizeof (const char*)); - - if (!temp_pattern) { - const char* _cursor = Sequence[0]; - Cursor = Pattern = _cursor; - return *_cursor; - } - Pattern = temp_pattern; - return *temp_pattern; //< We don't particularly care if the Period is '\0'. - } - - return period_temp; - } - - /* Updates the Status LED. */ - inline void Update () { - const char* period_temp = Period; - if (!Sequence || !period_temp) return; - - if (Count == 0) { //< Beginning of cycle Period. - char _period = GetNextPeriod (); - Period = _period; - Count = 1; - if (_period < '-') { - Pin = Off; - return; - } - Pin = On; - return; - } - else if (Count == 1) { //< 1/3 duty cycle. - Count = 2; - if (Period == '.') { - Pin = Off; - return; - } - return; - } - /// 2/3 duty cycle. - Count = 0; - if (Period > '.') //< Leave the LED on - return; - Pin = Off; - } -}; -} - -// _D_e_m_o_____________________________________________________________________ - -#if 0 //< Set to non-zero to run this demo. - -using namespace mbedBug; - -StatusLED Status (); -InterruptIn switch3 (SW3); - -const char* ExamplePattern[] = { - "... ", //< Blinks fast three times in a row. - "...---... ", //< SOS in Mores Code. - "____ ", //< Slowly blinks on and off. - 0 //< Pattern must have null-term pointer. -}; -/* Interrupt handler for SW2. */ -void SwitchIRQHandler () { - static bool ExamplePatterMode = true; - - if (ExamplePatterMode) { - Status.SetPattern (ExamplePattern); - Status.StartBlinking (); - ExamplePatterMode = false; - } - else { - Status.SetPattern(Status.SOSPattern ())); - ExamplePatterMode = true; - } -} - -int main() { - printf ("\r\n\nTesting mbed Utils.\r\n\n"); - PrintLine (); - - switch3.rise (&SwitchIRQHandler); - //Status.StartBlinking () - - while (true); -} - -#endif //< Demo -#endif
--- a/MorseCode.cpp Wed Apr 08 12:36:17 2020 +0000 +++ b/MorseCode.cpp Thu Apr 09 22:40:13 2020 +0000 @@ -1,6 +1,6 @@ /* mbedBug @version 0.x @link https://github.com/KabukiStarship/mbedbug.git -@file /morse_code.cpp +@file /MorseCode.cpp @author Cale McCollough <https://cale-mccollough.github.io> @license Copyright 2016-20 (C) Kabuki Starship <kabukistarship.com>; all rights reserved (R). This Source Code Form is subject to the terms of the Mozilla
--- a/MorseCode.h Wed Apr 08 12:36:17 2020 +0000 +++ b/MorseCode.h Thu Apr 09 22:40:13 2020 +0000 @@ -7,12 +7,12 @@ Public License, v. 2.0. If a copy of the MPL was not distributed with this file, You can obtain one at <https://mozilla.org/MPL/2.0/>. */ #pragma once -#ifndef MBEDBUG_MORSECODE_DECL -#define MBEDBUG_MORSECODE_DECL -namespace mbedbug { +#ifndef MbedBugMorseCodeDecl +#define MbedBugMorseCodeDecl +namespace mbedBug { /* Gets the Morse code for the given char. */ const char* CodeMorseEncode (char Value); -} //< namespace mbedbug +} //< namespace mbedBug #endif
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/StatusIndicator.h Thu Apr 09 22:40:13 2020 +0000 @@ -0,0 +1,292 @@ +/* mbedBug @version 0.x +@link https://github.com/KabukiStarship/mbedBug.git +@file /StatusIndicator.h +@author Cale McCollough <https://cale-mccollough.github.io> +@license Copyright 2016-20 (C) Kabuki Starship <kabukistarship.com>; all rights +reserved (R). This Source Code Form is subject to the terms of the Mozilla +Public License, v. 2.0. If a copy of the MPL was not distributed with this file, +You can obtain one at <https://mozilla.org/MPL/2.0/>. */ +#ifndef _mbedBug_StatusLED_header +#define _mbedBug_StatusLED_header +#define _Debug 0 //< Use this flag to turn this library into a debug example program. @see mbedBug.cpp:int main () +#include <mbedBug.h> +#define _CreateStatusLED \ +static StatusIndicator<0,1> Status (GREEN_LED);\ + +#define Assert(Statement, Message) {\ + if (!(Statement)) {\ + printf("Assert: %s\r\n%s, line %d\r\n", #Message, __FILE__, __LINE__)\ + Status.HandleAssert ()\ + while (true)\ + }\ +} + +namespace mbedBug { + +/* Outputs the firmware Status using an LED/buzzer/etc. +This class works by using strings with ASCII Mores Code. Each char in a +represents a pulse split into 4 lengths. + +| Frame | ASCII | Index | Duty Cycle | +|:-----:|:-----:|:-----:|:----------:| +| Off | ' ' | <= 44 | 0% | +| Long | '-' | 45 | 1/3 | +| Short | '.' | 46 | 1/3 | +| On | '_' | >= 47 | 100% | + +Off could be any value less than 44, and On could be any value greater than +47, but ASCII space (' ') and Period ('.') are used by convention because +they look like the pulse widths. + +## Terminology +* Frame - Each character in a char Sequence represents 3 timer interrupts. +* Pattern - A null-terminated string of frames. +* Sequence - A null-terminated string of const char*. + +@code +StatusIndicator<0, 1> stausLED (); //< Use <0, 1> if you're LED is active low. +StatusIndicator<1, 0> stausLED (LED_2); //< Use <0, 1> if you're LED is active high. + +const char* ExamplePattern[] = { + "... ", //< Blinks fast three times in a row. + "...---... ", //< SOS in Mores Code. + "____ ", //< Slowly blinks on and off. + 0 //< Must have null-termination pointer. +}; + +statusLED.SetPattern (exapmlePattern, 1.5f); + +@endcode +*/ +template <int On, int Off> +class StatusIndicator { + public: + + char Count, //< Counter counts from from 1-3. + Period; //< The current Period char. + + float Frequency; //< The Period length + + const char** Sequence; //< Null-terminated string of pointers. + + const char* Pattern, //< The current string in the Sequence. + * Cursor; //< The current char in the current string. + + DigitalOut Pin; //< Red LED on the mbed board. + + Ticker Blinker; //< Ticker for blinking the LEDs. + + static const float FrequencyDefault = 0.5f, //< Default Frequency in hertz. + FrequencyMin = 0.01f, //< Min Frequency in hertz. + FrequencyMax = 2.0f; //< Max Frequency in hertz. + + typedef enum { + Off = 0, + Short = 63, + Long = 127, + On = 255 + } Pulse; + + /* Simple constructor. */ + StatusIndicator (PinName LEDPin = LED1, float Frequency = FrequencyDefault): + Count (0), + Period (0), + Sequence (0), + Pattern (0), + Cursor (0), + Frequency (Frequency), + Pin (LEDPin, Off) { + /// Nothing to do here. + } + + /* Sets the light blinking Sequence. */ + void SetSequence (char** SequenceNew) { + if (!SequenceNew) { + Sequence = 0; + StopBlinking (); + return; + } + + const char* TempString = Sequence[0]; + + if (TempString == 0 || TempString[0] == 0) { + DPrintf("\r\n\nError: First Sequence and first char can't be null." + "\r\n\n"); + return; + } + Sequence = SequenceNew; + Pattern = SequenceNew[0]; + Cursor = Pattern; + CurrentByte = *Cursor; + Update (); + } + + /* Turns off the Blinker. */ + void TurnOff () { + Pin = Off; + } + + /* Turns on the Blinker. */ + void TurnOn () { + Color = ColorA; + Update (); + } + + /* Starts flashing the SOS Sequence. */ + void FlashSOS () { + Sequence = SoSPattern (); + Cursor = Sequence[0]; + Cursor = *Cursor; + Period = *Cursor; + } + + /* Starts blinking. */ + void StartBlinking () { + const char* _pattern = Sequence[0]; + Pattern = _pattern; + Cursor = _pattern; + Period = *_pattern; + + Blinker.attach (this, &StatusIndicator::blink, Frequency / 4); + Update (); + } + + /* Stops blinking and turns off the LED. */ + void StopBlinking () { + TurnOff (); + Blinker.detach (); + Pin = Off; + Update (); + } + + /* Sets the blink Frequency. */ + void FrequencySet (float Value) { + Frequency = Value; + Blinker.attach (this, &StatusIndicator::Blink, Value); + } + + /* Handler for the Assert macro. */ + void HandleAssert () { + SetPattern (SoSPattern ()); + } + + /* Pattern blinks three times in a row. */ + const char** Blink3TimesPattern () { + static const char** Sequence = { "... ", 0 }; + return &Sequence; + } + + /* Standard blink Sequence. */ + const char** SlowBlinkPattern () { + static const char** Sequence = { "__ ", 0 }; + return &Sequence; + } + + /* Standard blink Sequence. */ + const char** FastBlinkPattern () { + static const char** Sequence = { "_ ", 0 }; + return &Sequence; + } + + /* Standard SOS Sequence. */ + const char** SoSPattern () { + static const char** Sequence = { "...---... ", 0 }; + return &Sequence; + } + + /* Returns the next char in the Sequence. */ + inline char GetNextPeriod () { + /// We've already checked that the Sequence and Cursor and not null. + + char period_temp = *(++Cursor); + + if (period_temp == 0) { + const char* temp_pattern = *(Pattern + sizeof (const char*)); + + if (!temp_pattern) { + const char* _cursor = Sequence[0]; + Cursor = Pattern = _cursor; + return *_cursor; + } + Pattern = temp_pattern; + return *temp_pattern; //< We don't particularly care if the Period is '\0'. + } + + return period_temp; + } + + /* Updates the Status LED. */ + inline void Update () { + const char* period_temp = Period; + if (!Sequence || !period_temp) return; + + if (Count == 0) { //< Beginning of cycle Period. + char _period = GetNextPeriod (); + Period = _period; + Count = 1; + if (_period < '-') { + Pin = Off; + return; + } + Pin = On; + return; + } + else if (Count == 1) { //< 1/3 duty cycle. + Count = 2; + if (Period == '.') { + Pin = Off; + return; + } + return; + } + /// 2/3 duty cycle. + Count = 0; + if (Period > '.') //< Leave the LED on + return; + Pin = Off; + } +}; +} + +// _D_e_m_o_____________________________________________________________________ + +#if 0 //< Set to non-zero to run this demo. + +using namespace mbedBug; + +StatusIndicator Status (); +InterruptIn switch3 (SW3); + +const char* ExamplePattern[] = { + "... ", //< Blinks fast three times in a row. + "...---... ", //< SOS in Mores Code. + "____ ", //< Slowly blinks on and off. + 0 //< Pattern must have null-term pointer. +}; +/* Interrupt handler for SW2. */ +void SwitchIRQHandler () { + static bool ExamplePatterMode = true; + + if (ExamplePatterMode) { + Status.SetPattern (ExamplePattern); + Status.StartBlinking (); + ExamplePatterMode = false; + } + else { + Status.SetPattern(Status.SOSPattern ())); + ExamplePatterMode = true; + } +} + +int main() { + printf ("\r\n\nTesting mbed Utils.\r\n\n"); + PrintLine (); + + switch3.rise (&SwitchIRQHandler); + //Status.StartBlinking () + + while (true); +} + +#endif //< Demo +#endif
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/StatusIndicatorRGB.h Thu Apr 09 22:40:13 2020 +0000 @@ -0,0 +1,221 @@ +/* mbedbug @version 0.x +@link https://github.com/KabukiStarship/mbedbug.git +@file /StatusIndicatorRGB.h +@author Cale McCollough <https://cale-mccollough.github.io> +@license Copyright 2016-20 (C) Kabuki Starship <kabukistarship.com>; all rights +reserved (R). This Source Code Form is subject to the terms of the Mozilla +Public License, v. 2.0. If a copy of the MPL was not distributed with this file, +You can obtain one at <https://mozilla.org/MPL/2.0/>. */ +#ifndef MbedBugStatusIndicatorRGBDecl +#define MbedBugStatusIndicatorRGBDecl +#include "mbedBug.h" +#define CREATE_RGB_STATUS_LED \ +static RGBStatusLED<0,1> Status (RED_LED, GREEN_LED, BLUE_LED);\ + +#define Assert(statement, message) {\ + if (!(statement)) {\ + printf("Assert: %s\r\n%s, line %d\r\n", #message, __FILE__, __LINE__)\ + Status.HandleAssert ()\ + while (true)\ + }\ +} + +namespace Primary { + +typedef enum { + ColorPresetBlack = 0, + ColorPresetRed = 1, + ColorPresetYellow = 2, + ColorPresetGreen = 3, + ColorPresetCyan = 4, + ColorPresetBlue = 5, + ColorPresetMagenta = 6, + ColorPresetWhite = 7 +} Color; +} //< namespace Primary + +namespace mbedbug { + +/* The onboard mbed RGB LED. +Some boards have PWM on the RGB LED, some don't. This class uses DigitalOut(s). +There are 8 potential combinations of Color without PWM (@see Wiki +"Color Space"). + +@code +RGBStatusLED<0, 1> stausLED (RED_LED, GREEN_LED, BLUE_LED); //< Use <0, 1> if you're LED is active low. +RGBStatusLED<1, 0> stausLED (p0, p1, p2); //< Use <0, 1> if you're LED is active high. + +statusLED.SetColorA (Color::); + +@endcode +*/ +template <int On, int Off> +class RGBStatusLED { + public: + + enum { + BrightnessDefault = 128 + }; + + float Frequency; //< The Frequency of the blinking. + + DigitalOut Red, //< ColorPresetRed LED on the mbed board. + Green, //< ColorPresetGreen LED on the mbed board. + Blue; //< ColorPresetBlue LED on the mbed board. + + Ticker Blinker; //< Ticker for blinking the LEDs. + + uint8_t Color, //< The current Color. + ColorA, //< Blink Color A. + ColorB; //< Blink Color B. + + /* Simple constructor. */ + RGBStatusLED (PinName RedLED, PinName GreenLED, PinName BlueLED, float BinkDelay = 0.2f) + : Frequency (Frequency), + Red (RedLED), + Green (GreenLED), + Blue (BlueLED), + Blinker (), + Color (Color::ColorPresetBlack), + ColorA (Color::ColorPresetBlack), + ColorB (Color::ColorPresetBlack) { + Red = Green = Blue = 1; + } + + /* Updates the RGB status LED "frame": Color. */ + void Update () { + switch (Color) { + case Color::ColorPresetBlack : Red = 1; Green = 1; Blue = 1; return; + case Color::ColorPresetRed : Red = 0; Green = 1; Blue = 1; return; + case Color::ColorPresetYellow : Red = 0; Green = 0; Blue = 1; return; + case Color::ColorPresetGreen : Red = 1; Green = 0; Blue = 1; return; + case Color::ColorPresetCyan : Red = 1; Green = 0; Blue = 0; return; + case Color::ColorPresetBlue : Red = 1; Green = 1; Blue = 0; return; + case Color::ColorPresetMagenta: Red = 0; Green = 1; Blue = 0; return; + case Color::ColorPresetWhite : Red = 0; Green = 0; Blue = 0; return; + } + } + + /* Sets ColorA. */ + void SetColorA (Primary::Color Value) { + ColorA = Value; + } + + /* Sets ColorB. */ + void SetColorB (Primary::Color Value) { + ColorB = Value; + } + + /* Turns off the Blinker. */ + void TurnOff () { + Red = Green = Blue = 1; + } + + /* Turns on the Blinker. */ + void TurnOn () { + Color = ColorA; + Update (); + } + + /* Sets the Color of the Blinker. */ + void ColorsSet (Primary::Color ColorA, Primary::Color ColorB = Primary::ColorPresetBlack) + { + ColorA = ColorA; + ColorB = ColorB; + } + + void FlashRedBlue () + /* Starts flashing Red and Blue lights. */ + { + ColorA = Primary::ColorPresetRed; + ColorB = Primary::ColorPresetBlue; + StartBlinking (); + } + + void StartBlinking () + /* Starts blinking. */ + { + Blinker.attach (this, &RGBStatusLED::Blink, Frequency); + Color = ColorA; + Update (); + } + + /* Stops blinking and turns off the LED. */ + void StopBlinking () { + TurnOff (); + Blinker.detach (); + Color = Primary::ColorPresetBlack; + Update (); + } + + /* Starts blinking and turns on Color A. */ + void StopBlinkingA () { + Color = ColorA; + Blinker.detach (); + } + + /* Starts blinking and turns on Color B. */ + void StopBlinkingB () { + Color = ColorB; + Blinker.detach (); + } + + + /* Sets the Blink Frequency. */ + void FrequencySet (float Value) { + Frequency = Value; + Blinker.attach (this, &RGBStatusLED::Blink, Value); + } + + /* Handler for the Assert macro. */ + void HandleAssert () { + FlashRedBlue () + } + + private: + + /* Blinks the status RGB LED on the mbed board between ColorA and ColorB. */ + void Blink () { + Color = (Color == ColorA) ? ColorB : ColorA; + Update (); + } +}; +} + +// _D_e_m_o_____________________________________________________________________ + +#if 0 //< Set to non-zero to run this demo. + +using namespace mbedbug; + +RGBStatusLED Status (LED_RED, LED_GREEN, LED_BLUE); +InterruptIn Switch3 (SW3); + +/* Interrupt handler for SW2. */ +void SW3Handler () { + static int counter = 16; + + if (++counter > 15) { + Status.FlashRedBlue (); counter = 0; + } + else if (counter & 1) { + Status.StopBlinking (); + } else { + Status.SetColorA ((Primary::Color)(counter >> 1)); + Status.SetColorB (Primary::ColorPresetBlack); + Status.StartBlinking (); + } +} + +int main() { + printf ("\r\nTesting mbed Utils.\r\n"); + PrintLine ('-'); + + Switch3.rise (&SW3Handler); + //Status.StartBlinking (); + + while (true); +} +#endif //< #if _Demo + +#endif
--- a/mbedBug.cpp Wed Apr 08 12:36:17 2020 +0000 +++ b/mbedBug.cpp Thu Apr 09 22:40:13 2020 +0000 @@ -1,6 +1,6 @@ /** mbedbug @version 0.x @link https://github.com/KabukiStarship/mbedbug.git -@file /mbedbug.cpp +@file /mbedBug.cpp @author Cale McCollough <https://cale-mccollough.github.io> @license Copyright 2016-20 (C) Kabuki Starship <kabukistarship.com>; all rights reserved (R). This Source Code Form is subject to the terms of the Mozilla
--- a/mbedBugConfig.h Wed Apr 08 12:36:17 2020 +0000 +++ b/mbedBugConfig.h Thu Apr 09 22:40:13 2020 +0000 @@ -1,6 +1,6 @@ /** mbedBug @version 0.x @link https://github.com/KabukiStarship/mbedbug.git -@file /mbedbug_config.h +@file /mbedBugConfig.h @author Cale McCollough <https://cale-mccollough.github.io> @license Copyright 2016-20 (C) Kabuki Starship <kabukistarship.com>; all rights reserved (R). This Source Code Form is subject to the terms of the Mozilla