The inclusion of the Bargraph Display into the Softata suite, as per the previous blog post here, is outlined here starting with specifications and initial hooks into the software.

As stated previously: “To add a device you include its Arduino library and then slot it into the Softata app infrastructure. That code is, in the main, polymorphic. To add for example, a sensor, you copy the template sensor.cpp file and implement the methods in it according to the devices library samples. You also create header code for it largely by copying an existing sensor’s header. Within the Softata app and SoftataLib code there ar then some specific hooks to add for the device. This API is documented here Here goes for a new Display:

The “shell” Softata code for the Bargraph Display has been implemented. This includes code in the Arduino sketch as well as in the minimal mirroring code in SoftataLib. The Console app did not require any new code. The shell code does not implement the required functionality, but includes empty methods that return true where the functionality can be implemented. The Arduino sketch builds and runs without error with these additions. The C# SoftataLib code compiles and the display can be chosen in the Console app where the app runs and completes without error. A comparison was made of the repository before and after the addition of the “shell” code for the display and can be viewed here

The object of this specific exercise is to provide a template for adding devices, specifically for adding displays to Softata.

This post covers specifications for a new display particularly in terms of enum constants and class name. The next post covers the actual class code.

1. Start Here

Download the repository to a directory:

Open the folder in VS Code.

Note: The lower level Arduino code is not visible in the Arduino IDE when Softata is opened as it’s in a src folder below that of softata.ino. The src folder files are though used when the Arduino sketch is built in the Arduino IDE.

2. The Display Device

Having determined the display to include, get a sample app running on an Arduino device. May require installation of a standard Arduino library or a custom one via its zip file. Note the connections GPIO, I2C, SPI or Serial etc.

3. The Display Name

Select a name for the display class and for its enum in the list of displays, for example:

  • Class Name: Custom_Bargraph
  • Enum: BARGRAPH

In softata.h" in the sketch at about line 77 append the Enum name for the display toG_Displays``` with a preceding C:

#define G_DISPLAYS C(OLED096)C(LCD1602)C(NEOPIXEL)C(BARGRAPH)

Note the C between each display enum name in the list.

This is used to generate the enum list as well as an array of strings of those names

Also in softata.h, add the string that gets retuirned upon request stating the default connections to the string. It can also state options for that. Insert as a line after that statement for the NEOPIXEL_PINNOUT i.e. after about line 152:

#define BARGRAPH_PINNOUT "16 (DS of 74HC595-Pin14),20 (ST_CP of 74HC595-Pin12),21 (SH_CP of 74HC595-Pin11)(default)"

Nb: Needs to before the following #endif

Note that the name of this defined string must be the display’s Enum name with _PINNOUT appended. This reuse of the Enum name is similarly used to generate symbolic names elsewhere.


In SoftataLib/enums.cs at about line 7, add the display name to the DisplayDevice list at /* Add Here, */

public enum DisplayDevice : byte { OLED096, LCD1602, NEOPIXEL,BARGRAPH, /* Add Here, */ Undefined = 0xFF }
  1. Misc Commands

The overarching class for devices in Softata is the Grove class which specifies methods applicable to all device types which all device classes must implement. An example is the SetupDefault() and more general Setup() methods. The device types Sensor, Actuator and Display derive from this. Whilst Sensor and Actuator interfaces are quite standard, and hence the interfaces for their classes are reasonably universal, (that is, each has a standard set of properties and methods), displays are not so. A display can be anything from a set of LEDs, to a 2 line display of characters to a 2D array of pixels. Whilst there will be a universal set of commands for a display, each display type requires specific commands. So the Softata Display class has an additional display method with a specific implementation, Misc(). This takes a parameter specifying the specific sub command for the specific display, along with any required data. Note that that means, for example, the first (0th) Misc command for one display will mean something quite different for another.

Note: Whilst there is a set of methods that each device in a class will be required to implement, they might not be all applicable to a specific device. They are then implemented as a method that does not do anything except return a true or false value. If true is used in these cases, a call by a device to such a method in Softata will be seamless, with no consequences. Alternatively a return of false can be used to indicate to the host app that the method does not apply to the device.

Each display requires a list of Misc commands. It can be empty though:

For the BARGRAPH display in softata.h just after enum OLEDMiscCmds ..., about line 161 add:

enum BARGRAPHMiscCmds {flow};

This means there will be a Bargraph Misc command called flow() and being first in the list its index will be zero.

This will be added to SoftataLib later.


 TopicSubtopic
   
 This Category Links 
Category:Softata Index:Softata
  Next: > Softata - Adding a new display
<  Prev:   Softata - Adding a new display