C++ Pixels Library For Windows
Enable communications with Pixels dice using Bluetooth Low Energy.
Loading...
Searching...
No Matches
PixelScanner.h
Go to the documentation of this file.
1
6#pragma once
7
8#include <functional>
9#include <memory>
10#include <vector>
11#include <mutex>
12
14{
15 class Scanner;
16 class ScannedPeripheral;
17}
18
19namespace Systemic::Pixels
20{
21 class ScannedPixel;
22
29 {
30 public:
32 using ScannedPixelListener = std::function<void(const std::shared_ptr<const ScannedPixel>&)>;
33
34 private:
35 // Listener given by user
36 const ScannedPixelListener _listener;
37 // Bluetooth scanner instance
38 std::shared_ptr<Systemic::BluetoothLE::Scanner> _scanner{};
39 // List of scanned pixels
40 std::vector<std::shared_ptr<const ScannedPixel>> _scannedPixels{};
41
42 // Mutex used to modify list of scanned Pixels
43 std::recursive_mutex _mutex{};
44
45 public:
52 explicit PixelScanner(const ScannedPixelListener& listener);
53
56
59 {
60 return _scanner != nullptr;
61 }
62
68 void copyScannedPixels(std::vector<std::shared_ptr<const ScannedPixel>>& outScannedPixels)
69 {
70 std::lock_guard lock{ _mutex };
71
72 outScannedPixels.reserve(outScannedPixels.size() + _scannedPixels.size());
73 for (auto& p : _scannedPixels)
74 {
75 outScannedPixels.emplace_back(p);
76 }
77 }
78
80 void start();
81
83 void stop();
84
86 void clear();
87 };
88}
Represents a Bluetooth scanner for Pixels dice.
Definition: PixelScanner.h:29
void stop()
Stops scanning for Pixels.
void copyScannedPixels(std::vector< std::shared_ptr< const ScannedPixel > > &outScannedPixels)
Copy the list of scanned Pixels to the given std::vector.
Definition: PixelScanner.h:68
std::function< void(const std::shared_ptr< const ScannedPixel > &)> ScannedPixelListener
Signature of a scanned Pixel listener.
Definition: PixelScanner.h:32
bool isScanning()
Indicates whether a scan for Pixels dice is currently running.
Definition: PixelScanner.h:58
PixelScanner(const ScannedPixelListener &listener)
Initializes a new instance of PixelScanner with the given listener.
void start()
Starts a Bluetooth scan for Pixels.
~PixelScanner()
Default destructor.
void clear()
Clear the list of scanned Pixels.
A collection of C++ classes that provides a simplified access to Bluetooth Low Energy peripherals.
Definition: BleTypes.h:38
A collection of C++ classes and types to scan for and connect to Pixels dice.
Definition: Helpers.h:13