You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: content/arduino-libraries/io-abstraction/arduino-logging-with-io-logging.md
+16-4Lines changed: 16 additions & 4 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -14,9 +14,9 @@ toc_needed = true
14
14
weight = 5
15
15
+++
16
16
17
-
Logging is part of the IoAbstraction offering, it has a moderately complete logging framework that is still lightweight enough to work on small boards. It can easily be turned off completely for very small boards too. Both IoAbstraction and tcMenu use this logging to provide information about internal state and operations.
17
+
Logging is part of the TcMenu offering provided by library `TcMenuLog`, it has a moderately complete logging framework that is still lightweight enough to work on small boards. It can easily be turned off completely for very small boards too. TaskManagerIO, IoAbstraction and tcMenu use this logging to provide information about internal state and operations.
18
18
19
-
The logging is fully integrated into both IoAbstraction and TcMenu, and this change is backward compatible at a code level.
19
+
You can also use this logging framework in your own project code, regardless if you're using any other of our libraries.
20
20
21
21
{{< blockClear "left" >}}
22
22
@@ -26,11 +26,15 @@ To use the logging in your project you first include the logging header file:
26
26
27
27
#include <IoLogging.h>
28
28
29
-
Secondly you define the following build switch to turn on logging: `IO_LOGGING_DEBUG`. For example on platformIO that would be:
29
+
Should an older version of Arduino need the library header match the library name, you can also include:
30
+
31
+
#include <TcMenuLog.h>
32
+
33
+
Next, you define the following build switch to turn on logging: `IO_LOGGING_DEBUG`. For example on platformIO that would be:
30
34
31
35
build_flags = -DIO_LOGGING_DEBUG=1
32
36
33
-
If you are using the original Arduino IDE, it does not support build flags, you can in this case open IoLogging.h in the IoAbstraction library and uncomment the entry to define it in there. This would need to be done after each upgrade and is not recommended.
37
+
If you are using the original Arduino IDE, it does not support build flags, you can in this case open `IoLogging.h` in the TcMenuLog library and uncomment the entry to define it in there. This would need to be done after each upgrade and is not recommended.
34
38
35
39
You can set the logging levels at compile time using `IO_LOGGING_DEFAULT_LEVEL` by ORing together entries from `SerLoggingLevel`. An is shown below for only warning and error logs:
36
40
@@ -107,6 +111,14 @@ On mbed proper (IE using mbed without Arduino), **we must define the print inter
107
111
BufferedSerial serPort(USBTX, USBRX);
108
112
MBedLogger LoggingPort(serPort);
109
113
114
+
Instead of the above, you can use the following macro that always work, on any platform.
115
+
116
+
IOLOG_MBED_PORT_IF_NEEDED(txPin, rxPin)
117
+
118
+
You should always start the serial port. For example on Arduino you may need to start the serial port youre using with something like `Serial.begin(115200);`, and there is also a macro for that:
119
+
120
+
IOLOG_START_SERIAL
121
+
110
122
In summary, the logging framework is a compromise between functionality and size, biased slightly toward size.
IoAbstraction 2.0 onwards has core I2C/Wire functionality provided by several functions, these abstract the use of I2C over Arduino and mbed, and over time the implementation of these will be improved, such that asynchronous behaviour will be possible on certain boards.
16
+
IoAbstraction has core I2C/Wire and SPI functionality provided by several functions, these abstract the use of I2C and SPI over Arduino, mbed, PicoSDK and other supported platforms. Over time the implementation of these will be improved, such that asynchronous behaviour will be possible on certain boards.
17
17
18
-
Prior to 2.0, we had conditional I2C code scattered around the project, but now nearly all such functionality is separated out by platform, and sometimes even by board, we've made this available through the API, so you can use it too.
18
+
Prior to 2.0, we had conditional I2C code scattered around the project, but now nearly all such functionality is separated out by platform, and sometimes even by board simplifying access.
19
+
20
+
{{< blockClear "left" >}}
21
+
22
+
## Wire/I2C abstraction
19
23
20
24
We wrap up the wire object with `WireType`; which on Arduino it is a TwoWire pointer and on mbed it is an I2C pointer. For example the default wire type on Arduino would be `&Wire`. Be aware that this is not a complete replacement for Wire/I2C, it is a simple set of calls for reading and write from I2C where the device is master. It works on a very wide range of boards without needing code changes.
21
25
@@ -41,7 +45,7 @@ On all boards there is a lock around the i2c bus, this ensures that only one thr
41
45
42
46
extern SimpleSpinLock i2cLock;
43
47
44
-
## Reading bytes from the bus
48
+
###Reading bytes from the bus
45
49
46
50
To read bytes from the bus:
47
51
@@ -55,7 +59,7 @@ Where:
55
59
* len is the number of bytes to read
56
60
* returns true if the read is fully successful, otherwise false.
57
61
58
-
## Writing bytes to the bus
62
+
###Writing bytes to the bus
59
63
60
64
bool ioaWireWriteWithRetry(WireType pI2c, int address, const uint8_t* buffer,
61
65
size_t len, int retriesAllowed = 0, bool sendStop = true);
@@ -69,6 +73,39 @@ Where:
69
73
* retriesAllowed is the number of times to attempt the operation, 0 = only once.
70
74
* sendStop allows you to keep the bus open ready for a repeated start, use with care.
71
75
76
+
## The SPI abstraction
77
+
78
+
You can use SPI regardless of platform using the SPI abstraction. This is used in a few places within IoAbstraction so is already quite stable.
79
+
80
+
### Construction of SPI abstraction
81
+
82
+
In order to create an instance, you first need to create an `SPIWithSettings` object:
83
+
84
+
SPIWithSettings spiObj(&SPIBus, csPin);
85
+
86
+
Then in your code somewhere:
87
+
88
+
spiObj.init();
89
+
90
+
Where:
91
+
92
+
* SPIBus is the SPI bus on your hardware, for example on Arduino this may be `&SPI` for example.
93
+
* csPin is the chip select pin, doing any transfers automatically selects the pin first.
94
+
95
+
The class is quite small and has copy constructors, so you can safely copy it over by value, and this is often how its used within IoAbstraction.
96
+
97
+
### Transferring data over SPI
98
+
99
+
Normally on SPI you read and write data at the same time, therefore to `transfer` data call the following method that will first select the chip, do the transfer, and then deselect the chip:
100
+
101
+
uint8_t readWriteData[dataSize];
102
+
bool ok = spiObj.transferSPI(readWriteData, dataSize);
103
+
104
+
Where
105
+
106
+
* readWriteData is a uint8_t array of at least dataSize, the read data is put into the array after calling.
107
+
* dataSize is the number of bytes to transfer
108
+
72
109
{{< refdocs title="You can read more about this in the reference documentation" src="/ioabstraction/html/index.html" >}}
73
110
74
111
[Go back to the IoAbstraction page]({{< relref "io-abstraction.md" >}})
Copy file name to clipboardExpand all lines: content/arduino-libraries/io-abstraction/ioabstraction-troubleshooting-unit-testing.md
+1-1Lines changed: 1 addition & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -24,7 +24,7 @@ Within the MockIoAbstraction.h header there is an implementation of BasicIoAbstr
24
24
25
25
## Mock objects for use with Unit testing
26
26
27
-
This library itself is quite well tested using our simple test facilities, and further it makes unit testing your code easier. There is a MockIoAbstraction that provides very easy support for mocking out an IoAbstraction. You just provide how many `sync()` calls to store in the internal buffer:
27
+
This library itself is quite well tested, and further it makes unit testing your code easier. There is a MockIoAbstraction that provides very easy support for mocking out an IoAbstraction. You just provide how many `sync()` calls to store in the internal buffer:
Firstly the dimensions are configured automatically by calling `dimensionsFromRenderer` this sets the display sizes by querying the display plugin. Then the selected colors are chosen using the RGB macro for each color. Read more about `color_t` and the `RGB` macro below.
72
+
Firstly the dimensions are configured automatically by calling `dimensionsFromRenderer` this sets the display sizes by querying the display plugin. Then the selected colors are chosen using the `RGB` macro for each color. As you'd probably expect by convention the `RGB` macro takes red, green and blue parameters between `0` and `255`.
73
73
74
74
After that the item and title padding are configured, you can see we demonstrate both ways to construct a padding object (either all sides same, or separate value for each). The padding is within the rectangle of a menu item, and "pads out" the rectangle's size. You configure the title and item spacing separately (as they are usually different).
75
75
@@ -123,11 +123,13 @@ You can also change the font, color, padding, size and default justification at
123
123
* Default settings when no others match
124
124
* Last chance item that's compiled in just in-case there is a severe mis-configuration to avoid returning `nullptr`.
125
125
126
-
To change the default settings use `setDrawingPropertiesDefault` on the factory, providing the component type and the drawing settings. This will take effect when there are no other overrides
126
+
To change the default settings use `themeBuilder.defaultActionProperties()`, `themeBuilder.defaultItemProperties()` or `themeBuilder.defaultTitleProperties()` on a theme builder. This will take effect when there are no other overrides
127
127
128
-
To change the properties for all items that belong to a submenu use `setDrawingPropertiesForItem`on the factory, providing the component type and drawing settings. This will take effect when there are no item level overrides.
128
+
To change the settings for all items that belong to a submenu use `themeBuilder.submenuPropertiesActionOverride(subMenuItem)`, `themeBuilder.submenuPropertiesActionOverride(subMenuItem)`on theme builder, providing the menu to apply these settings to. This will take effect when there are no item level overrides.
129
129
130
-
To change the properties for a single item use `setDrawingPropertiesAllInSub` on the factory, providing the component type and drawing settings. This item will always have priority over anything else.
130
+
To change the properties for a single item use `themeBuilder.menuItemOverride(menuItem)` on theme builder, providing the menu item. This item will always have priority over anything else. Important note that if you apply changes at the item level, it is normally best to manually set the `row(..)` to keep control of the ordering.
131
+
132
+
These all use chained builder syntax as described elsewhere in this guide. You adjust the settings as desired, and finally you must call the `apply()` method. See below for examples.
131
133
132
134
### Creating two icon menu items on the same row
133
135
@@ -147,14 +149,16 @@ Here we present an example theme builder layout to show how to override two menu
147
149
148
150
In the above, the row and column upon which the item should appear in configured with `onRowCol(row, col, columnsOnRow)` and then the renderer is told to draw as an icon. Lastly, and very importantly we call `apply()`.
149
151
150
-
### Overriding a single item's paletteor border
152
+
### Overriding a single item's palette, border or font
151
153
152
154
Let's say we want an item to have a different palette, border, and justify differently:
0 commit comments