Softata - Adding a new display: 4. Class Code
softata rpipico firmata arduino csharp bme280 grove softatadisplay
Implementation of the C++ Bargraph class (shell only)._
As stated previously: 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.
The previous post covered specifications for a new display particularly in terms of enum constants and class name. This post covers the actual class code.
1. Links
- The repository latest version
-
The version before the Bargraph was added that is modified in this discussion.
- A comparison of the repository before and after this extension is here.
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 contains the C++ files that do most of the actual implementation. The src folder files are used when the Arduino sketch is built in the Arduino IDE.
2. The Display Header File
In Softata/src/grove_displays.h
All of the header files for Softata are in one file. A reasonable change would be to separate them (2Do).
In grove_displays.h
, (remember to open in VScode), completely copy one of the display’s header and paste this at the end. Modify to match this following. (Essentially just a name change of the display.)
#ifndef CUSTOM_BARGRAPHH
#define CUSTOM_BARGRAPHH
class Custom_Bargraph: public Grove_Display
{
public:
static String GetPins()
{
String msg="OK:";
msg.concat(BARGRAPH_PINNOUT);
return msg;
}
virtual bool Setup();
virtual bool Setup(byte * settings, byte numSettings);
virtual bool Clear();
virtual bool Home();
virtual bool Backlight();
virtual bool SetCursor(byte x, byte y);
virtual bool WriteString(String msg);
virtual bool CursorWriteStringAvailable();
virtual bool WriteString(byte x, byte y, String msg);
virtual bool Misc(byte cmd, byte * data, byte length=0);
protected:
};
#endif
Alt: The modified
grove_displays.h
is here
3. Create the Display source file
Alt: The
custom_bargraph.cpp
is here
- Create a new file called custom_bargraph.cpp.
- Copy the class code from above and paste it into the file.
- Remove everything above
virtual bool Setup();
. - Add the following to the top of the file:
#include <Arduino.h> #include "grove_displays.h"
- Do a bulk replace of
virtual bool<space>
withbool Custom_Bargraph::
and remove the semicolon on those lines.
e.g.virtual bool Setup();
becomesbool Custom_Bargraph::Setup()
- Remove the following at the end of the file:
protected: };
- After each method append blank code:
{ return true; }
So overall,
virtual bool Setup();
becomes:Custom_Bargraph::Setup() { return true; }
Do this for all methods in the .cpp file.
4. The Misc Method
Modify it as follows:
bool Custom_Bargraph::Misc(byte cmd, byte * data, byte length)
{
BARGRAPHMiscCmds Cmd = (BARGRAPHMiscCmds)cmd;
switch(Cmd)
{
case flow:
return true;
break;
default:
return false;
break;
}
}
5. SoftataLib
- In SofataLib/Displays.cs insert the BARGRAPHDisplay class after about line 274:
(Can open the cs solution for Softata in Visual Studio for this.)
public static class BARGRAPHDisplay
{
// Misc commands
enum BARGRAPHMiscCmds { flow };
public static bool Flow(byte displayLinkedListIndex)
{
byte[] data = new byte[] { 0x1, (byte)BARGRAPHMiscCmds.flow };
string result = SendMessage(Commands.groveDisplay, 0, (byte)GroveDisplayCmds.misc, "OK:", displayLinkedListIndex, data);
return true;
}
}
Nb: This should be inside the closing brace for
public static class Display
.
Next: Test thus far.
Topic | Subtopic | |
This Category Links | ||
Category: | Softata Index: | Softata |
Next: > | Softata - Adding a new display | 5. Simple Test |
< Prev: | Softata - Adding a new display | 3. Arduino "Hooks" |