Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependencies: BLE_API mbed nRF51822
Revision 2:5ec56b1cea3f, committed 2016-04-19
- Comitter:
- wodenageshen
- Date:
- Tue Apr 19 03:41:18 2016 +0000
- Parent:
- 1:1a916ea0c603
- Commit message:
- smartball_testball
Changed in this revision
| main.cpp | Show annotated file Show diff for this revision Revisions of this file |
--- a/main.cpp Tue Apr 19 02:47:33 2016 +0000
+++ b/main.cpp Tue Apr 19 03:41:18 2016 +0000
@@ -1,15 +1,15 @@
#include "mbed.h"
#include "BLE.h"
-
+#include "stdio.h"
#include "UARTService.h"
-DigitalOut onboard_led(p30);
+DigitalOut charge(p6);
DigitalOut fixture_led(p10);
Serial change_stdio_uart(p20, p21);
#define NEED_CONSOLE_OUTPUT 0 /* Set this if you need debug messages on the console;
- * it will have an impact on code-size and power consumption. */
+* it will have an impact on code-size and power consumption. */
#if NEED_CONSOLE_OUTPUT
#define DEBUG(...) { printf(__VA_ARGS__); }
@@ -20,17 +20,11 @@
BLEDevice ble;
UARTService *uart;
-
-void disconnectionCallback(Gap::Handle_t handle, Gap::DisconnectionReason_t reason)
-{
- DEBUG("Disconnected!\n\r");
- DEBUG("Restarting the advertising process\n\r");
- ble.startAdvertising();
-}
+
void periodicCallback(void)
{
- onboard_led = !onboard_led;
+ // onboard_led = !onboard_led;
}
int main(void)
@@ -39,92 +33,36 @@
ticker.attach(periodicCallback, 1);
DEBUG("Initialising the nRF51822\n\r");
- ble.init();
- ble.onDisconnection(disconnectionCallback);
-
- uart = new UARTService(ble);
-
- /* setup advertising */
- ble.accumulateAdvertisingPayload(GapAdvertisingData::BREDR_NOT_SUPPORTED);
- ble.setAdvertisingType(GapAdvertisingParams::ADV_CONNECTABLE_UNDIRECTED);
- ble.accumulateAdvertisingPayload(GapAdvertisingData::SHORTENED_LOCAL_NAME,
- (const uint8_t *)"BLE UART", sizeof("BLE UART") - 1);
- ble.accumulateAdvertisingPayload(GapAdvertisingData::COMPLETE_LIST_128BIT_SERVICE_IDS,
- (const uint8_t *)UARTServiceUUID_reversed, sizeof(UARTServiceUUID_reversed));
-
- ble.setAdvertisingInterval(160); /* 100ms; in multiples of 0.625ms. */
- ble.startAdvertising();
-
- BusOut output_pins(p7,p8,p23,p25,p28,p29);
- BusIn input_pins(p1,p2,p4,p12,p13,p24,p0,p17,p18,p9);
-
- const uint16_t output_value1 = 0x2a;
- const uint16_t output_value2 = 0x15;
- const uint16_t input_value_expected1 = 0x2aa;
- const uint16_t input_value_expected2 = 0x155;
- uint16_t input_value1;
- uint16_t input_value2;
- bool io_passed = true;
- fixture_led = 0;
-
- output_pins = output_value1;
- wait_ms(1);
- input_value1 = input_pins;
- if(input_value_expected1 != input_value1) {
- io_passed = false;
- }
-
- output_pins = output_value2;
- wait_ms(1);
- input_value2 = input_pins;
- if(input_value_expected2 != input_value2) {
- io_passed = false;
- }
-
Serial pc(p8, p7);
pc.baud(9600);
pc.puts("ready\r\n");
-
+
// ------------- serial test -------------------
char line_buffer[32] = {0};
- const char *line_expected = "start"; // "start test" -- "arch ble"
- bool line_matched = false;
- for (int i = 0; i < 3; i++) {
+ const char *line_expected1 = "charge1";
+ const char *line_expected2 = "charge0"; // "start test" -- "arch ble"
+ // bool line_matched = false;
+ while(1) {
pc.scanf("%s", line_buffer);
- if (0 == strcmp(line_buffer, line_expected)) {
- line_matched = true;
- pc.puts("arch ble\r\n");
- break;
+ if (0 == strcmp(line_buffer, line_expected1)) {
+ // line_matched = true;
+ pc.puts("charge\r\n");
+ charge=1;
+ memset(line_buffer,32,0); //line_buffer[32] = {0};
+ // break;
}
- }
-
- // ----------- io test result -----------------
- if (!io_passed) {
- pc.puts("io test failed:\r\n");
- pc.printf("\tout = 0x%X, in = 0x%X, expected = 0x%X\r\n", output_value1, input_value1, input_value_expected1);
- pc.printf("\tout = 0x%X, in = 0x%X, expected = 0x%X\r\n", output_value2, input_value2, input_value_expected2);
- } else {
- pc.puts("io test ok\r\n");
- }
-
- // ------------- serial test result --------------
- if (!line_matched) {
- pc.puts("serial rx test failed\r\n");
- } else {
- pc.puts("serial rx test ok\r\n");
- }
-
- if ( io_passed && line_matched) {
- fixture_led = 1;
- } else {
- while (true) {
- fixture_led = !fixture_led;
- wait(0.1);
+
+ if (0 == strcmp(line_buffer, line_expected2)) {
+ // line_matched = true;
+ pc.puts("discharge\r\n");
+ charge=0;
+ memset(line_buffer,32,0);
+ // break;
}
+
}
- while (true) {
- ble.waitForEvent();
- }
+
+
}
\ No newline at end of file