forked from adafruit/Adafruit_Microbit
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Calliope_Arduino.h
113 lines (96 loc) · 3.37 KB
/
Calliope_Arduino.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
/*!
* @file Calliope.h
*/
#ifndef _Calliope_H_
#define _Calliope_H_
#include <Adafruit_GFX.h>
#include <Arduino.h>
#include <Fonts/TomThumb.h>
#if defined(S110) || defined(S130)
#define SD_SELECTED
#include <BLEPeripheral.h>
#endif
#define LED_ON 1 //!< Used to make turning the LED on more readable
#define LED_OFF 0 //!< Used to make turning the LED off more readable
void IRQ_MATRIX_HANDLER(void); //!< Matrix interrupt request handler
/** Class to create Adafruit_GFX interface for 5x5 matrix of Calliope mini */
class Calliope_Matrix : public Adafruit_GFX {
public:
Calliope_Matrix();
~Calliope_Matrix(void);
boolean begin(void);
void drawPixel(int16_t x, int16_t y, uint16_t color),
fillScreen(uint16_t color), clear(void), rowHandler(void);
void show(const uint8_t bitmap[]);
void scrollText(char *string, uint8_t stepdelay = 150);
void print(char *string);
void print(int32_t i);
void print(int i);
void print(double f, int precision = 3);
static const uint8_t EMPTYHEART[5], ///< an empty heart icon
HEART[5], ///< full heart icon
NO[5], ///< X icon
YES[5], ///< Check icon
CALLIOPE_SMILE[5]; ///< smile icon
private:
void startTimer();
#if defined(NRF51)
uint8_t matrix_buffer[3][9];
#elif defined(NRF52833_XXAA)
uint8_t matrix_buffer[5][5];
#endif
};
#ifdef SD_SELECTED
/** Class to use Nordic UART service as a Stream object on Calliope mini */
class Calliope_BLESerial : public BLEPeripheral, public Stream {
public:
Calliope_BLESerial(unsigned char req = BLE_DEFAULT_REQ,
unsigned char rdy = BLE_DEFAULT_RDY,
unsigned char rst = BLE_DEFAULT_RST);
void begin(...);
void poll();
void end();
virtual int available(void);
virtual int peek(void);
virtual int read(void);
virtual void flush(void);
virtual size_t write(uint8_t byte);
using Print::write;
virtual operator bool();
private:
unsigned long _flushed;
static Calliope_BLESerial *_instance;
size_t _rxHead;
size_t _rxTail;
size_t _rxCount() const;
uint8_t _rxBuffer[BLE_ATTRIBUTE_MAX_VALUE_LENGTH];
size_t _txCount;
uint8_t _txBuffer[BLE_ATTRIBUTE_MAX_VALUE_LENGTH];
BLEService _uartService = BLEService("6E400001-B5A3-F393-E0A9-E50E24DCCA9E");
BLEDescriptor _uartNameDescriptor = BLEDescriptor("2901", "UART");
BLECharacteristic _rxCharacteristic = BLECharacteristic(
"6E400002-B5A3-F393-E0A9-E50E24DCCA9E", BLEWriteWithoutResponse,
BLE_ATTRIBUTE_MAX_VALUE_LENGTH);
BLEDescriptor _rxNameDescriptor =
BLEDescriptor("2901", "RX - Receive Data (Write)");
BLECharacteristic _txCharacteristic =
BLECharacteristic("6E400003-B5A3-F393-E0A9-E50E24DCCA9E", BLENotify,
BLE_ATTRIBUTE_MAX_VALUE_LENGTH);
BLEDescriptor _txNameDescriptor =
BLEDescriptor("2901", "TX - Transfer Data (Notify)");
void _received(const uint8_t *data, size_t size);
static void _received(BLECentral & /*central*/,
BLECharacteristic &rxCharacteristic);
};
#endif
/** Class to create hardware interface to BLE/matrix of Calliope mini */
class Calliope {
public:
Calliope_Matrix matrix; ///< 5x5 graphical matrix
#ifdef SD_SELECTED
Calliope_BLESerial BTLESerial; ///< Nordic UART service connection
uint8_t getDieTemp(void);
#endif
void begin(void);
};
#endif