C++ API reference

C++ Classes

Compass

The id-4001’s compass uses 16 LEDs in a circle to display wind direction

class Compass

Compass class used to manipulate the id-4001 compass.

Author

Joe (joe.sedutto@silvertech.com)

Public Functions

Compass(byte _WINDA_PIN, byte _WINDB_PIN, byte _WINDC_PIN, byte _WINDD_PIN)

Construct a new Compass object.

Parameters:
  • _WINDA_PIN – Wind “A” pin.

  • _WINDB_PIN – Wind “B” pin.

  • _WINDC_PIN – Wind “C” pin.

  • _WINDD_PIN – Wind “D” pin.

void setHeading(int angle)

Set the output heading.

Parameters:

angle – In degrees, 0-360

void iterate(int angle)

Like Display’s iterate function, this method expects you to do the scheduling on your own.

void clearStats()

Simple method to clear/reset all running stats.

Private Members

int windDirAvg[compassTrail + 1]

This is neat, it stores the last 10 wind directions to avg them.

Display

The id-4001’s display is made from many 8 segment indicators, a few special indicators and some LEDs

class Display

Display object used to manipulate the display.

Author

Joe (joe.sedutto@silvertech.com)

Public Functions

Display(uint8_t _SEG_SEL_A_PIN, uint8_t _SEG_SEL_B_PIN, uint8_t _SEG_SEL_C_PIN, uint8_t _SEG_SEL_D_PIN, uint8_t _SEG_DP_PIN, uint8_t _SEG_A_PIN, uint8_t _SEG_B_PIN, uint8_t _SEG_C_PIN, uint8_t _SEG_D_PIN, uint8_t _SEG_E_PIN, uint8_t _SEG_F_PIN, uint8_t _SEG_G_PIN)

Constructs a new Display object.

Parameters:
  • _SEG_SEL_A_PIN – Segment Selector (A)

  • _SEG_SEL_B_PIN – Segment Selector (B)

  • _SEG_SEL_C_PIN – Segment Selector (C)

  • _SEG_SEL_D_PIN – Segment Selector (D)

  • _SEG_DP_PIN – Segment Decimal Point pin

  • _SEG_A_PIN – Segment “A” LED (top)

  • _SEG_B_PIN – Segment “B” LED (top right)

  • _SEG_C_PIN – Segment “C” LED (bottom right)

  • _SEG_D_PIN – Segment “D” LED (bottom)

  • _SEG_E_PIN – Segment “E” LED (bottom left)

  • _SEG_F_PIN – Segment “F” LED (top left)

  • _SEG_G_PIN – Segment “G” LED (center)

Display(uint8_t _SEG_SEL_A_PIN, uint8_t _SEG_SEL_B_PIN, uint8_t _SEG_SEL_C_PIN, uint8_t _SEG_SEL_D_PIN, uint8_t _LATCH_PIN)

Construct a new Display object.

Parameters:
  • _SEG_SEL_A_PIN – Segment Selector (A)

  • _SEG_SEL_B_PIN – Segment Selector (B)

  • _SEG_SEL_C_PIN – Segment Selector (C)

  • _SEG_SEL_D_PIN – Segment Selector (D)

  • _LATCH_PIN – Segment Latch

void begin()

Begin the display.

void setBaro(float pres, bool rising = true, bool falling = true, bool autoscale = true)

Set barometric pressure.

Parameters:
  • pres – Pressure in Millibar

  • rising – Wether or not the pressure has been trending up.

  • falling – Wether or not the pressure has been trending down.

  • autoscale – If true, will autoscale the number to include the highest precision (move dp)

void setWindspeed(float speed)

Set windspeed.

Note

Speed can be a float! setWindspeed will auto-scale from 0-9.9, and from 10-99

Parameters:

speed – Windspeed in km/h

void setHeading(int angle)

Set the compass heading.

Parameters:

angle – In degrees, 0-360

void setFill(bool _fill)

Enable or disable compass fill.

Parameters:

_fill – Whether or not to fill

void setClear(bool _clear)

Enables the display to go full-clear/test mode.

Parameters:

_clear – true when clearing

void setFillWidth(int _fillWidth)

Set the width of compass fill.

Parameters:

_fillWidth – How much to fill

void setTemp(float temp, bool indoor = false, bool outdoor = false, bool drawSign = false)

Set the temperature.

Parameters:
  • temp – A temperature in degrees C

  • indoor – Whether or not this reading is indoors

  • outdoor – Whether or not this reading is outdoors

  • drawSign – Whether or not to force draw the sign

void setTime(char *time, bool am = false, bool pm = false)

Set the display time section.

Note

The AM lamp and PM lamp can be enabled/disabled at the same time. They are not mutually exclusive.

Parameters:
  • time – Any char array with 6 chars exactly, the time display can also display the date, error codes and more

  • am – AM lamp

  • pm – PM lamp

void setErr(int err)

Raise and display an error code.

See also

Error

Parameters:

err – An error code, (0-99)

void clearDisplay()

Instantly clear an error from the display.

See also

Error

void refresh(unsigned int scrTime = 2000)

Refresh the screen.

Deprecated:

Deprecated, recommended to use Display.iterate instead.

Parameters:

scrTime – Time to be spent displaying each segment, in microseconds

uint8_t iterate()

Iterates through each display module at a time, designed to be called with a regular timer callback.

Returns:

The current index

float fastRound(float in, int precision)

Replacement for arduino std round, this is a little messy but its better than truncating the numbers we round. An alternative would be to only accept integers and leave rounding to the user.

Parameters:
  • in

  • precision

Returns:

float

int cyclic(int i, int max)

Return a cyclic value.

Parameters:
  • i – Value to circularize

  • max – The max bound

Returns:

int Returned Value

Private Functions

int nth_digit(int val, int n)

Return the n’th digit in an int (base 10)

Note

Do not confuse with bitRead(): Returning the n’th bit in an int (base 2)

Parameters:
  • val – An int value

  • n – What power to extract, eg 0 for 1 in 1234. and 2 for 3 in 1234

Returns:

The digit extracted (0-9)

bool hasElapsed(unsigned long time, int dur)

Checks to see if a set amount of time has elapsed.

Parameters:
  • time – The time in millis() to reference from

  • dur – A duration (in seconds)

Returns:

true if time has expired

Returns:

false if time has not yet expired

void writeRawDigit(uint8_t value, uint8_t index, bool drawZeros)

Writes a specific value to a specific LED index.

See also

segmentLookup

Parameters:
  • value – The value to write

  • index – The index of the segment to display on

  • drawZeros – Draw zeros or not

C++ Other

Error Codes

An error enumerator handles keeping track of all the possible error codes.

enum Error

Represents all possible id-4001-wifi errors.

Values:

enumerator noErr

Err00: Only used for testing.

enumerator noComm

Err01: No communication (Ususally refering to communication with ESP32 or API server).

enumerator notImplemented

Err02: Feature is not implemented or not yet finished. (May trigger on unconfigured buttons/config settings).

enumerator outOfRange

Err03: Function produced numbers out of range or function is not applicable to the current range (ie, rate when there is no deviation data).

enumerator gpsError

Err04: GPS error, usually encoding failure.

enumerator i2cError

Err05: i^2c error, ususally decoding failure.

Animations

A collection of little animations for the ID-4001-WiFi project.

Author

Joe (joe.sedutto@silvertech.com)

Date

2022-05-10

Copyright

Copyright (c) 2022

Functions

void startupAnimation1(Compass compass)

Simple little spinning compass startup animation.

Buttons

Functions

void configureButtons()

Configure the ID-4001’s buttons.

Author

Joe (joe.sedutto@silvertech.com)

void updateButton(uint8_t idx)

Updates a button based on its current intex.

Parameters:

idx

void updateButtons()

Updates every button, switching from front to back when appropriate.

Note

This should be called at the start of every loop

conversions

Functions

float milibarToInchMG(float millibar)

Converts Millibar to Inches of Mercury.

Parameters:

millibar – Value in millibars

Returns:

int Value in Inches of Mercury

float celsiusToFahrenheit(float celsius)

Converts Degrees Centigrade to Degrees Fahrenheit.

Parameters:

celsius – Value in C

Returns:

int Value in F

float kmhToMph(float kmh)

Converts Kilometers per hour to Miles per hour.

Parameters:

kmh – Value in Kmh

Returns:

float Value in Mph

float kmhToKnots(float kmh)

Converts Kilometers per hour to knots.

Parameters:

kmh – Value in Kmh

Returns:

float Value in kts