Skip to content

Adding object oriented syntactical sugar #13

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Nov 8, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 8 additions & 9 deletions examples/Example-09_CustomOLED/Example-09_CustomOLED.ino
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@

QwiicCustomOLED myOLED;


void setup()
{
delay(1000);
Expand All @@ -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
Expand Down
12 changes: 10 additions & 2 deletions src/SparkFun_Qwiic_OLED.h
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ typedef QwBitmap QwiicBitmap;

template <typename SSD1306DeviceType>
class QwiicOLEDBaseClass : public Print { // NOTE: implementing Arduino Print
public:
protected:
// our device driver
SSD1306DeviceType m_device;
private:
Expand Down Expand Up @@ -840,5 +840,13 @@ class Qwiic1in3OLED : public QwiicOLEDBaseClass<QwOLED1in3> {
};

class QwiicCustomOLED : public QwiicOLEDBaseClass<QwOLEDCustom> {
// 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); }
};
44 changes: 28 additions & 16 deletions src/qwiic_oled_custom.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
};