BLE-writeable Display Puck with an e-paper display. Built on the Puck IOT platform.
Dependencies: Puck lz mbed seeedstudio-epaper
The Display puck is a puck with an e-paper display that can show arbitrary black and white images received over Bluetooth LE.
A tutorial for the Display Puck is available on GitHub.
Tutorials and in-depth documentation for the Puck platform is available at the project's GitHub page
Diff: main.cpp
- Revision:
- 1:42882ba4c901
- Parent:
- 0:7499fa0a8ecb
- Child:
- 3:4ff226c4fe2a
diff -r 7499fa0a8ecb -r 42882ba4c901 main.cpp --- a/main.cpp Thu Jul 17 14:16:16 2014 +0000 +++ b/main.cpp Fri Jul 18 09:20:35 2014 +0000 @@ -53,13 +53,17 @@ #define IMAGE_SIZE 2904 #define Y_SIZE 88 #define X_SIZE 264 - +#define RECEIVE_BUFFER_SIZE 1000 uint8_t image[IMAGE_SIZE]; +uint8_t receive_buffer[RECEIVE_BUFFER_SIZE]; extern GattService display_service; extern GattCharacteristic command, data; int current_command = COMMAND_NOOP; +bool isConnected = false; +bool isAdvertising = false; + const static uint8_t beaconPayload[] = { 0x00, 0x4C, // Company identifier code (0x004C == Apple) 0x02, // ID @@ -87,7 +91,7 @@ current_command = command.getValuePtr()[0]; - py.printf("%i\n", current_command); + py.printf("cmd: %i\n", current_command); if(current_command == COMMAND_BEGIN_UPPER || current_command == COMMAND_BEGIN_LOWER) { receive_index = 0; @@ -97,12 +101,10 @@ if (data.getHandle() == handle) { uint8_t* value = data.getValuePtr(); for(int i = 0; i < 20 && receive_index < IMAGE_SIZE; i++) { - image[receive_index++] = value[i]; + receive_buffer[receive_index++] = value[i]; } if (receive_index == IMAGE_SIZE) { receive_index = 0; - if(current_command == COMMAND_BEGIN_UPPER) { current_command = COMMAND_IMAGE_UPPER; } - if(current_command == COMMAND_BEGIN_LOWER) { current_command = COMMAND_IMAGE_LOWER; } } } } @@ -110,16 +112,19 @@ void disconnectionCallback(void) { py.printf("Disconnected!\n"); - py.printf("Restarting the advertising process\n"); - ble.startAdvertising(); + isConnected = false; } void connectionCallback(void) { py.printf("Connected!\n"); + isConnected = true; + isAdvertising = false; } - +void uncompress_image() { + LZ_Uncompress(receive_buffer, image, receive_index); +} //uint8_t image[5808]; @@ -162,15 +167,7 @@ ble.onDisconnection(disconnectionCallback); ble.onConnection(connectionCallback); ble.onDataWritten(onDataWritten); - ble.accumulateAdvertisingPayload(GapAdvertisingData::BREDR_NOT_SUPPORTED); - ble.setAdvertisingType(GapAdvertisingParams::ADV_CONNECTABLE_UNDIRECTED); - ble.setAdvertisingInterval(160); /* 100ms; in multiples of 0.625ms. */ - - ble.accumulateAdvertisingPayload(GapAdvertisingData::MANUFACTURER_SPECIFIC_DATA, - beaconPayload, sizeof(beaconPayload)); - - ble.startAdvertising(); ble.addService(display_service); @@ -197,6 +194,7 @@ if(current_command == COMMAND_IMAGE_UPPER) { py.printf("Uppering.\n"); + uncompress_image(); EPD.begin(EPD_2_7); EPD.start(); EPD.image(image, 0, EPD.lines_per_display / 2); @@ -207,12 +205,25 @@ if(current_command == COMMAND_IMAGE_LOWER) { py.printf("Lowering.\n"); + uncompress_image(); EPD.begin(EPD_2_7); EPD.start(); - EPD.image(image, EPD.lines_per_display / 2); + EPD.image(image, EPD.lines_per_display / 2, EPD.lines_per_display); EPD.end(); current_command = COMMAND_NOOP; } + + if(!isConnected && !isAdvertising) { + ble.clearAdvertisingPayload(); + ble.accumulateAdvertisingPayload(GapAdvertisingData::BREDR_NOT_SUPPORTED); + ble.setAdvertisingType(GapAdvertisingParams::ADV_CONNECTABLE_UNDIRECTED); + ble.setAdvertisingInterval(160); /* 100ms; in multiples of 0.625ms. */ + ble.accumulateAdvertisingPayload(GapAdvertisingData::MANUFACTURER_SPECIFIC_DATA, + beaconPayload, sizeof(beaconPayload)); + ble.startAdvertising(); + py.printf("Restarting the advertising process\n"); + isAdvertising = true; + } } } \ No newline at end of file