-
Notifications
You must be signed in to change notification settings - Fork 12
/
Copy pathOpenBCI_Wifi_Master.h
104 lines (84 loc) · 2.46 KB
/
OpenBCI_Wifi_Master.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
/**
* Name: OpenBCI_Radio.h
* Date: 3/15/2016
* Purpose: This is the header file for the OpenBCI radios. Let us define two
* over arching paradigms: Host and Device, where:
* Host is connected to PC via USB VCP (FTDI).
* Device is connectedd to uC (PIC32MX250F128B with UDB32-MX2-DIP).
*
* Author: Push The World LLC (AJ Keller)
* Much credit must also go to Joel Murphy who with Conor Russomanno and Leif
* Percifield created the original OpenBCI_32bit_Device.ino and
* OpenBCI_32bit_Host.ino files in the Summer of 2014. Much of this code base
* is inspired directly from their work.
*/
#ifndef __OpenBCI_Wifi_Master__
#define __OpenBCI_Wifi_Master__
#include <Arduino.h>
#include "OpenBCI_Wifi_Master_Definitions.h"
#if defined(__PIC32MX2XX__) // Cyton
#include <DSPI.h>
#define USE_SERIAL Serial0
#define WIFI_RESET 18
#define WIFI_SS 13
#else // Ganglion
#include <SPI.h>
#define USE_SERIAL Serial
#define WIFI_SS 24 // Wifi Chip Select
#define WIFI_RESET 4
#endif
class OpenBCI_Wifi_Master_Class {
public:
OpenBCI_Wifi_Master_Class();
boolean attach(void);
boolean begin(void);
boolean begin(boolean, boolean);
void bufferTxClear(void);
void bufferRxClear(void);
void csHigh(void);
void csLow(void);
void flushBufferTx(void);
char getChar(void);
boolean hasData(void);
void loop(void);
void readData(void);
uint32_t readStatus(void);
boolean remove(void);
void reset(void);
void sendGains(uint8_t, uint8_t *);
void sendStringMulti(char);
void sendStringMulti(const char *);
void sendStringLast();
void sendStringLast(const char *);
boolean smell(void);
boolean storeByteBufTx(uint8_t);
void writeData(uint8_t *, size_t);
// VARIABLES
// wifi variables
boolean debug;
boolean present;
boolean rx;
boolean tx;
boolean sentGains;
char bufferRx[WIFI_SPI_MAX_PACKET_SIZE];
char bufferReadFrom[WIFI_SPI_MAX_PACKET_SIZE];
uint8_t bufferTx[WIFI_SPI_MAX_PACKET_SIZE];
uint8_t bufferTxPosition;
#if defined(__PIC32MX2XX__)
DSPI0 spi;
#endif
private:
byte xfer(byte _data);
void bufferReadFromClear(void);
boolean toggleWifiCS;
boolean toggleWifiReset;
boolean soughtWifiShield;
boolean seekingWifi;
int attachAttempts;
unsigned long timeOfLastRead;
unsigned long timeOfWifiToggle;
unsigned long timeOfWifiStart;
};
// Very important, major key to success #christmas
extern OpenBCI_Wifi_Master_Class wifi;
#endif // OPENBCI_Wifi_H