mraa  1.8.0
Low Level Skeleton Library for Communication on GNU/Linux platforms
Functions | Typedefs
firmata.h File Reference

API Description

Firmata IO lets you SYSEX messages construct and ask for a callback on a SYSEX messages. This is meant to provide a way to call custom firmata APIs especially using the Custom firmata API

mraa_firmata_context firm = mraa_firmata_init(FIRMATA_CURIE_IMU);
if (firm == NULL) {
return EXIT_FAILURE;
}
mraa_firmata_response(firm, interrupt);
char* buffer = calloc(4, 0);
if (buffer == NULL) {
free(firm);
return EXIT_FAILURE;
}
buffer[0] = FIRMATA_START_SYSEX;
buffer[1] = FIRMATA_CURIE_IMU;
buffer[2] = FIRMATA_CURIE_IMU_READ_ACCEL;
buffer[3] = FIRMATA_END_SYSEX;
mraa_firmata_write_sysex(firm, buffer, 4);
sleep(1);
// stop the isr and set it again
mraa_firmata_response(firm, interrupt);
mraa_firmata_write_sysex(firm, buffer, 4);
sleep(1);
// close everything and try again
firm = mraa_firmata_init(FIRMATA_CURIE_IMU);
mraa_firmata_response(firm, interrupt);
mraa_firmata_write_sysex(firm, buffer, 4);
sleep(10);

Go to the source code of this file.

Functions

mraa_firmata_context mraa_firmata_init (int feature)
 
mraa_result_t mraa_firmata_write_sysex (mraa_firmata_context dev, char *msg, int length)
 
mraa_result_t mraa_firmata_response (mraa_firmata_context dev, void(*fptr)(uint8_t *, int))
 
mraa_result_t mraa_firmata_response_stop (mraa_firmata_context dev)
 
mraa_result_t mraa_firmata_close (mraa_firmata_context dev)
 

Typedefs

typedef struct _firmata * mraa_firmata_context
 

Function Documentation

mraa_firmata_context mraa_firmata_init ( int  feature)

Initialise firmata context on a feature. This feature is what will be listened on if you request a response callback

Parameters
featurefirmata feature
Returns
firmata context or NULL
mraa_result_t mraa_firmata_write_sysex ( mraa_firmata_context  dev,
char *  msg,
int  length 
)

Sends a custom SYSEX message to the firmata board.

Parameters
devThe Firmata context
msgThe SYSEX message
lengthThe length of the sysex message
mraa_result_t mraa_firmata_response ( mraa_firmata_context  dev,
void(*)(uint8_t *, int)  fptr 
)

Set a callback on 'feature'. This function is not thread safe and threads calling it need to make sure they are the only thread calling this.

Parameters
devThe Firmata context
fptrFunction pointer to function to be called when interrupt is triggered, the returned buffer and length are the arguments.
Returns
Result of operation
mraa_result_t mraa_firmata_response_stop ( mraa_firmata_context  dev)

Stop getting events on feature. This is more efficient than mraa_firmata_close as it can be re-enabled without adding a feature

Parameters
devThe Firmata context
Returns
Result of operation
mraa_result_t mraa_firmata_close ( mraa_firmata_context  dev)

Free all firmata handle resources, this will leave an element in an array internally that will be skipped, avoid closing many firmata contexts often as there is a cost to doing this

Parameters
devThe Firmata context
Returns
Result of operation

Typedef Documentation

typedef struct _firmata* mraa_firmata_context

Opaque pointer definition to the internal struct _firmata. This context refers to one firmata 'extension' letting you write/return SYSEX messages directly

Include dependency graph for firmata.h: