Menu

Using ModuleClient

Daniel Crewe

The ModuleClient library is intended to handle I2C communications and maintain the current state of each module.

Installing

To install the ModuleClient library on your computer so you can include it in your module:

  • Open the Arduino IDE
  • Select "Sketch">"Include Library">"Add .ZIP Library.."
  • Browse to and select the ModuleClient folder
  • Click Open

If it was successful, you should see the message: Library added to your libraries. Check "Include library" menu

How to Use

To use the ModuleClient library in your module, add the following two lines to the top of your ino file:

#include <ModuleClient.h>
ModuleClient client(x);

Replacing x with one of the ids assigned to you.

You can then get the current state of your module with the command:
uint8_t state = client.GetState();

Where state is one of the states below:

InactiveState - The host has yet to activate your module. (default state)
ActiveState - The host has activated your module.
SuccessState - Your module has been successfully completed.
FailState - The user has failed your module, but the host has not recorded that loss yet.
FailReadState - The host has recognized the failure and you can now reset your module so the user can try again.

Your module has three functions it can use to modify the state, but each only works when the module is already in a certain state
client.SetSuccess()- Changes the state to SuccessState if the state is currently ActiveState
client.SetFail() - Changes the state to FailState if the state is currently ActiveState
client.Reset()- Changes the state to InactiveState if the state is currently FailReadState

Limiting the module's control over the module's current state is intentional, because part of this library's purpose is to ensure that the different clients provide a consistant interface with the host


Related

Wiki: Home