diff --git a/docs/README.md b/docs/README.md index b8fcca7..8c4d32e 100644 --- a/docs/README.md +++ b/docs/README.md @@ -41,6 +41,7 @@ For now here are some topics I want to cover tho they are not complete: - [User Defined Events](user-events.md) ## In-Depth +- [Constants](constants.md) - [Callbacks](advanced-callbacks.md) - [Max Length Constants](advanced-max-length-constants.md) - [Names & Strings](advanced-names-and-strings.md) diff --git a/docs/advanced-names-and-strings.md b/docs/advanced-names-and-strings.md index 61aa2af..f802768 100644 --- a/docs/advanced-names-and-strings.md +++ b/docs/advanced-names-and-strings.md @@ -45,10 +45,12 @@ This list represents the current list of names available at the time of this wri * `BMC_NAME_LEN_ENCODERS` applies to encoders and global encoders * `BMC_NAME_LEN_RELAYS` applies to Latching and Non-Latching Relays * `BMC_NAME_LEN_PAGES` applies to Pages -* `BMC_NAME_LEN_STRING_LIBRARY` applies to String Library names * `BMC_NAME_LEN_LIBRARY` applies to midi library * `BMC_NAME_LEN_PRESETS` applies to BMC presets * `BMC_NAME_LEN_SETLISTS` applies to set lists +* `BMC_NAME_LEN_STRING_LIBRARY` applies to String Library names +* `BMC_NAME_LEN_TIMED_EVENTS` applies to Timed Event names + ### Name retrieving methods diff --git a/docs/buttons.md b/docs/buttons.md index 5ae0cd4..dfa83c0 100644 --- a/docs/buttons.md +++ b/docs/buttons.md @@ -140,74 +140,47 @@ void onButtonsUserEvent(void (*fptr)(uint8_t n, uint32_t event, uint8_t ports, u // @t_index the index of the button you want to retrieve // @t_item a reference to the bmcStoreButton to put data in void getButton(uint8_t t_index, bmcStoreButton& t_item); -``` - -```c++ // get button data of a specific page void getButton(uint8_t t_page, uint8_t t_index, bmcStoreButton& t_item); -``` - -```c++ // get button name in the current page // @n the index of the button // @t_string a pointer to a string to put the button name in -// the length of the pointer must be BMC_NAME_LEN_BUTTONS +// see "advanced names and strings" documentation for length of char string void getButtonName(uint8_t n, char* t_string); -``` - -```c++ -// get button name of a specific page +// get button name of a specific button +// see "advanced names and strings" documentation for length of char string void getButtonName(uint8_t t_page, uint8_t n, char* t_string); -``` - -```c++ // Trigger a button being pressed, this button will remain pressed until you call triggerButtonRelease // @n the index of the button being triggered void triggerButtonPress(uint8_t n); -``` - -```c++ // Trigger a button being depressed, this function will only work on the button if triggerButtonPress was called before // @n the index of the button being triggered void triggerButtonRelease(uint8_t n); -``` - -```c++ // Get a global button's data // @t_index the index of the button you want to retrieve // @t_item a reference to the bmcStoreButton to put data in void getGlobalButton(uint8_t t_index, bmcStoreButton& t_item); -``` -```c++ // get global button name // @n the index of the button // @t_string a pointer to a string to put the button name in -// the length of the pointer must be BMC_NAME_LEN_BUTTONS -void getButtonName(uint8_t n, char* t_string); -``` +// see "advanced names and strings" documentation for length of char string +void getGlobalButtonName(uint8_t n, char* t_string); -```c++ // Trigger a global button being pressed, this button will remain pressed until you call triggerButtonRelease // @n the index of the button being triggered void triggerGlobalButtonPress(uint8_t n); -``` - -```c++ // Trigger a global button being depressed, this function will only work on the button if triggerButtonPress was called before // @n the index of the button being triggered void triggerGlobalButtonRelease(uint8_t n); -``` - -```c++ // Change the Buttons Hold Time Setting for Buttons // if @save is true it will call the settingsSave() writing the store to EEPROM // @value must be a value from 0 to 15, where 0 is 500ms, 1 is 750ms, 2 is 1000ms, etc. @@ -216,10 +189,7 @@ void triggerGlobalButtonRelease(uint8_t n); // this is so that with a value of 0 the hold threshold is 500ms, that's the minimum // since during testing i've found that a value any lower than that is unusable. void settingsSetButtonHold(uint8_t value, bool save=false); -``` - -```c++ // Get the Buttons Hold Threshold Setting for Buttons // this value will range from 0 to 15 // to get the actual time in milliseconds set inMillis to true diff --git a/docs/constants.md b/docs/constants.md new file mode 100644 index 0000000..1e15e95 --- /dev/null +++ b/docs/constants.md @@ -0,0 +1,19 @@ +*Under MIT license.* + +[Official BMC Website >> RoxXxtar.com/bmc](https://www.roxxxtar.com/bmc) + +[< Back to Documentation](README.md) + +# BMC Constants +Coming Soon + +### API +There are many API callbacks and functions available for use, these may not reflect the latest version + +##### FUNCTIONS +```c++ +``` + +##### CALLBACKS +```c++ +``` diff --git a/docs/encoders.md b/docs/encoders.md index 12579e8..b416800 100644 --- a/docs/encoders.md +++ b/docs/encoders.md @@ -21,9 +21,11 @@ void getEncoder(uint8_t t_index, bmcStoreEncoder& t_item); void getEncoder(uint8_t t_page, uint8_t t_index, bmcStoreEncoder& t_item); // get encoder name on current page passing a pointer string +// see "advanced names and strings" documentation for length of char string void getEncoderName(uint8_t t_index, char* t_string); // get encoder name on specified page passing a pointer string +// see "advanced names and strings" documentation for length of char string void getEncoderName(uint8_t t_page, uint8_t t_index, char* t_string); ``` diff --git a/docs/leds-and-pixels.md b/docs/leds-and-pixels.md index 7b20d66..42e40ef 100644 --- a/docs/leds-and-pixels.md +++ b/docs/leds-and-pixels.md @@ -135,8 +135,10 @@ void getLed(uint8_t t_index, bmcStoreLed& t_item); void getLed(uint8_t t_page, uint8_t t_index, bmcStoreLed& t_item); +// see "advanced names and strings" documentation for length of char string void getLedName(uint8_t t_index, char* t_string); +// see "advanced names and strings" documentation for length of char string void getLedName(uint8_t t_page, uint8_t t_index, char* t_string); // used to control leds only by the sketch, no matter what page @@ -150,6 +152,7 @@ uint32_t getLedStates(); // get GLOBAL_LED Data void getGlobalLed(uint8_t n, bmcStoreLed& t_item); +// see "advanced names and strings" documentation for length of char string void getGlobalLedName(uint8_t n, char* t_string); // used to control leds only by the sketch, no matter what page @@ -166,8 +169,10 @@ void getPwmLed(uint8_t n, bmcStoreLed& t_item); void getPwmLed(uint8_t t_page, uint8_t n, bmcStoreLed& t_item); +// see "advanced names and strings" documentation for length of char string void getPwmLedName(uint8_t n, char* t_string); +// see "advanced names and strings" documentation for length of char string void getPwmLedName(uint8_t t_page, uint8_t n, char* t_string); // used to control pwm leds only by the sketch, no matter what page @@ -184,8 +189,10 @@ void getPixel(uint8_t n, bmcStoreLed& t_item); void getPixel(uint8_t t_page, uint8_t n, bmcStoreLed& t_item); +// see "advanced names and strings" documentation for length of char string void getPixelName(uint8_t n, char* t_string); +// see "advanced names and strings" documentation for length of char string void getPixelName(uint8_t t_page, uint8_t n, char* t_string); // used to control pixels only by the sketch, no matter what page @@ -214,8 +221,10 @@ void getRgbPixel(uint8_t n, bmcStoreRgbLed& t_item); void getRgbPixel(uint8_t t_page, uint8_t n, bmcStoreRgbLed& t_item); +// see "advanced names and strings" documentation for length of char string void getRgbPixelName(uint8_t n, char* t_string); +// see "advanced names and strings" documentation for length of char string void getRgbPixelName(uint8_t t_page, uint8_t n, char* t_string); // used to control rgb pixels only by the sketch, no matter what page diff --git a/docs/pots.md b/docs/pots.md index 2dced40..1b6a6f2 100644 --- a/docs/pots.md +++ b/docs/pots.md @@ -21,9 +21,11 @@ void getPot(uint8_t n, bmcStorePot& t_item); void getPot(uint8_t t_page, uint8_t n, bmcStorePot& t_item); // get pot name on current page passing a pointer string +// see "advanced names and strings" documentation for length of char string void getPotName(uint8_t n, char* t_string); // get pot name on specified page passing a pointer string +// see "advanced names and strings" documentation for length of char string void getPotName(uint8_t t_page, uint8_t n, char* t_string); // start/stop pot calibration, pot calibration data is global diff --git a/docs/relays.md b/docs/relays.md index 533b419..fe4ea16 100644 --- a/docs/relays.md +++ b/docs/relays.md @@ -26,6 +26,32 @@ Relays have 1 event each and have the ability to be reverse polarity. ### API There are many API callbacks and functions available for use, these may not reflect the latest version +```c++ +// ******************* +// NON-LATCHING RELAYS +// ******************* + +// get NL RELAY Data +void getRelayNL(uint8_t n, bmcStoreGlobalRelay& t_item); + +// get NL RELAY Name Data +// see "advanced names and strings" documentation for length of char string +void getRelayNLName(uint8_t n, char* t_string); + +// *************** +// LATCHING RELAYS +// *************** + +// get L RELAY Data +void getRelayL(uint8_t t_index, bmcStoreGlobalRelay& t_item); + +// get L RELAY Name Data +// see "advanced names and strings" documentation for length of char string +void getRelayLName(uint8_t t_index, char* t_string); + +``` + + ##### FUNCTIONS ##### CALLBACKS diff --git a/library.properties b/library.properties index d1b05ef..e07a36c 100644 --- a/library.properties +++ b/library.properties @@ -1,5 +1,5 @@ name=BMC -version=1.6.0 +version=1.6.2 author=Nero Rox maintainer=Nero Rox sentence=Fully featured MIDI Controller Library with a Companion Editor App for 32-bit Teensy boards, Requires Teensyduino. diff --git a/src/BMC-Version.h b/src/BMC-Version.h index 387e673..b580f01 100644 --- a/src/BMC-Version.h +++ b/src/BMC-Version.h @@ -23,7 +23,7 @@ // BMC Version stored in EEPROM (for editor usage) #define BMC_VERSION_MAJ 1 #define BMC_VERSION_MIN 6 -#define BMC_VERSION_PATCH 0 +#define BMC_VERSION_PATCH 2 //16 bits unsigned, LSB byte is minor, MSB byte is major #define BMC_VERSION ((BMC_VERSION_MAJ<<8) | BMC_VERSION_MIN) diff --git a/src/hardware/BMC-Pixels.h b/src/hardware/BMC-Pixels.h index 8f3f19a..d22837c 100644 --- a/src/hardware/BMC-Pixels.h +++ b/src/hardware/BMC-Pixels.h @@ -32,6 +32,9 @@ #define BMC_PIXELS_FLAG_SHOW 0 #define BMC_PIXELS_FLAG_USE_DIM 1 #define BMC_PIXELS_FLAG_RAINBOW_CHANGED 2 +#define BMC_PIXELS_FLAG_RAINBOW_FADE_CHANGED 3 +// -------------------------------------- +#define BMC_PIXELS_RAINBOW_AMOUNT 25 // Default Data Trasmition order is RGB, most WS2812 however are GRB // I made this the default since the first NeoPixels I tried were the 5mm diffused @@ -120,6 +123,7 @@ class BMCPixels { void clockBeat(uint16_t speed){ #if BMC_MAX_PIXELS > 0 updateRainbowColor(60000/speed); + updateRainbowFadeColor(15000/speed); #else speed = 0; #endif @@ -179,7 +183,7 @@ class BMCPixels { color = getDefaultColor(n); #if BMC_MAX_PIXELS > 0 - } else if(color==BMC_COLOR_RAINBOW){ + } else if(color==BMC_COLOR_RAINBOW || color==BMC_COLOR_RAINBOW_FADE){ // only Pixels (not RGB) use rainbow color = rainbowCurrentColor; #endif @@ -227,6 +231,7 @@ class BMCPixels { if(flags.toggleIfTrue(BMC_PIXELS_FLAG_SHOW)){ pixels.show(); flags.off(BMC_PIXELS_FLAG_RAINBOW_CHANGED); + flags.off(BMC_PIXELS_FLAG_RAINBOW_FADE_CHANGED); } } @@ -260,7 +265,10 @@ class BMCPixels { } // this would be very complicated to do for RGB pixels so it's not used void setBrightness(uint8_t t_index, uint8_t t_brightness=127, uint8_t t_color=255){ - if(t_color==BMC_COLOR_RAINBOW || t_index >= BMC_MAX_PIXELS){ + if(t_color==BMC_COLOR_RAINBOW || + t_color==BMC_COLOR_RAINBOW_FADE || + t_index >= BMC_MAX_PIXELS + ){ return; } // we start by writting the new color to that pixel @@ -448,15 +456,21 @@ class BMCPixels { #if BMC_MAX_PIXELS > 0 // RAINBOW + uint8_t rainbowRGB[3] = {250, 0, 0}; + uint8_t rainbowTarget = 1; + bool rainbowUp = true; // in Rainbow mode the led uses a different color anytime you set the color // the rainbowCurrentColor variable is changed only when pixels.show() is called uint8_t rainbowCurrentColor = BMC_COLOR_RED; + uint8_t rainbowFadeCurrentColor = BMC_COLOR_RED; // time the rainbow to be triggered after 10ms elapsedMillis rainbowTimeout; + elapsedMillis rainbowFadeTimeout; void updateRainbowColor(uint16_t speed=500){ if(rainbowTimeout >= speed){ if(!flags.read(BMC_PIXELS_FLAG_RAINBOW_CHANGED)){ + rainbowCurrentColor++; // BMC_COLOR_RAINBOW is the highest index number // once we reach it we go back to the start of the colors @@ -472,6 +486,34 @@ class BMCPixels { flags.on(BMC_PIXELS_FLAG_RAINBOW_CHANGED); } } + void updateRainbowFadeColor(uint16_t speed=500){ + if(rainbowFadeTimeout >= speed){ + if(!flags.read(BMC_PIXELS_FLAG_RAINBOW_FADE_CHANGED)){ + bool cycleComplete = false; + rainbowFadeCurrentColor++; + if(rainbowFadeCurrentColor >= 15){ + rainbowFadeCurrentColor = 1; + } + if(rainbowUp){ + cycleComplete = (rainbowRGB[rainbowTarget] == 250); + if(!cycleComplete){ + rainbowRGB[rainbowTarget] += BMC_PIXELS_RAINBOW_AMOUNT; + } + } else { + cycleComplete = (rainbowRGB[rainbowTarget] < 10); + if(!cycleComplete){ + rainbowRGB[rainbowTarget] -= BMC_PIXELS_RAINBOW_AMOUNT; + } + } + if(cycleComplete){ + rainbowUp = !rainbowUp; + rainbowTarget = rainbowTarget==0 ? 2 : (rainbowTarget-1); + } + rainbowFadeTimeout = 0; + } + flags.on(BMC_PIXELS_FLAG_RAINBOW_FADE_CHANGED); + } + } #endif uint8_t getDimColor(uint8_t n){ uint8_t offset = (uint8_t) ((n>0) ? (n/2) : 0); @@ -521,6 +563,7 @@ class BMCPixels { } // hold the current color assigned to the pixel uint8_t cColor = getState(t_index); + uint8_t _t_color = t_color; if(t_color==255){ // if target color is 255 we use the last assigned color @@ -535,6 +578,11 @@ class BMCPixels { // if the target color BMC_COLOR_RAINBOW then we will go thru all colors t_color = rainbowCurrentColor; setDimColor(t_index, t_color); +#endif + } else if(t_color==BMC_COLOR_RAINBOW_FADE){ +#if BMC_MAX_PIXELS > 0 + t_color = rainbowFadeCurrentColor; + setDimColor(t_index, rainbowCurrentColor); #endif } @@ -569,12 +617,18 @@ class BMCPixels { show(); } } else { + // we are setting a color aka turning the pixel ON // we are going to check if the pixel if OFF or if the color is different // than the current color, in either case we want to update the pixel if(!bitRead(cColor,7) || (cColor&0x7F)!=t_color){ // convert the 4 bit color to the full rgb value - setPixelValue(t_index, BMCPixelColors::getRgbColor(t_color)); + if(_t_color==BMC_COLOR_RAINBOW_FADE){ + setPixelValue(t_index, (rainbowRGB[0] | (rainbowRGB[1]<<8) | (rainbowRGB[2]<<16))); + //setPixelValue(t_index, BMCPixelColors::getRgbColor(t_color)); + } else { + setPixelValue(t_index, BMCPixelColors::getRgbColor(t_color)); + } // set bit 7 to 0 // thats the bit that tells you if the led is on(1) or off(0) diff --git a/src/hardware/BMC-RelayNL.h b/src/hardware/BMC-RelayNL.h index 2331725..37bfadb 100644 --- a/src/hardware/BMC-RelayNL.h +++ b/src/hardware/BMC-RelayNL.h @@ -145,12 +145,12 @@ class BMCRelayNL { // RELAY has changed states // t_value = true (RELAY on position), false (RELAY off position) void write(bool t_value){ - #if !defined(BMC_FAST_MODE) +#if !defined(BMC_FAST_MODE) // ignore if RELAY was not enabled if(pin==255){ return; } - #endif +#endif // if new value is different than the current state we set it if(t_value == getState()){ return; diff --git a/src/storage/BMC-24LC256.h b/src/storage/BMC-24LC256.h index a6f33f1..0cbe460 100644 --- a/src/storage/BMC-24LC256.h +++ b/src/storage/BMC-24LC256.h @@ -22,11 +22,7 @@ * to not exceed the maximum address for the EEPROM. * * * * Library tested with: * - * Microchip 24AA02E48 (2k bit) * - * 24xx32 (32k bit, thanks to Richard M) * * Microchip 24LC256 (256k bit) * - * Microchip 24FC1026 (1M bit, thanks to Gabriele B on the Arduino forum) * - * ST Micro M24M02 (2M bit) * * * * Library will NOT work with Microchip 24xx1025 as its control byte does not * * conform to the following assumptions. * diff --git a/src/utility/BMC-ConfigCheck.h b/src/utility/BMC-ConfigCheck.h index 92219f1..c2e498c 100644 --- a/src/utility/BMC-ConfigCheck.h +++ b/src/utility/BMC-ConfigCheck.h @@ -842,6 +842,9 @@ #define BMC_ENCODER_BUTTON_DEBOUNCE_TIME 50 #endif + + + // BMC_MAX_LED_TEST_DELAY defines the delay between led's blinking when // they are tested by the editor or at launch, the idea is that at launch // the test of alls LED and PIXELS should not exceed more than 4 seconds. diff --git a/src/utility/BMC-Def.h b/src/utility/BMC-Def.h index 04c96bc..d8e5cfe 100644 --- a/src/utility/BMC-Def.h +++ b/src/utility/BMC-Def.h @@ -1276,14 +1276,15 @@ const char bmcAlphabet[26] = {'A','B','C','D','E','F','G','H','I','J','K','L','M #define BMC_COLOR_ORANGE 11 #define BMC_COLOR_TEAL 12 #define BMC_COLOR_CORAL 13 -#define BMC_COLOR_LIGHT_BLUE 14 -#define BMC_COLOR_RAINBOW 15 +#define BMC_COLOR_RAINBOW 14 +#define BMC_COLOR_RAINBOW_FADE 15 // PIXEL COLORS // kept here for old configs #define BMC_PIXEL_BLACK BMC_COLOR_BLACK #define BMC_PIXEL_RAINBOW BMC_COLOR_RAINBOW +#define BMC_PIXEL_RAINBOW_FADE BMC_COLOR_RAINBOW_FADE #define BMC_PIXEL_RED BMC_COLOR_RED #define BMC_PIXEL_GREEN BMC_COLOR_GREEN #define BMC_PIXEL_BLUE BMC_COLOR_BLUE @@ -1293,7 +1294,6 @@ const char bmcAlphabet[26] = {'A','B','C','D','E','F','G','H','I','J','K','L','M #define BMC_PIXEL_CYAN BMC_COLOR_CYAN #define BMC_PIXEL_PINK BMC_COLOR_PINK #define BMC_PIXEL_PURPLE BMC_COLOR_PURPLE -#define BMC_PIXEL_LIGHT_BLUE BMC_COLOR_LIGHT_BLUE #define BMC_PIXEL_ORANGE BMC_COLOR_ORANGE #define BMC_PIXEL_CORAL BMC_COLOR_CORAL #define BMC_PIXEL_TEAL BMC_COLOR_TEAL @@ -2345,5 +2345,6 @@ const char bmcAlphabet[26] = {'A','B','C','D','E','F','G','H','I','J','K','L','M #include "utility/BMC-Callbacks.h" #include "utility/BMC-Globals.h" #include "utility/SSD1306.h" +#include "utility/SSD1306_OLED.h" #endif diff --git a/src/utility/BMC-PixelColors.h b/src/utility/BMC-PixelColors.h index 577c73d..acdc1e0 100644 --- a/src/utility/BMC-PixelColors.h +++ b/src/utility/BMC-PixelColors.h @@ -44,7 +44,7 @@ #define BMC_COLOR_RGB_RED 0xFF0000 #endif #ifndef BMC_COLOR_RGB_GREEN - #define BMC_COLOR_RGB_GREEN 0x00CC00 + #define BMC_COLOR_RGB_GREEN 0x00FF00 #endif #ifndef BMC_COLOR_RGB_YELLOW #define BMC_COLOR_RGB_YELLOW 0xFFB200 @@ -53,10 +53,10 @@ #define BMC_COLOR_RGB_BLUE 0x0000FF #endif #ifndef BMC_COLOR_RGB_MAGENTA - #define BMC_COLOR_RGB_MAGENTA 0xFF004C + #define BMC_COLOR_RGB_MAGENTA 0xFF00FF #endif #ifndef BMC_COLOR_RGB_CYAN - #define BMC_COLOR_RGB_CYAN 0x00E5FF + #define BMC_COLOR_RGB_CYAN 0x00C8FF #endif #ifndef BMC_COLOR_RGB_WHITE #define BMC_COLOR_RGB_WHITE 0x999999 @@ -70,14 +70,11 @@ #ifndef BMC_COLOR_RGB_PURPLE #define BMC_COLOR_RGB_PURPLE 0x6619CC #endif -#ifndef BMC_COLOR_RGB_LIGHT_BLUE - #define BMC_COLOR_RGB_LIGHT_BLUE 0x007FCC -#endif #ifndef BMC_COLOR_RGB_ORANGE #define BMC_COLOR_RGB_ORANGE 0xFF3300 #endif #ifndef BMC_COLOR_RGB_TEAL - #define BMC_COLOR_RGB_TEAL 0x199999 + #define BMC_COLOR_RGB_TEAL 0x00FF7F #endif #ifndef BMC_COLOR_RGB_CORAL #define BMC_COLOR_RGB_CORAL 0xFF1919 @@ -85,6 +82,9 @@ #ifndef BMC_COLOR_RGB_RAINBOW #define BMC_COLOR_RGB_RAINBOW 0xFFFFFF #endif +#ifndef BMC_COLOR_RGB_RAINBOW_FADE + #define BMC_COLOR_RGB_RAINBOW_FADE 0xFFFFFE +#endif #define BMC_PIXEL_MULTIPLIER (BMC_PIXEL_MAX_BRIGHTNESS+1) @@ -152,12 +152,6 @@ #define BMC_PIXEL_DIM_R_PERCENT_PURPLE ((uint8_t)ceil( ((((BMC_COLOR_RGB_PURPLE)>>16)&0xFF)/(BMC_PIXEL_MAX_BRIGHTNESS+0.0)) * (BMC_PIXEL_DIM_BRIGHTNESS))) #define BMC_COLOR_RGB_DIM_PURPLE ( BMC_PIXEL_DIM_B_PERCENT_PURPLE | ((BMC_PIXEL_DIM_G_PERCENT_PURPLE) << 8) | ((BMC_PIXEL_DIM_R_PERCENT_PURPLE) << 16) ) #endif -#ifndef BMC_COLOR_RGB_DIM_LIGHT_BLUE - #define BMC_PIXEL_DIM_B_PERCENT_LIGHT_BLUE ((uint8_t)ceil( (((BMC_COLOR_RGB_LIGHT_BLUE)&0xFF) / (BMC_PIXEL_MAX_BRIGHTNESS+0.0)) * (BMC_PIXEL_DIM_BRIGHTNESS) )) - #define BMC_PIXEL_DIM_G_PERCENT_LIGHT_BLUE ((uint8_t)ceil( ((((BMC_COLOR_RGB_LIGHT_BLUE)>>8)&0xFF)/(BMC_PIXEL_MAX_BRIGHTNESS+0.0)) * (BMC_PIXEL_DIM_BRIGHTNESS))) - #define BMC_PIXEL_DIM_R_PERCENT_LIGHT_BLUE ((uint8_t)ceil( ((((BMC_COLOR_RGB_LIGHT_BLUE)>>16)&0xFF)/(BMC_PIXEL_MAX_BRIGHTNESS+0.0)) * (BMC_PIXEL_DIM_BRIGHTNESS))) - #define BMC_COLOR_RGB_DIM_LIGHT_BLUE ( BMC_PIXEL_DIM_B_PERCENT_LIGHT_BLUE | ((BMC_PIXEL_DIM_G_PERCENT_LIGHT_BLUE) << 8) | ((BMC_PIXEL_DIM_R_PERCENT_LIGHT_BLUE) << 16) ) -#endif #ifndef BMC_COLOR_RGB_DIM_ORANGE #define BMC_PIXEL_DIM_B_PERCENT_ORANGE ((uint8_t)ceil( (((BMC_COLOR_RGB_ORANGE)&0xFF) / (BMC_PIXEL_MAX_BRIGHTNESS+0.0)) * (BMC_PIXEL_DIM_BRIGHTNESS) )) #define BMC_PIXEL_DIM_G_PERCENT_ORANGE ((uint8_t)ceil( ((((BMC_COLOR_RGB_ORANGE)>>8)&0xFF)/(BMC_PIXEL_MAX_BRIGHTNESS+0.0)) * (BMC_PIXEL_DIM_BRIGHTNESS))) @@ -176,12 +170,19 @@ #define BMC_PIXEL_DIM_R_PERCENT_CORAL ((uint8_t)ceil( ((((BMC_COLOR_RGB_CORAL)>>16)&0xFF)/(BMC_PIXEL_MAX_BRIGHTNESS+0.0)) * (BMC_PIXEL_DIM_BRIGHTNESS))) #define BMC_COLOR_RGB_DIM_CORAL ( BMC_PIXEL_DIM_B_PERCENT_CORAL | ((BMC_PIXEL_DIM_G_PERCENT_CORAL) << 8) | ((BMC_PIXEL_DIM_R_PERCENT_CORAL) << 16) ) #endif +// for dim rainbow the leds will be red #ifndef BMC_COLOR_RGB_DIM_RAINBOW - #define BMC_PIXEL_DIM_B_PERCENT_RAINBOW ((uint8_t)ceil( (((BMC_COLOR_RGB_RAINBOW)&0xFF) / (BMC_PIXEL_MAX_BRIGHTNESS+0.0)) * (BMC_PIXEL_DIM_BRIGHTNESS) )) - #define BMC_PIXEL_DIM_G_PERCENT_RAINBOW ((uint8_t)ceil( ((((BMC_COLOR_RGB_RAINBOW)>>8)&0xFF)/(BMC_PIXEL_MAX_BRIGHTNESS+0.0)) * (BMC_PIXEL_DIM_BRIGHTNESS))) - #define BMC_PIXEL_DIM_R_PERCENT_RAINBOW ((uint8_t)ceil( ((((BMC_COLOR_RGB_RAINBOW)>>16)&0xFF)/(BMC_PIXEL_MAX_BRIGHTNESS+0.0)) * (BMC_PIXEL_DIM_BRIGHTNESS))) + #define BMC_PIXEL_DIM_B_PERCENT_RAINBOW ((uint8_t)ceil( (((BMC_COLOR_RGB_RED)&0xFF) / (BMC_PIXEL_MAX_BRIGHTNESS+0.0)) * (BMC_PIXEL_DIM_BRIGHTNESS) )) + #define BMC_PIXEL_DIM_G_PERCENT_RAINBOW ((uint8_t)ceil( ((((BMC_COLOR_RGB_RED)>>8)&0xFF)/(BMC_PIXEL_MAX_BRIGHTNESS+0.0)) * (BMC_PIXEL_DIM_BRIGHTNESS))) + #define BMC_PIXEL_DIM_R_PERCENT_RAINBOW ((uint8_t)ceil( ((((BMC_COLOR_RGB_RED)>>16)&0xFF)/(BMC_PIXEL_MAX_BRIGHTNESS+0.0)) * (BMC_PIXEL_DIM_BRIGHTNESS))) #define BMC_COLOR_RGB_DIM_RAINBOW ( BMC_PIXEL_DIM_B_PERCENT_RAINBOW | ((BMC_PIXEL_DIM_G_PERCENT_RAINBOW) << 8) | ((BMC_PIXEL_DIM_R_PERCENT_RAINBOW) << 16) ) #endif +#ifndef BMC_COLOR_RGB_DIM_RAINBOW_FADE + #define BMC_PIXEL_DIM_B_PERCENT_RAINBOW_FADE ((uint8_t)ceil( (((BMC_COLOR_RGB_RED)&0xFF) / (BMC_PIXEL_MAX_BRIGHTNESS+0.0)) * (BMC_PIXEL_DIM_BRIGHTNESS) )) + #define BMC_PIXEL_DIM_G_PERCENT_RAINBOW_FADE ((uint8_t)ceil( ((((BMC_COLOR_RGB_RED)>>8)&0xFF)/(BMC_PIXEL_MAX_BRIGHTNESS+0.0)) * (BMC_PIXEL_DIM_BRIGHTNESS))) + #define BMC_PIXEL_DIM_R_PERCENT_RAINBOW_FADE ((uint8_t)ceil( ((((BMC_COLOR_RGB_RED)>>16)&0xFF)/(BMC_PIXEL_MAX_BRIGHTNESS+0.0)) * (BMC_PIXEL_DIM_BRIGHTNESS))) + #define BMC_COLOR_RGB_DIM_RAINBOW_FADE ( BMC_PIXEL_DIM_B_PERCENT_RAINBOW_FADE | ((BMC_PIXEL_DIM_G_PERCENT_RAINBOW_FADE) << 8) | ((BMC_PIXEL_DIM_R_PERCENT_RAINBOW_FADE) << 16) ) +#endif class BMCPixelColors { @@ -201,11 +202,11 @@ class BMCPixelColors { case BMC_COLOR_LIME: return BMC_COLOR_RGB_LIME; case BMC_COLOR_PINK: return BMC_COLOR_RGB_PINK; case BMC_COLOR_PURPLE: return BMC_COLOR_RGB_PURPLE; - case BMC_COLOR_LIGHT_BLUE: return BMC_COLOR_RGB_LIGHT_BLUE; case BMC_COLOR_ORANGE: return BMC_COLOR_RGB_ORANGE; case BMC_COLOR_TEAL: return BMC_COLOR_RGB_TEAL; case BMC_COLOR_CORAL: return BMC_COLOR_RGB_CORAL; case BMC_COLOR_RAINBOW: return BMC_COLOR_RGB_RAINBOW; + case BMC_COLOR_RAINBOW_FADE: return BMC_COLOR_RGB_RAINBOW_FADE; } return BMC_COLOR_RGB_BLACK; } @@ -223,11 +224,11 @@ class BMCPixelColors { case BMC_COLOR_LIME: return BMC_COLOR_RGB_DIM_LIME; case BMC_COLOR_PINK: return BMC_COLOR_RGB_DIM_PINK; case BMC_COLOR_PURPLE: return BMC_COLOR_RGB_DIM_PURPLE; - case BMC_COLOR_LIGHT_BLUE: return BMC_COLOR_RGB_DIM_LIGHT_BLUE; case BMC_COLOR_ORANGE: return BMC_COLOR_RGB_DIM_ORANGE; case BMC_COLOR_TEAL: return BMC_COLOR_RGB_DIM_TEAL; case BMC_COLOR_CORAL: return BMC_COLOR_RGB_DIM_CORAL; case BMC_COLOR_RAINBOW: return BMC_COLOR_RGB_DIM_RAINBOW; + case BMC_COLOR_RAINBOW_FADE: return BMC_COLOR_RGB_DIM_RAINBOW_FADE; } #endif // default color would always be dimmed RED diff --git a/src/utility/SSD1306_OLED.h b/src/utility/SSD1306_OLED.h new file mode 100644 index 0000000..274ac94 --- /dev/null +++ b/src/utility/SSD1306_OLED.h @@ -0,0 +1,127 @@ +/* + This is a wrapper for the Adafruit SSD1306 library + https://github.com/adafruit/Adafruit_SSD1306 + + it handles up to 2 lines of text, it centers the text and keeps it as large + as possible, you can use this if you want to use an OLED display to show + the name of a button/pot/encoder etc. +*/ +#ifndef BMC_OLED_H_ +#define BMC_OLED_H_ + +#ifdef BMC_USE_OLED +#include "SSD1306.h" + +class BMC_OLED { + public: + uint8_t w = 0; + uint8_t h = 0; + BMC_SSD1306 display; + BMC_OLED(uint8_t _w, uint8_t _h):display(_w, _h){ + w = _w; + h = _h; + } + bool begin(uint8_t switchvcc=BMC_SSD1306_SWITCHCAPVCC, uint8_t i2caddr=0){ + if(!display.begin(switchvcc, i2caddr)){ + return false; + } + display.setTextWrap(false); + display.setTextSize(2); + display.setTextColor(BMC_SSD1306_WHITE); + clear(); + return true; + } + void setRotation(uint8_t r){ + display.setRotation(r); + } + void clear(){ + display.clearDisplay(); + display.display(); + } + void print(const char * str){ + char c[strlen(str)]; + strncpy(c, str, strlen(str)); + print(c); + } + void print(char * str){ + display.clearDisplay(); + //display.drawRect(0, 0, 128, 64, BMC_SSD1306_WHITE); + //display.drawLine(0, 32, 128, 32, BMC_SSD1306_WHITE); + display.setTextColor(BMC_SSD1306_WHITE); + uint8_t spaceIndex = 0; + uint8_t lines = 1; + int len = strlen(str); + for(uint8_t i = 0 ; i < len ; i++){ + if(str[i]==' '){ + spaceIndex = i; + break; + } + } + if(spaceIndex > 0 && len > 7){ + lines = 2; + } else { + if(len <= 10 && spaceIndex < 0){ + lines = 1; + } else if(len > 7 && len <= 10 && spaceIndex > 0){ + lines = 2; + } else if(len > 10 && len <= 12){ + lines = 1; + } else if(len > 12){ + lines = spaceIndex > 0 ? 2 : 3; + } + } + if(lines==3){ + if(len>20){ + renderLine(str, 0, 2, 0, 10, h/2); + renderLine(str, 1, 2, 10, len, h/2); + } else { + renderLine(str, 0, 2, 0, len/2, h/2); + renderLine(str, 1, 2, len/2, len, h/2); + } + } else if(lines==2){ + renderLine(str, 0, 2, 0, spaceIndex, h/2); + renderLine(str, 1, 2, (spaceIndex+1), len, h/2); + } else { + renderLine(str, 0, 2, 0, len, h); + } + display.display(); + } + private: + void renderLine(const char * str, uint8_t lineNumber, uint8_t totalLines, uint8_t start, uint8_t end, uint8_t height){ + uint8_t font = 2; + uint8_t len = end - start; + len = constrain(len, 0, 10); + if(len <= 5){ + font = totalLines == 1 ? 4 : 3; + } else if(len > 5 && len < 8){ + font = 3; + } else if(len > 7){ + font = 2; + } + + uint8_t x = (w - (((font * 6) * len) - font)) / 2; + uint8_t y = ceil((height - (font * 7)) / 2.0) + (height * lineNumber); + + if(totalLines==2){ + if(lineNumber==0){ + y += font; + } else { + y -= font; + } + } + + display.setTextSize(font); + display.setCursor(x, y); + + for(uint8_t i = start, e = 0 ; e < len ; i++, e++){ + display.print(str[i]); + if(e >= len){ + break; + } + } + } +}; + +#endif + +#endif