Skip to content

Commit 3236a7d

Browse files
committed
Merge branch 'opta_analog_rebased' of github.com:bcmi-labs/Arduino_Opta_Blueprint into opta_analog_rebased
2 parents 323d1c3 + 30ca307 commit 3236a7d

File tree

2 files changed

+34
-21
lines changed

2 files changed

+34
-21
lines changed

AddCustomExpansion.md

Lines changed: 32 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ To add new expansion to the BluePrint library is necessary to provide:
1818

1919
The FW and expansion class must be developed in a different folder/repository
2020
and no changes or PR should be required in this Opta BluePrint library.
21+
We suggest to create a separate library.
2122

2223
It is suggested that FW source files and the expansion class are put in the
2324
same folder for simplicity reasons (this allows to share information between
@@ -45,7 +46,7 @@ So a good starting point to develop an expansion FW is the following folder
4546
structure (suppose your expansion is called "NewExpansion")
4647

4748
```
48-
/rood_folder_of_new_expansion_library
49+
/root_folder_of_new_expansion_library
4950
|-firmware/NewExpansion/NewExpansion.ino
5051
|-src/
5152
|-OptaNewExpansion.h
@@ -66,25 +67,6 @@ Opta Controller is build.
6667
**_NOTE: in the following we suppose that the new expansion "name" is
6768
"NewExpansion"_**
6869

69-
## Performance request
70-
Each expansion performs Assign Address Process using a common class Module, which
71-
is contained in OptaBlueModule files (.h and .cpp).
72-
In particular the function Module::update() is responsible to change the I2C address
73-
of the expansion.
74-
When the expansion has not a valid address and it receives the command from the
75-
controller to set up the address, the change of the address (being performed in
76-
Module::update()) is done in the main loop of the function.
77-
So there is a delay between the time the expansion get the message (I2C interrupt) and
78-
the moment the espansion actually set the address (in the main loop).
79-
The actual set of the expansion, in other word, depends on how "fast" is the main
80-
loop, however the main controller waits for a certain time and then retry the
81-
process.
82-
The expansion must set the new address as fast as it can!
83-
This means that is is strongly suggested that the main loop of the expansion
84-
only runs when the address is valid, so that when not a valid address has been set up,
85-
it can react very quickly to the address set request.
86-
87-
8870
### OptaNewExpansion class
8971

9072
The files OptaNewExpansion file .h and .cpp must contain the implementation
@@ -228,6 +210,35 @@ care of the message and you just need to return the same value.
228210
Do not make any change to the `expansion_type` (an integer in the Module class).
229211
This is set in Module class and must NOT be modified in any Custom expansion.
230212

213+
### Performance request
214+
Each expansion performs Assign Address Process using a common class Module, which
215+
is contained in OptaBlueModule files (.h and .cpp).
216+
The Module::begin() function performs the assign address process at the very
217+
beginning, but the function Module::update() is responsible to change the I2C address
218+
of the expansion when a new expansion is plugged in and the assign address process
219+
is done a second time (this function has to be called in the NewExpansion::update()
220+
function, see above).
221+
In the latter case the change of the address (being performed in
222+
Module::update()) is done in the main loop of the expansion.
223+
So there is a delay between the time the expansion gets the message (I2C interrupt) and
224+
the moment the espansion actually sets the address (in the main loop).
225+
The actual set of the expansion, in other word, depends on how "fast" is the main
226+
loop, however the main controller waits for a certain time and then retry the
227+
process.
228+
The expansion must set the new address as fast as it can in order to avoid retries
229+
from the controller.
230+
This means that is is strongly suggested that the main loop of the expansion (except for
231+
the call to the Module::update() function) only runs when the address is valid,
232+
so that when not a valid address has been set up, it can react very quickly to the
233+
address set request.
234+
A good way to understand if the expansion has a valid address is:
235+
```
236+
if(wire_i2c_address <= OPTA_DEFAULT_SLAVE_I2C_ADDRESS ||
237+
wire_i2c_address >= OPTA_CONTROLLER_FIRST_TEMPORARY_ADDRESS) {
238+
// NO VALID ADDRESS ACQUIRED
239+
}
240+
```
241+
231242
## OptaNewExpansionCfg.h
232243

233244
This is an optional configuration file that contains all the configuration
@@ -384,7 +395,7 @@ The I2C_TRANSACTION already takes cares of timeouts and will call the failed
384395
communication callback if set.
385396

386397
**IMPORTANT**
387-
There are 3 operation the basic expansion class takes care which are common to
398+
There are 3 operations the basic expansion class takes care which are common to
388399
all classes (WRITE in flash, READ in flash, get FW version).
389400
If you want to use these operation remember to call `Expansion::execute();` in
390401
your `defaul` case switch of execute. This will use the base `execute()` function

examples/Digital/defaultValues/defaultValues.ino

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,8 @@ void setup() {
3737
false,true,true,false,false),2000);
3838
DigitalExpansion::setDefault(OptaController,3,DigitalExpansion::calcDefault(false,false,false,
3939
false,false,false,true,true),1000);
40+
DigitalExpansion::setDefault(OptaController,4,DigitalExpansion::calcDefault(true,false,false,
41+
true,false,false,false,true),5000);
4042
delay(1000);
4143

4244

0 commit comments

Comments
 (0)