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: ADXL362_v3 BLE_API mbed nRF51822
Fork of BLENano_SimpleTemplate_adxl362_170813 by
Revision 10:c90237505549, committed 2017-10-19
- Comitter:
- asyrofi
- Date:
- Thu Oct 19 11:59:32 2017 +0000
- Parent:
- 9:ca9a58478ddd
- Commit message:
- still confuse
Changed in this revision
| Servo.cpp | Show diff for this revision Revisions of this file |
| Servo.h | Show diff for this revision Revisions of this file |
| main.cpp | Show annotated file Show diff for this revision Revisions of this file |
--- a/Servo.cpp Tue Sep 05 06:20:07 2017 +0000
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,42 +0,0 @@
-/*
-
-Copyright (c) 2012-2014 RedBearLab
-
-Permission is hereby granted, free of charge, to any person obtaining a copy of this software
-and associated documentation files (the "Software"), to deal in the Software without restriction,
-including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense,
-and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so,
-subject to the following conditions:
-The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
-
-THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
-INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
-PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE
-FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
-ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
-
-*/
-
-#include "Servo.h"
-
-Servo::Servo(PinName pin) : _servo(pin)
-{
- _servo.period_ms(20);
-}
-
-Servo::~Servo(void)
-{
-
-}
-
-void Servo::write(unsigned char degree)
-{
- convert(degree);
- _servo.pulsewidth_us(pulse);
-}
-
-void Servo::convert(unsigned char degree)
-{
- // 0~180 degree correspond to 500~2500
- pulse = degree * 11 + 500;
-}
--- a/Servo.h Tue Sep 05 06:20:07 2017 +0000
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,40 +0,0 @@
-/*
-
-Copyright (c) 2012-2014 RedBearLab
-
-Permission is hereby granted, free of charge, to any person obtaining a copy of this software
-and associated documentation files (the "Software"), to deal in the Software without restriction,
-including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense,
-and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so,
-subject to the following conditions:
-The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
-
-THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
-INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
-PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE
-FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
-ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
-
-*/
-
-#ifndef _SERVO_H
-#define _SERVO_H
-
-#include "mbed.h"
-
-class Servo
-{
-public:
- Servo(PinName pin);
- ~Servo(void);
-
- void write(unsigned char degree);
-
-private:
- void convert(unsigned char degree);
-
- PwmOut _servo;
- unsigned int pulse;
-};
-
-#endif
\ No newline at end of file
--- a/main.cpp Tue Sep 05 06:20:07 2017 +0000
+++ b/main.cpp Thu Oct 19 11:59:32 2017 +0000
@@ -34,6 +34,16 @@
#include "ble/BLE.h"
#include "ADXL362.h"
+#include "ble/services/UARTService.h"
+
+#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. */
+
+#if NEED_CONSOLE_OUTPUT
+#define DEBUG(...) { printf(__VA_ARGS__); }
+#else
+#define DEBUG(...) /* nothing */
+#endif /* #if NEED_CONSOLE_OUTPUT */
//------------------------------------------------------------
//Definition
@@ -46,10 +56,10 @@
//#define ANALOG_IN_PIN P0_4
//Set SPI Pin
-#define CS P0_10
-#define MOSI P0_9
-#define MISO P0_11
-#define SCK P0_8
+#define CS P0_8
+#define MOSI P0_5
+#define MISO P0_6
+#define SCK P0_7
//------------------------------------------------------------
@@ -58,6 +68,7 @@
BLE ble;
DigitalOut LED_SET(DIGITAL_OUT_PIN);
//AnalogIn ANALOG(ANALOG_IN_PIN);
+UARTService *uartServicePtr;
//SPI pin setting and change header file.(see ADXL362.h line185)
ADXL362 adxl362(CS, MOSI, MISO, SCK);
@@ -93,6 +104,15 @@
ble.startAdvertising();
}
+void onDataWritten(const GattWriteCallbackParams *params)
+{
+ if ((uartServicePtr != NULL) && (params->handle == uartServicePtr->getTXCharacteristicHandle())) {
+ uint16_t bytesRead = params->len;
+ DEBUG("received %u bytes\n\r", bytesRead);
+ ble.updateCharacteristicValue(uartServicePtr->getRXCharacteristicHandle(), params->data, bytesRead);
+ }
+}
+
//======================================================================
//onDataWritten
@@ -164,7 +184,9 @@
Ticker ticker;
ticker.attach_us(m_status_check_handle, TICKER_TIME);
+
//BLE init
+ DEBUG("Initialising the nRF51822\n\r");
ble.init();
//EventListener
@@ -198,6 +220,9 @@
//Start Advertising
ble.startAdvertising();
+ UARTService uartService(ble);
+ uartServicePtr = &uartService;
+
//------------------------------------------------------------
//Loop
//------------------------------------------------------------
