Serial Wombat Arduino Library
Loading...
Searching...
No Matches
SerialWombatCharlieplex Class Reference

A class representing a Serial Wombat Charlieplexed LED display. More...

#include <SerialWombatCharlieplex.h>

Inheritance diagram for SerialWombatCharlieplex:
Collaboration diagram for SerialWombatCharlieplex:

Public Types

enum  displayMode_t { DISPLAY_MODE_BITMAP = 0 , DISPLAY_MODE_PUBLIC_DATA_BITMAP = 1 , DISPLAY_MODE_SCALED_SINGLE_LED = 2 , DISPLAY_MODE_SCALED_BARGRAPH = 3 }
 
- Public Types inherited from SerialWombatAbstractScaledOutput
enum  Period {
  PERIOD_1mS = 0 , PERIOD_2mS = 1 , PERIOD_4mS = 2 , PERIOD_8mS = 3 ,
  PERIOD_16mS = 4 , PERIOD_32mS = 5 , PERIOD_64mS = 6 , PERIOD_128mS = 7 ,
  PERIOD_256mS = 8 , PERIOD_512mS = 9 , PERIOD_1024mS = 10
}
 
enum  RampMode { RAMP_MODE_BOTH = 0 , RAMP_MODE_INCREMENT = 1 , RAMP_MODE_DECREMENT = 2 }
 

Public Member Functions

 SerialWombatCharlieplex (SerialWombatChip &serialWombat)
 Constructor for the SerialWombatCharlieplex class.
 
int16_t begin (uint8_t pin0, uint8_t pin1, uint8_t pin2, uint8_t pin3, uint8_t pin4, uint8_t pin5=UNUSED_PIN, uint8_t pin6=UNUSED_PIN, uint8_t pin7=UNUSED_PIN, displayMode_t displayMode=DISPLAY_MODE_BITMAP, uint8_t scanPeriod_mS=0)
 Initialize a Charlieplexed LED display.
 
int16_t writeLEDArray (const uint8_t ledArray[BITMAP_BYTES])
 Write the complete LED bitmap from an array of bytes.
 
int16_t setLEDs (uint8_t led0, uint8_t led1=UNUSED_LED, uint8_t led2=UNUSED_LED, uint8_t led3=UNUSED_LED, uint8_t led4=UNUSED_LED)
 Set up to five logical LEDs in bitmap display mode.
 
int16_t setLEDs (const uint8_t ledIndexes[], uint8_t count)
 Set up to five logical LEDs from an array.
 
int16_t clearLEDs (uint8_t led0, uint8_t led1=UNUSED_LED, uint8_t led2=UNUSED_LED, uint8_t led3=UNUSED_LED, uint8_t led4=UNUSED_LED)
 Clear up to five logical LEDs in bitmap display mode.
 
int16_t clearLEDs (const uint8_t ledIndexes[], uint8_t count)
 Clear up to five logical LEDs from an array.
 
int16_t clearLEDs ()
 Turn off all LEDs in bitmap display mode.
 
int16_t writeLookupEntries (uint8_t firstLEDIndex, uint8_t entry0, uint8_t entry1, uint8_t entry2, uint8_t entry3)
 Write four consecutive logical LED lookup entries.
 
int16_t writeLookupTable (const uint8_t lookupTable[MAX_LEDS])
 Write all 56 logical LED lookup entries.
 
uint8_t pin ()
 Fulfills a virtual function requirement of SerialWombatAbstractScaledOutput.
 
uint8_t swPinModeNumber ()
 Fulfills a virtual function requirement of SerialWombatAbstractScaledOutput.
 
- Public Member Functions inherited from SerialWombatPin
 SerialWombatPin (SerialWombatChip &serialWombatChip)
 Instantiates a Serial Wombat Pin.
 
 SerialWombatPin (SerialWombatChip &serialWombatChip, uint8_t pin)
 Instantiates a Serial Wombat Pin.
 
uint16_t readPublicData ()
 Read the 16 Bit public data associated with this pin.
 
void pinMode (uint8_t mode, bool pullDown=false, bool openDrain=false)
 Set pin to INPUT or OUTPUT, with options for pull Ups and open Drain settings.
 
void digitalWrite (uint8_t val)
 Set output pin High or Low.
 
int digitalRead ()
 Reads the state of the Pin.
 
uint16_t writePublicData (uint16_t value)
 Write a 16 bit value to this pin.
 
uint8_t pin ()
 Returns the current SW pin number. Used primarily for virtual calls by derived classes.
 
uint8_t swPinModeNumber ()
 Returns the Mode number. Used primarily by derived classes to populate packet data.
 
int16_t initPacketNoResponse (uint8_t packetNumber, uint8_t param0=0x55, uint8_t param1=0x55, uint8_t param2=0x55, uint8_t param3=0x55, uint8_t param4=0x55)
 
int16_t initPacketNoResponse (uint8_t packetNumber, uint16_t param0=0x55, uint8_t param1=0x55, uint8_t param2=0x55, uint8_t param3=0x55)
 
int16_t initPacketNoResponse (uint8_t packetNumber, uint16_t param0, uint16_t param1, uint8_t param2=0x55)
 
int16_t disable ()
 Disables the pin mode (if applicable)
 
int16_t enablePullup (bool enabled)
 Enables the weak pull up on a pin. Implemented on SW18AB and SW8B only.
 
int16_t enablePulldown (bool enabled)
 Enables the weak pull down on a pin. Implemented on SW18AB and SW8B only.
 
int16_t enableOpenDrain (bool enabled)
 Enables open drain mode on a pin. Implemented on SW18AB and SW8B only.
 
int16_t forceDMA (bool enabled)
 Forces use of DMA instead of hardware timing resources on SW18AB.
 
void setPinNumberForTesting (uint8_t pin)
 A function designed for testing only. May have unpredictable results if used in real time. Not intended for general use.
 
- Public Member Functions inherited from SerialWombatAbstractScaledOutput
 SerialWombatAbstractScaledOutput (SerialWombatChip &sw)
 Constructor for the SerialWombatAbstractScaledOutput Class.
 
int16_t writeTimeout (uint16_t timeout_mS, uint16_t timeoutOutputValue)
 Enable a timeout value which will cause the output to go to a default value if not updated.
 
int16_t writeScalingEnabled (bool enabled, uint8_t sourcePin)
 Enable scaling and set which pin or public data is used as the input source.
 
int16_t writeInputScaling (uint16_t inputMin, uint16_t inputMax)
 Scale incoming values to a range of 0 to 65535.
 
int16_t writeOutputScaling (uint16_t outputMin, uint16_t outputMax)
 Reduces the output range from 0 to 65535 to user specified range.
 
int16_t writeScalingInvertedInput (bool inverted)
 if enabled subtract the input value from 65535 before doing any other processing.
 
int16_t writeScalingTargetValue (uint16_t target)
 The target input value for PID control.
 
int16_t writeRateControl (Period samplePeriod, uint16_t maximumChangecounts, uint16_t maximumDecrementCounts=0)
 Controls how fast an ouput can change in counts.
 
int16_t write1stOrderFiltering (Period samplePeriod, uint16_t filterConstant)
 Controls how fast an ouput can change based on filtering.
 
int16_t writeHysteresis (uint16_t lowLimit, uint16_t lowOutputValue, uint16_t highLimit, uint16_t highOutputValue, uint16_t initialOutputValue)
 Controls the output based on hystersis control.
 
int16_t writeRamp (uint16_t slowIncrement, uint16_t incrementThreshold, uint16_t fastIncrement, Period samplePeriod, RampMode rampMode)
 Configure the scaled output block into Ramp control mode.
 
int16_t writePID (uint16_t kp, uint16_t ki, uint16_t kd, uint16_t target, Period samplePeriod, uint8_t targetPin=255, bool biDirectional=false)
 Configure the scaled output block into PID control mode.
 
uint16_t readLastOutputValue ()
 Request Last Output Value.
 
int16_t writeScalingTargetValueResetIntegrator (uint16_t target)
 
int32_t PIDGetLastError ()
 
int32_t PIDGetLastIntegrator ()
 
int32_t PIDGetLastIntegratorEffort ()
 
int32_t PIDGetLastProportionalEffort ()
 
int32_t PIDGetLastDerivativeEffort ()
 
int32_t PIDGetLastEffort ()
 
uint16_t ReadLastTarget ()
 
int16_t Enable2DLookupOutputScaling (uint16_t IndexInUserMemory)
 Set Up 2D Lookup Output Scaling.
 

Static Public Member Functions

static uint8_t encodePinPair (uint8_t highPinIndex, uint8_t lowPinIndex)
 Encode a logical high pin and logical low pin into one lookup byte.
 

Static Public Attributes

static const uint8_t MAX_PINS = 8
 
static const uint8_t MAX_LEDS = 56
 
static const uint8_t BITMAP_BYTES = 7
 
static const uint8_t UNUSED_PIN = 0xFF
 
static const uint8_t UNUSED_LED = 0xFF
 

Additional Inherited Members

- Protected Attributes inherited from SerialWombatPin
uint8_t _pin = 255
 
SerialWombatChip_sw
 
uint8_t _pinMode = 0
 

Detailed Description

A class representing a Serial Wombat Charlieplexed LED display.

The Charlieplex pin mode uses between 2 and 8 Serial Wombat pins to control up to N * (N - 1) LEDs, for a maximum of 56 LEDs with 8 pins. One LED is driven during each approximately 1 ms Serial Wombat execution frame.

The first pin in the pins array is the controlling pin. Its public data is used by display modes that consume public data. The second pin is also used by the firmware to store the customizable 56-byte logical LED lookup table.

Each lookup-table byte contains two logical pin indexes:

  • Bits 7:4: logical pin index driven high
  • Bits 3:0: logical pin index driven low

The class inherits SerialWombatAbstractScaledOutput. Scaled-output functions are useful with DISPLAY_MODE_SCALED_SINGLE_LED and DISPLAY_MODE_SCALED_BARGRAPH.

Definition at line 52 of file SerialWombatCharlieplex.h.

Member Enumeration Documentation

◆ displayMode_t

Enumerator
DISPLAY_MODE_BITMAP 

Seven-byte protocol bitmap controls up to 56 LEDs.

DISPLAY_MODE_PUBLIC_DATA_BITMAP 

Controlling pin public data controls LEDs 0 through 15 as a bitfield.

DISPLAY_MODE_SCALED_SINGLE_LED 

Scaled-output value selects one logical LED index.

DISPLAY_MODE_SCALED_BARGRAPH 

Scaled-output value lights LEDs 0 through the selected index.

Definition at line 55 of file SerialWombatCharlieplex.h.

Constructor & Destructor Documentation

◆ SerialWombatCharlieplex()

SerialWombatCharlieplex::SerialWombatCharlieplex ( SerialWombatChip & serialWombat)
inline

Constructor for the SerialWombatCharlieplex class.

Parameters
serialWombatSerial Wombat chip on which the pin mode will run.

Definition at line 73 of file SerialWombatCharlieplex.h.

Member Function Documentation

◆ begin()

int16_t SerialWombatCharlieplex::begin ( uint8_t pin0,
uint8_t pin1,
uint8_t pin2,
uint8_t pin3,
uint8_t pin4,
uint8_t pin5 = UNUSED_PIN,
uint8_t pin6 = UNUSED_PIN,
uint8_t pin7 = UNUSED_PIN,
displayMode_t displayMode = DISPLAY_MODE_BITMAP,
uint8_t scanPeriod_mS = 0 )
inline

Initialize a Charlieplexed LED display.

Parameters
pin0First physical Serial Wombat pin. This is the controlling pin.
pin1Second physical Serial Wombat pin. The firmware uses this pin's pin memory to store the customizable logical LED lookup table.
pin2Third physical Serial Wombat pin, or UNUSED_PIN.
pin3Fourth physical Serial Wombat pin, or UNUSED_PIN.
pin4Fifth physical Serial Wombat pin, or UNUSED_PIN.
pin5Sixth physical Serial Wombat pin, or UNUSED_PIN. Defaults to UNUSED_PIN.
pin6Seventh physical Serial Wombat pin, or UNUSED_PIN. Defaults to UNUSED_PIN.
pin7Eighth physical Serial Wombat pin, or UNUSED_PIN. Defaults to UNUSED_PIN.
displayModeSelects bitmap, public-data bitmap, single-LED, or bargraph operation.
scanPeriod_mSMinimum number of approximately 1 ms execution frames between the starts of consecutive scans. Zero adds no blank padding. The documented useful range is 0 through 56.
Returns
0 or a positive value if successful, otherwise a negative error code.

The number of Charlieplex pins is calculated by counting pin parameters from pin0 through the first UNUSED_PIN value. Pin parameters after the first UNUSED_PIN are ignored by the firmware.

Definition at line 106 of file SerialWombatCharlieplex.h.

◆ clearLEDs() [1/3]

int16_t SerialWombatCharlieplex::clearLEDs ( )
inline

Turn off all LEDs in bitmap display mode.

Returns
0 or a positive value if successful, otherwise a negative error code.

Definition at line 302 of file SerialWombatCharlieplex.h.

◆ clearLEDs() [2/3]

int16_t SerialWombatCharlieplex::clearLEDs ( const uint8_t ledIndexes[],
uint8_t count )
inline

Clear up to five logical LEDs from an array.

Parameters
ledIndexesArray containing count logical LED indexes.
countNumber of entries to send. Valid range is 0 through 5.
Returns
0 or a positive value if successful, otherwise a negative error code.

Definition at line 289 of file SerialWombatCharlieplex.h.

◆ clearLEDs() [3/3]

int16_t SerialWombatCharlieplex::clearLEDs ( uint8_t led0,
uint8_t led1 = UNUSED_LED,
uint8_t led2 = UNUSED_LED,
uint8_t led3 = UNUSED_LED,
uint8_t led4 = UNUSED_LED )
inline

Clear up to five logical LEDs in bitmap display mode.

Each argument is a logical LED index from 0 through 55. Use UNUSED_LED for an unused argument. The firmware modifies its LED bitmap directly; no host-side bitmap copy is maintained.

Parameters
led0First logical LED index to clear.
led1Second logical LED index, or UNUSED_LED.
led2Third logical LED index, or UNUSED_LED.
led3Fourth logical LED index, or UNUSED_LED.
led4Fifth logical LED index, or UNUSED_LED.
Returns
0 or a positive value if successful, otherwise a negative error code.

Definition at line 270 of file SerialWombatCharlieplex.h.

◆ encodePinPair()

static uint8_t SerialWombatCharlieplex::encodePinPair ( uint8_t highPinIndex,
uint8_t lowPinIndex )
inlinestatic

Encode a logical high pin and logical low pin into one lookup byte.

Parameters
highPinIndexLogical Charlieplex pin index driven high.
lowPinIndexLogical Charlieplex pin index driven low.
Returns
Encoded lookup-table byte.

Definition at line 375 of file SerialWombatCharlieplex.h.

◆ pin()

uint8_t SerialWombatCharlieplex::pin ( )
inlinevirtual

Fulfills a virtual function requirement of SerialWombatAbstractScaledOutput.

Returns
Current controlling pin number.

Implements SerialWombatAbstractScaledOutput.

Definition at line 384 of file SerialWombatCharlieplex.h.

◆ setLEDs() [1/2]

int16_t SerialWombatCharlieplex::setLEDs ( const uint8_t ledIndexes[],
uint8_t count )
inline

Set up to five logical LEDs from an array.

Parameters
ledIndexesArray containing count logical LED indexes.
countNumber of entries to send. Valid range is 0 through 5.
Returns
0 or a positive value if successful, otherwise a negative error code.

Definition at line 247 of file SerialWombatCharlieplex.h.

◆ setLEDs() [2/2]

int16_t SerialWombatCharlieplex::setLEDs ( uint8_t led0,
uint8_t led1 = UNUSED_LED,
uint8_t led2 = UNUSED_LED,
uint8_t led3 = UNUSED_LED,
uint8_t led4 = UNUSED_LED )
inline

Set up to five logical LEDs in bitmap display mode.

Each argument is a logical LED index from 0 through 55. Use UNUSED_LED for an unused argument. The firmware modifies its LED bitmap directly; no host-side bitmap copy is maintained.

Parameters
led0First logical LED index to set.
led1Second logical LED index, or UNUSED_LED.
led2Third logical LED index, or UNUSED_LED.
led3Fourth logical LED index, or UNUSED_LED.
led4Fifth logical LED index, or UNUSED_LED.
Returns
0 or a positive value if successful, otherwise a negative error code.

Definition at line 228 of file SerialWombatCharlieplex.h.

◆ swPinModeNumber()

uint8_t SerialWombatCharlieplex::swPinModeNumber ( )
inlinevirtual

Fulfills a virtual function requirement of SerialWombatAbstractScaledOutput.

Returns
Current pin mode number.

Implements SerialWombatAbstractScaledOutput.

Definition at line 393 of file SerialWombatCharlieplex.h.

◆ writeLEDArray()

int16_t SerialWombatCharlieplex::writeLEDArray ( const uint8_t ledArray[BITMAP_BYTES])
inline

Write the complete LED bitmap from an array of bytes.

Parameters
ledArrayArray of seven bytes in little-endian bit order. Bit 0 of byte 0 controls logical LED 0; bit 7 of byte 6 controls logical LED 55.
Returns
0 or a positive value if successful, otherwise a negative error code.

Definition at line 180 of file SerialWombatCharlieplex.h.

◆ writeLookupEntries()

int16_t SerialWombatCharlieplex::writeLookupEntries ( uint8_t firstLEDIndex,
uint8_t entry0,
uint8_t entry1,
uint8_t entry2,
uint8_t entry3 )
inline

Write four consecutive logical LED lookup entries.

Each entry is encoded as high logical pin index in bits 7:4 and low logical pin index in bits 3:0. The firmware writes four entries per command.

Parameters
firstLEDIndexLogical LED index for entry0.
entry0Encoded mapping for firstLEDIndex.
entry1Encoded mapping for firstLEDIndex + 1.
entry2Encoded mapping for firstLEDIndex + 2.
entry3Encoded mapping for firstLEDIndex + 3.
Returns
0 or a positive value if successful, otherwise a negative error code.

Definition at line 322 of file SerialWombatCharlieplex.h.

◆ writeLookupTable()

int16_t SerialWombatCharlieplex::writeLookupTable ( const uint8_t lookupTable[MAX_LEDS])
inline

Write all 56 logical LED lookup entries.

Parameters
lookupTableArray of 56 encoded high/low logical pin pairs.
Returns
0 or a positive value if successful, otherwise a negative error code.

Definition at line 348 of file SerialWombatCharlieplex.h.

Member Data Documentation

◆ BITMAP_BYTES

const uint8_t SerialWombatCharlieplex::BITMAP_BYTES = 7
static

Definition at line 65 of file SerialWombatCharlieplex.h.

◆ MAX_LEDS

const uint8_t SerialWombatCharlieplex::MAX_LEDS = 56
static

Definition at line 64 of file SerialWombatCharlieplex.h.

◆ MAX_PINS

const uint8_t SerialWombatCharlieplex::MAX_PINS = 8
static

Definition at line 63 of file SerialWombatCharlieplex.h.

◆ UNUSED_LED

const uint8_t SerialWombatCharlieplex::UNUSED_LED = 0xFF
static

Definition at line 67 of file SerialWombatCharlieplex.h.

◆ UNUSED_PIN

const uint8_t SerialWombatCharlieplex::UNUSED_PIN = 0xFF
static

Definition at line 66 of file SerialWombatCharlieplex.h.