Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add firmata ble support using littleb library #604

Open
wants to merge 9 commits into
base: master
Choose a base branch
from
Prev Previous commit
Next Next commit
removed debug prints
renamed callback
removed firmata pull thread when using ble

Signed-off-by: Shiran Ben-Melech <shiran.ben-melech@intel.com>
shiranbm committed Jun 12, 2016
commit 814b7455c5c5c4df0c01cd8d289f8cef3205f9e3
320 changes: 0 additions & 320 deletions api/mraa/littleb.h

This file was deleted.

6 changes: 5 additions & 1 deletion examples/python/hello_gpio.py
Original file line number Diff line number Diff line change
@@ -23,11 +23,15 @@
# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

import mraa
import time

print (mraa.getVersion())
mraa.addSubplatform(mraa.BLE_FIRMATA_BY_NAME, "FIRMATA")
x = mraa.Gpio(13 + 512)
x.dir(mraa.DIR_OUT)
for i in range(100):
print "Blinking"
for i in range(10):
x.write(1)
time.sleep(0)
x.write(0)
time.sleep(1)
15 changes: 3 additions & 12 deletions src/firmata/firmata.c
Original file line number Diff line number Diff line change
@@ -31,30 +31,21 @@
#include <stdio.h>

static int
test_callback(sd_bus_message* message, void* userdata, sd_bus_error* error)
firmata_uart_read_handler(sd_bus_message* message, void* userdata, sd_bus_error* error)
{

int r, i;
size_t size = 0;
uint8_t* result = NULL;
t_firmata* firmata = (t_firmata*) userdata;


printf("callback called\n");

r = dl_lb_parse_uart_service_message(message, (const void**) &result, &size);
if (r < 0) {
fprintf(stderr, "ERROR: couldn't parse uart message\n");
return LB_ERROR_UNSPECIFIED;
}

printf("message is:\n");
for (i = 0; i < size; i++) {
printf("%x ", result[i]);
}
printf("\n");

//firmata_parse(firmata, result, size);
firmata_parse(firmata, result, size);

return LB_SUCCESS;
}
@@ -183,7 +174,7 @@ firmata_ble_new(const char* name, mraa_platform_t type)
}

ble_res = dl_lb_register_characteristic_read_event(res->lb_ctx, res->bl_dev,
"6e400003-b5a3-f393-e0a9-e50e24dcca9e", test_callback, res);
"6e400003-b5a3-f393-e0a9-e50e24dcca9e", firmata_uart_read_handler, res);
if (ble_res < 0) {
fprintf(stderr, "ERROR: lb_register_characteristic_read_event\n");
firmata_ble_close(res);
4 changes: 3 additions & 1 deletion src/firmata/firmata_mraa.c
Original file line number Diff line number Diff line change
@@ -555,7 +555,9 @@ mraa_firmata_plat_init(const char* uart_dev, mraa_platform_t type)
return NULL;
}

pthread_create(&thread_id, NULL, mraa_firmata_pull_handler, NULL);
if (!(type == MRAA_BLE_FIRMATA_BY_NAME || type == MRAA_BLE_FIRMATA_BY_ADDRESS)) {
pthread_create(&thread_id, NULL, mraa_firmata_pull_handler, NULL);
}

b->platform_name = "firmata";
// do we support 2.5? Or are we more 2.3?