diff --git a/examples/Example-09_CustomOLED/Example-09_CustomOLED.ino b/examples/Example-09_CustomOLED/Example-09_CustomOLED.ino index e795152..c101586 100644 --- a/examples/Example-09_CustomOLED/Example-09_CustomOLED.ino +++ b/examples/Example-09_CustomOLED/Example-09_CustomOLED.ino @@ -28,7 +28,6 @@ QwiicCustomOLED myOLED; - void setup() { delay(1000); @@ -40,14 +39,14 @@ void setup() // If desired, we can customize the OLED before we begin it. // Otherwise it will default to 128x64 (1.3" OLED). - myOLED.m_device.xOffset = 0; // Set the active area X offset. For the Micro 64x48, set this to 2 - myOLED.m_device.yOffset = 0; // Set the active area Y offset - myOLED.m_device.displayWidth = 128; // Set the active area width - myOLED.m_device.displayHeight = 64; // Set the active area height - myOLED.m_device.pinConfig = 0x12; // Set COM Pins Hardware Configuration (DAh) - myOLED.m_device.preCharge = 0xF1; // Set Pre-charge Period (D9h) - myOLED.m_device.vcomDeselect = 0x40; // Set VCOMH Deselect Level (DBh) - myOLED.m_device.contrast = 0xCF; // Set Contrast Control for BANK0 (81h) + myOLED.setXOffset(0); // Set the active area X offset. For the Micro 64x48, set this to 2 + myOLED.setYOffset(0); // Set the active area Y offset + myOLED.setDisplayWidth(128); // Set the active area width. For the Micro 64x48, set this to 64 + myOLED.setDisplayHeight(64); // Set the active area height. For the Micro 64x48, set this to 48 + myOLED.setPinConfig(0x12); // Set COM Pins Hardware Configuration (DAh) + myOLED.setPreCharge(0xF1); // Set Pre-charge Period (D9h) + myOLED.setVcomDeselect(0x40); // Set VCOMH Deselect Level (DBh) + myOLED.setContrast(0xCF); // Set Contrast Control for BANK0 (81h). For the Micro 64x48, set this to 0x8F // Initalize the OLED device and related graphics system if (myOLED.begin(Wire, 0x3D) == false) // The TwoWire port and I2C address are set here diff --git a/src/SparkFun_Qwiic_OLED.h b/src/SparkFun_Qwiic_OLED.h index dc1c99d..3c75193 100644 --- a/src/SparkFun_Qwiic_OLED.h +++ b/src/SparkFun_Qwiic_OLED.h @@ -85,7 +85,7 @@ typedef QwBitmap QwiicBitmap; template class QwiicOLEDBaseClass : public Print { // NOTE: implementing Arduino Print -public: +protected: // our device driver SSD1306DeviceType m_device; private: @@ -840,5 +840,13 @@ class Qwiic1in3OLED : public QwiicOLEDBaseClass { }; class QwiicCustomOLED : public QwiicOLEDBaseClass { - // nothing here - see above +public: + void setXOffset(uint8_t xOffset){ m_device.setXOffset(xOffset); } + void setYOffset(uint8_t yOffset){ m_device.setYOffset(yOffset); } + void setDisplayWidth(uint8_t displayWidth){ m_device.setDisplayWidth(displayWidth); } + void setDisplayHeight(uint8_t displayHeight){ m_device.setDisplayHeight(displayHeight); } + void setPinConfig(uint8_t pinConfig){ m_device.setPinConfig(pinConfig); } + void setPreCharge(uint8_t preCharge){ m_device.setPreCharge(preCharge); } + void setVcomDeselect(uint8_t vcomDeselect){ m_device.setVcomDeselect(vcomDeselect); } + void setContrast(uint8_t contrast){ m_device.setContrast(contrast); } }; diff --git a/src/qwiic_oled_custom.h b/src/qwiic_oled_custom.h index 0d665ff..fb508df 100644 --- a/src/qwiic_oled_custom.h +++ b/src/qwiic_oled_custom.h @@ -81,38 +81,50 @@ class QwOLEDCustom : public QwGrSSD1306 { ~QwOLEDCustom() { if (m_graphicsBuffer != nullptr) + { delete[] m_graphicsBuffer; + m_graphicsBuffer = nullptr; + } }; // set up the specific device settings bool init(void) { - setViewport(xOffset, yOffset, displayWidth, displayHeight); + this->QwGrSSD1306::setViewport(m_xOffset, m_yOffset, m_displayWidth, m_displayHeight); - setCommPins(pinConfig); - setPreCharge(preCharge); - setVcomDeselect(vcomDeselect); - setContrast(contrast); + this->QwGrSSD1306::setCommPins(m_pinConfig); + this->QwGrSSD1306::setPreCharge(m_preCharge); + this->QwGrSSD1306::setVcomDeselect(m_vcomDeselect); + this->QwGrSSD1306::setContrast(m_contrast); if (m_graphicsBuffer != nullptr) delete[] m_graphicsBuffer; - m_graphicsBuffer = new uint8_t[(uint16_t)displayWidth * (uint16_t)displayHeight / 8]; - setBuffer(m_graphicsBuffer); // The buffer to use + m_graphicsBuffer = new uint8_t[(uint16_t)m_displayWidth * (uint16_t)m_displayHeight / 8]; + this->QwGrSSD1306::setBuffer(m_graphicsBuffer); // The buffer to use // Call the super class to do all the work return this->QwGrSSD1306::init(); }; - uint8_t xOffset = kOLEDCustomDefaultXOffset; - uint8_t yOffset = kOLEDCustomDefaultYOffset; - uint8_t displayWidth = kOLEDCustomDefaultWidth; - uint8_t displayHeight = kOLEDCustomDefaultHeight; - uint8_t pinConfig = kOLEDCustomDefaultPinConfig; - uint8_t preCharge = kOLEDCustomDefaultPreCharge; - uint8_t vcomDeselect = kOLEDCustomDefaultVCOM; - uint8_t contrast = kOLEDCustomDefaultContrast; + void setXOffset(uint8_t xOffset){ m_xOffset = xOffset; } + void setYOffset(uint8_t yOffset){ m_yOffset = yOffset; } + void setDisplayWidth(uint8_t displayWidth){ m_displayWidth = displayWidth; } + void setDisplayHeight(uint8_t displayHeight){ m_displayHeight = displayHeight; } + void setPinConfig(uint8_t pinConfig){ m_pinConfig = pinConfig; } + void setPreCharge(uint8_t preCharge){ m_preCharge = preCharge; } + void setVcomDeselect(uint8_t vcomDeselect){ m_vcomDeselect = vcomDeselect; } + void setContrast(uint8_t contrast){ m_contrast = contrast; } + +private: + uint8_t m_xOffset = kOLEDCustomDefaultXOffset; + uint8_t m_yOffset = kOLEDCustomDefaultYOffset; + uint8_t m_displayWidth = kOLEDCustomDefaultWidth; + uint8_t m_displayHeight = kOLEDCustomDefaultHeight; + uint8_t m_pinConfig = kOLEDCustomDefaultPinConfig; + uint8_t m_preCharge = kOLEDCustomDefaultPreCharge; + uint8_t m_vcomDeselect = kOLEDCustomDefaultVCOM; + uint8_t m_contrast = kOLEDCustomDefaultContrast; -protected: // Graphics buffer for this device. uint8_t *m_graphicsBuffer = nullptr; }; \ No newline at end of file