rename to Bluefruit52Lib
This commit is contained in:
1 parent
4c7b6a2927
commit
f9828071fa
30 files changed
No files matched your search
@@ -0,0 +1,172 @@
|
||||
/*********************************************************************
|
||||
This is an example for our nRF51822 based Bluefruit LE modules
|
||||
|
||||
Pick one up today in the adafruit shop!
|
||||
|
||||
Adafruit invests time and resources providing this open source code,
|
||||
please support Adafruit and open-source hardware by purchasing
|
||||
products from Adafruit!
|
||||
|
||||
MIT license, check LICENSE for more information
|
||||
All text above, and the splash screen below must be included in
|
||||
any redistribution
|
||||
*********************************************************************/
|
||||
|
||||
#include <bluefruit.h>
|
||||
|
||||
BLEUart bleuart;
|
||||
|
||||
// function prototypes over in packetparser.cpp
|
||||
uint8_t readPacket(Adafruit_BLE *ble, uint16_t timeout);
|
||||
float parsefloat(uint8_t *buffer);
|
||||
void printHex(const uint8_t * data, const uint32_t numBytes);
|
||||
|
||||
// the packet buffer
|
||||
extern uint8_t packetbuffer[];
|
||||
|
||||
|
||||
/**************************************************************************/
|
||||
/*!
|
||||
@brief Sets up the HW an the BLE module (this function is called
|
||||
automatically on startup)
|
||||
*/
|
||||
/**************************************************************************/
|
||||
void setup(void)
|
||||
{
|
||||
Serial.begin(115200);
|
||||
Serial.println(F("Adafruit Bluefruit App Controller Example"));
|
||||
Serial.println(F("-----------------------------------------"));
|
||||
|
||||
Bluefruit.begin();
|
||||
Bluefruit.setName("Bluefruit");
|
||||
|
||||
// Configure and Start BLE Uart Service
|
||||
bleuart.start();
|
||||
|
||||
// Set up Advertising Packet
|
||||
setupAdv();
|
||||
|
||||
// Start Advertising
|
||||
Bluefruit.startAdvertising();
|
||||
}
|
||||
|
||||
void setupAdv(void)
|
||||
{
|
||||
//Bluefruit.addAdvTxPower();
|
||||
Bluefruit.addAdvFlags(BLE_GAP_ADV_FLAGS_LE_ONLY_GENERAL_DISC_MODE);
|
||||
Bluefruit.addAdvTxPower();
|
||||
|
||||
// Include bleuart 128-bit uuid
|
||||
Bluefruit.addAdvService(bleuart);
|
||||
|
||||
// There is no room for Name in Advertising packet
|
||||
// Use Scan response for Name
|
||||
Bluefruit.addScanName();
|
||||
}
|
||||
|
||||
/**************************************************************************/
|
||||
/*!
|
||||
@brief Constantly poll for new command or response data
|
||||
*/
|
||||
/**************************************************************************/
|
||||
void loop(void)
|
||||
{
|
||||
Bluefruit.poll();
|
||||
|
||||
/* Wait for new data to arrive */
|
||||
uint8_t len = readPacket(&ble, BLE_READPACKET_TIMEOUT);
|
||||
if (len == 0) return;
|
||||
|
||||
/* Got a packet! */
|
||||
// printHex(packetbuffer, len);
|
||||
|
||||
// Color
|
||||
if (packetbuffer[1] == 'C') {
|
||||
uint8_t red = packetbuffer[2];
|
||||
uint8_t green = packetbuffer[3];
|
||||
uint8_t blue = packetbuffer[4];
|
||||
Serial.print ("RGB #");
|
||||
if (red < 0x10) Serial.print("0");
|
||||
Serial.print(red, HEX);
|
||||
if (green < 0x10) Serial.print("0");
|
||||
Serial.print(green, HEX);
|
||||
if (blue < 0x10) Serial.print("0");
|
||||
Serial.println(blue, HEX);
|
||||
}
|
||||
|
||||
// Buttons
|
||||
if (packetbuffer[1] == 'B') {
|
||||
uint8_t buttnum = packetbuffer[2] - '0';
|
||||
boolean pressed = packetbuffer[3] - '0';
|
||||
Serial.print ("Button "); Serial.print(buttnum);
|
||||
if (pressed) {
|
||||
Serial.println(" pressed");
|
||||
} else {
|
||||
Serial.println(" released");
|
||||
}
|
||||
}
|
||||
|
||||
// GPS Location
|
||||
if (packetbuffer[1] == 'L') {
|
||||
float lat, lon, alt;
|
||||
lat = parsefloat(packetbuffer+2);
|
||||
lon = parsefloat(packetbuffer+6);
|
||||
alt = parsefloat(packetbuffer+10);
|
||||
Serial.print("GPS Location\t");
|
||||
Serial.print("Lat: "); Serial.print(lat, 4); // 4 digits of precision!
|
||||
Serial.print('\t');
|
||||
Serial.print("Lon: "); Serial.print(lon, 4); // 4 digits of precision!
|
||||
Serial.print('\t');
|
||||
Serial.print(alt, 4); Serial.println(" meters");
|
||||
}
|
||||
|
||||
// Accelerometer
|
||||
if (packetbuffer[1] == 'A') {
|
||||
float x, y, z;
|
||||
x = parsefloat(packetbuffer+2);
|
||||
y = parsefloat(packetbuffer+6);
|
||||
z = parsefloat(packetbuffer+10);
|
||||
Serial.print("Accel\t");
|
||||
Serial.print(x); Serial.print('\t');
|
||||
Serial.print(y); Serial.print('\t');
|
||||
Serial.print(z); Serial.println();
|
||||
}
|
||||
|
||||
// Magnetometer
|
||||
if (packetbuffer[1] == 'M') {
|
||||
float x, y, z;
|
||||
x = parsefloat(packetbuffer+2);
|
||||
y = parsefloat(packetbuffer+6);
|
||||
z = parsefloat(packetbuffer+10);
|
||||
Serial.print("Mag\t");
|
||||
Serial.print(x); Serial.print('\t');
|
||||
Serial.print(y); Serial.print('\t');
|
||||
Serial.print(z); Serial.println();
|
||||
}
|
||||
|
||||
// Gyroscope
|
||||
if (packetbuffer[1] == 'G') {
|
||||
float x, y, z;
|
||||
x = parsefloat(packetbuffer+2);
|
||||
y = parsefloat(packetbuffer+6);
|
||||
z = parsefloat(packetbuffer+10);
|
||||
Serial.print("Gyro\t");
|
||||
Serial.print(x); Serial.print('\t');
|
||||
Serial.print(y); Serial.print('\t');
|
||||
Serial.print(z); Serial.println();
|
||||
}
|
||||
|
||||
// Quaternions
|
||||
if (packetbuffer[1] == 'Q') {
|
||||
float x, y, z, w;
|
||||
x = parsefloat(packetbuffer+2);
|
||||
y = parsefloat(packetbuffer+6);
|
||||
z = parsefloat(packetbuffer+10);
|
||||
w = parsefloat(packetbuffer+14);
|
||||
Serial.print("Quat\t");
|
||||
Serial.print(x); Serial.print('\t');
|
||||
Serial.print(y); Serial.print('\t');
|
||||
Serial.print(z); Serial.print('\t');
|
||||
Serial.print(w); Serial.println();
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user