Code Monkey home page Code Monkey logo

feeling-blue-cpp's Introduction

feeling-blue-logo

C++ library for BluetoothLE usage on MacOS or (soon) Windows.

feeling-blue was created because of a lack of resources for the non-expert on how to connect to a bluetooth device using C++. The API was carefully designed to be easy-to-use, yet feature-rich so you can take advantage of your bluetooth peripherals without learning the nuisances of bluetoothLE.

Full documentation here

Build Status license

Table of Contents


Features

  • Blocking & non-blocking API. Calls to find services, characteristics, etc block the calling thread until the process is complete.
  • Supports connecting to multiple bluetooth devices.
  • User-defined event handlers for device notifications.
  • Simple and straightfoward API.

Installation

Download and build

$ git clone https://github.com/seanngpack/feeling-blue-cpp
$ cd feeling-blue-cpp
$ mkdir build
$ cd build
$ cmake .. // use -DVERBOSE_MODE=OFF to turn off all console logging from feeling-blue
$ sudo make install

Add library to your project, you just need to add find_package() and target_link_libraries().

  • Example of cmakelists.txt in your project:
cmake_minimum_required(VERSION 3.17)
project(yourProject)

set(CMAKE_CXX_STANDARD 17)

find_package(feeling-blue REQUIRED)

add_executable(yourProject main.cpp)
target_link_libraries(yourProject PUBLIC feeling-blue)

Time to start using it!

Below is a brief example that finds a device and reads, writes, and sets notifications to it.

main.cpp

void print_temp(std::vector<std::byte> data) {
    std::cout << "the size of the data is: " << data.size() << std::endl;
    for (auto const &b : data) {
        std::cout << (int)b << std::endl;
    }
    std::cout << "the current temperature is: " << bytes_to_int(data) << "degrees" << std::endl;
}

#include "feeling-blue/feeling-blue.h"

int main() {
    std::unique_ptr<bluetooth::Central> central = std::make_unique<bluetooth::Central>();
    central->start_bluetooth();
    std::shared_ptr<bluetooth::Peripheral> temperature_device = central->find_peripheral("NameOfYourDevice");
    std::shared_ptr<bluetooth::Service> service = temperature_device->find_service("someUUID");
    std::shared_ptr<bluetooth::Characteristic> current_temp_char = service->find_characteristic("someUUID");
    std::shared_ptr<bluetooth::Characteristic> units_char = service->find_characteristic("someUUID");

    current_temp_char->set_notify(print_temp); // will call print_temp() whenever device notifies
    
    std::string units = units_char->read<std::string>();
    std::cout << "the current temperature unit is: " << units << std::endl
    units_char->write_without_response<std::string>("kelvin"); // set new temperature unit to device
    units = units_char->read<std::string>();
    std::cout << "the new temperature unit is: " << units << std::endl

    while (true) {
        ...
    }
  
    return 0;
}

Go to the documentation for more comprehensive examples!

Upcoming features:

  • methods to get status of peripherals, characteristics, etc
  • Windows support

Help & bug reports

Just open a new issue!

Contributing

  1. Fork the repo
  2. Clone your fork somewhere on your computer git clone https://github.com/<your-username>/pcl.git
  3. cd feeling-blue-cpp
  4. add upstream to original repo git remote add upstream https://github.com/seanngpack/feeling-blue-cpp.git
  5. implement your new changes on your fork
  6. pull from upstream master to make sure you are up to date with the newest release of feeling-blue-cpp
  7. open pull request

feeling-blue-cpp's People

Contributors

seanngpack avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.