Custom Arduino Addon Library Issues - MWArduinoClass& and sendRequestMsg
3 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
Hello,
I am having an issue creating an Arduino object with an custom add-on library. I think I have followed all the documentation both for the Arduino Hardware Troubleshooting, the custom addon library setup documentation and examples.
I can create an Arduino as here:
>> a= arduino()
Updating server code on board Due (COM9). This may take a few minutes.
a =
arduino with properties:
Port: 'COM9'
Board: 'Due'
AvailablePins: {'D2-D53', 'A0-A11'}
AvailableDigitalPins: {'D2-D53', 'A0-A11'}
AvailablePWMPins: {'D2-D13'}
AvailableAnalogPins: {'A0-A11'}
AvailableI2CBusIDs: [0, 1]
Libraries: {'I2C', 'SPI', 'Servo'}
And I know that my custom addon can be read by the MATLAB terminal:
>> listArduinoLibraries
ans =
8×1 cell array
{'Adafruit/MotorShieldV2' }
{'I2C' }
{'RotaryEncoder' }
{'SPI' }
{'Servo' }
{'ShiftRegister' }
{'Ultrasonic' }
{'MyFolder/MyClass'}...
The project folder setup is similar to the one described in the HelloWorld class addon example.
When I run this command:
arduinoObj = arduino('COM9', 'Due', 'Libraries', 'MyFolder/MyClass', 'ForceBuildOn', true, 'Trace',true);
This is the output:
Updating server code on board Due (COM9). This may take a few minutes.
Loading configuration...
Initialising packages...
Preparing boards...
Verifying...
...
(A LOT OF SEEMINGLY NORMAL LOGS)
...
\Users\Me\AppData\Local\Temp\ArduinoServer\MW\sketch\PeripheralToHandle.c: In function 'getHandle':
C:\Users\Me\AppData\Local\Temp\ArduinoServer\MW\sketch\PeripheralToHandle.c:86:10: warning: cast to pointer from integer of different size
[-Wint-to-pointer-cast]
return (MW_Handle_Type)handleValue;
^
"C:\ProgramData\MATLAB\SupportPackages\R2019a\3P.instrset\arduinoide.instrset\idepkgs\packages\arduino\tools\arm-none-eabi-gcc\4.8.3-2014q1/bin/arm-none-eabi-gcc"
-c -g -Os -std=gnu11 -ffunction-sections -fdata-sections -nostdlib --param max-inline-insns-single=500 -Dprintf=iprintf -MMD -mcpu=cortex-m3
...
(A BIT MORE SEEMINGLY NORMAL LOGS)
...
"C:\Users\Me\AppData\Local\Temp\ArduinoServer\MW\sketch\IO_addOn.cpp.o"
In file included from C:\Users\Me\AppData\Local\Temp\ArduinoServer\MW\sketch\IO_addOn.cpp:12:0:
addOnLibraries.h:6: error: 'MyClass' does not name a type
MyClass aMyClass(hwObject); // ID = 0
^
Using library Wire at version 1.0 in folder:
...(A bit more stuff)
...
I think the errors are related to these parts of the C++ class that are highlighted with errors in my IDE. The issue is that I took these lines directly from the HelloWorld example, so it is odd that it appears with errors in the IDE.
Some relevant lines from my Header file are:
#include "LibraryBase.h" // MATLAB Connection
#include <Arduino.h>
class MyClass : public LibraryBase {
public:
MyClass(MWArduinoClass& a) { // TODO Error highlight at MWArduinoClass
libName = "MyFolder/MyClass"; // Folder/class
a.registerLibrary(this);
}
void commandHandler(byte cmdID, byte* dataIn, unsigned int payloadSize) {
switch (cmdID) {
case TEST_CONNECTION: {
testConnection();
byte value[17] = "Good connection.";
sendResponseMsg(cmdID, value, 17); // TODO Error highlight at sendResponseMsg
break;
}
... more stuff
The error highlight at the `MWArduinoClass&` line from cpplint says:
(int)4096
Is this a non-const reference? If so, make const or use a pointer: MWArduinoClass& a [runtime/references]cpplint
Single-parameter constructors should be marked explicit. [runtime/explicit]cpplint
expected ')' before '&' token
identifier "MWArduinoClass" is undefined
Where would MWArduinoClass be included if not from LibraryBase.h?
The error highlight at the `sendResponseMsg` line from cpplint says:
(int)4096
'sendResponseMsg' was not declared in this scope
identifier "sendResponseMsg" is undefined
How do I include this function so it does not appear undefined?
I think that because the C++ library cannot build properly due to these two undefined external terms, this may cause the error uploading the library into the Arduino. However, I have looked into the CommandHandler documentation and the LCD custom addon library example where `sendResponseMsg` is explained and I still cannot find how to make these terms defined within the library file. Could you give me some guidance, please?
Note that if you copy paste this error description I have written into a markdown visualizer, it would look much nicer to read. The C++ library editor is Visual Studio Code and the library is built using PlatformIO.
Thanks
1 comentario
Respuestas (0)
Ver también
Categorías
Más información sobre I2C Devices en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!