C++ Pixels Library For Windows
Enable communications with Pixels dice using Bluetooth Low Energy.
Loading...
Searching...
No Matches
Helpers.h
Go to the documentation of this file.
1
6#pragma once
7
8#include <cstdint>
9#include <chrono>
10#include "PixelTypes.h"
11
12namespace Systemic::Pixels::Helpers
13{
19 inline DieType getDieType(int ledCount)
20 {
21 // For now we infer the die type from the number of LEDs, but eventually
22 // that value will be part of identification data.
23 switch (ledCount)
24 {
25 case 4:
26 return DieType::D4;
27 case 6:
28 return DieType::D6;
29 case 8:
30 return DieType::D8;
31 case 10:
32 return DieType::D10;
33 case 12:
34 return DieType::D12;
35 case 0: // Defaults unknown die to D20
36 case 20:
37 return DieType::D20;
38 case 21:
39 return DieType::D6Pipped;
40 default:
41 // Fudge has 6 LEDs actually, but let's use it as our default for now
42 return DieType::D6Fudge;
43 }
44 }
45
51 inline int getFaceCount(DieType dieType)
52 {
53 switch (dieType)
54 {
55 default:
56 case DieType::D20:
57 return 20;
58 case DieType::D12:
59 return 12;
60 case DieType::D10:
61 return 10;
62 case DieType::D8:
63 return 8;
64 case DieType::D6:
65 case DieType::D6Pipped:
66 case DieType::D6Fudge:
67 return 6;
68 case DieType::D4:
69 return 4;
70 }
71 }
72
78 inline bool isPixelChargingOrDone(PixelBatteryState batteryState)
79 {
80 return batteryState == PixelBatteryState::Charging || batteryState == PixelBatteryState::Done;
81 }
82
89 inline std::chrono::system_clock::time_point getFirmwareDate(uint32_t buildTimestamp)
90 {
91 return std::chrono::system_clock::time_point{ std::chrono::seconds{ buildTimestamp } };
92 }
93}
DieType getDieType(int ledCount)
Returns the die type based on the number of LEDs.
Definition: Helpers.h:19
bool isPixelChargingOrDone(PixelBatteryState batteryState)
Definition: Helpers.h:78
int getFaceCount(DieType dieType)
Returns the number of faces based on the die type.
Definition: Helpers.h:51
std::chrono::system_clock::time_point getFirmwareDate(uint32_t buildTimestamp)
Converts a UNIX timestamp in seconds to a time_point. Use this function to get the date of a Pixels f...
Definition: Helpers.h:89
Common types used across the Systemic::Pixel namespace.
PixelBatteryState
The different possible battery charging states.
Definition: PixelTypes.h:64
@ Charging
Battery is currently recharging.
@ Done
Battery is full and finished charging.
DieType
The different types of dice.
Definition: PixelTypes.h:87