-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
19 changed files
with
395 additions
and
213 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,111 @@ | ||
/* | ||
* Bluetooth LE Remote | ||
* | ||
* Copyright (C)2016 Laurentiu Badea | ||
* | ||
* This file may be redistributed under the terms of the MIT license. | ||
* A copy of this license has been included with this distribution in the file LICENSE. | ||
*/ | ||
|
||
#include "ble_remote.h" | ||
|
||
#define PACKET_BUTTON_LEN (5) | ||
#define READ_BUFSIZE (20) | ||
|
||
#define BUTTON_ID(code) (code & 0x0f) | ||
#define IS_PRESSED(code) (code >> 4) | ||
|
||
BLERemote::BLERemote(Adafruit_BluefruitLE_SPI& ble) | ||
:ble(ble) | ||
{} | ||
|
||
void BLERemote::init(void){ | ||
if (ble.isConnected()){ | ||
if (!active){ | ||
ble.setMode(BLUEFRUIT_MODE_DATA); | ||
active = true; | ||
Serial.println("Connected"); | ||
} | ||
} else { | ||
active = false; | ||
} | ||
} | ||
|
||
unsigned BLERemote::read(void){ | ||
unsigned event = EVENT_NONE; | ||
|
||
uint8_t buttonCode = readButtonCode(); | ||
|
||
if (IS_PRESSED(buttonCode)){ | ||
switch (BUTTON_ID(buttonCode)){ | ||
case 1: | ||
event |= EVENT_OK; | ||
break; | ||
case 3: | ||
event |= EVENT_CANCEL; | ||
break; | ||
case 5: | ||
event |= EVENT_UP; | ||
break; | ||
case 6: | ||
event |= EVENT_DOWN; | ||
break; | ||
case 7: | ||
event |= EVENT_LEFT; | ||
break; | ||
case 8: | ||
event |= EVENT_RIGHT; | ||
break; | ||
} | ||
|
||
next_repeat_time = millis() + REPEAT_DELAY; | ||
last_event = event; | ||
|
||
} else if (BUTTON_ID(buttonCode)){ // button depressed | ||
last_event = EVENT_NONE; | ||
|
||
} else if (last_event){ // button currently remaining pressed | ||
if (millis() > next_repeat_time && !isEventOk(last_event) && !isEventCancel(last_event)){ | ||
event = last_event; | ||
next_repeat_time = millis() + REPEAT_INTERVAL; | ||
} | ||
} | ||
return event; | ||
} | ||
|
||
/* | ||
* Read the controller messages. | ||
* Returns a byte which contains button number in low nibble, and pressed state in the high. | ||
*/ | ||
uint8_t BLERemote::readButtonCode(void){ | ||
static uint8_t packetbuffer[READ_BUFSIZE]; | ||
|
||
init(); | ||
if (!active){ | ||
return 0; | ||
} | ||
|
||
int i = 0; | ||
while (ble.available() && i < PACKET_BUTTON_LEN){ | ||
char c = ble.read(); | ||
if (i == 0 and c != '!'){ | ||
continue; | ||
} | ||
packetbuffer[i++] = c; | ||
} | ||
|
||
if (!i || packetbuffer[1] != 'B'){ | ||
return 0; | ||
} | ||
|
||
// Verify checksum | ||
uint8_t checksum = 1; | ||
for (; i > 0;){ | ||
checksum += packetbuffer[--i]; | ||
} | ||
if (checksum){ // checksum mismatch | ||
return 0; | ||
} | ||
|
||
return (packetbuffer[2] - '0') + (packetbuffer[3] - '0' << 4); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
/* | ||
* Bluetooth LE Remote | ||
* | ||
* Copyright (C)2016 Laurentiu Badea | ||
* | ||
* This file may be redistributed under the terms of the MIT license. | ||
* A copy of this license has been included with this distribution in the file LICENSE. | ||
*/ | ||
#ifndef BLE_REMOTE_H_ | ||
#define BLE_REMOTE_H_ | ||
|
||
#include <Adafruit_BluefruitLE_SPI.h> | ||
#include "hid.h" | ||
|
||
class BLERemote : public HID { | ||
private: | ||
Adafruit_BluefruitLE_SPI& ble; | ||
uint8_t readButtonCode(void); | ||
unsigned last_event = EVENT_NONE; | ||
unsigned next_repeat_time; | ||
|
||
public: | ||
bool active = false; | ||
BLERemote(Adafruit_BluefruitLE_SPI& ble); | ||
void init(void); | ||
unsigned read(void) override; | ||
}; | ||
|
||
#endif /* BLE_REMOTE_H_ */ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
/* | ||
* Pano Controller Master Configuration File | ||
*/ | ||
|
||
#if defined(__AVR__) | ||
#error "AVR is not supported" | ||
|
||
#elif !defined(ARDUINO_SAMD_FEATHER_M0) | ||
#include "config_teensy.h" | ||
|
||
#else | ||
#include "config_feather_m0.h" | ||
#endif | ||
|
||
// Address of I2C OLED display. If screen looks scaled edit Adafruit_SSD1306.h | ||
// and pick SSD1306_128_64 or SSD1306_128_32 that matches display type. | ||
#define DISPLAY_I2C_ADDRESS 0x3C | ||
#define OLED_RESET 12 | ||
#define TEXT_SIZE 1 | ||
#define DISPLAY_ROWS SSD1306_LCDHEIGHT/8/TEXT_SIZE | ||
#define DISPLAY_COLS SSD1306_LCDWIDTH/6/TEXT_SIZE | ||
|
||
// Battery monitoring settings | ||
#define VCC 3300 | ||
#define LOW_BATTERY 7000 | ||
// R1/R2 is the voltage divisor in Ω (GND-R1-A0-R2-Vin) | ||
// measure resistors and enter actual values for a more accurate voltage | ||
#define BATT_R1 9980 | ||
#define BATT_R2 46500 | ||
#define BATT_RANGE (VCC * (BATT_R1 + BATT_R2) / BATT_R1) | ||
|
||
// MPU (accel/gyro) | ||
#define MPU_I2C_ADDRESS 0x68 | ||
|
||
// Stepper motors steps per revolution | ||
#define MOTOR_STEPS 200 |
Oops, something went wrong.