From 6310ed5243152c6760c2eec31b2f23f7b73fe803 Mon Sep 17 00:00:00 2001 From: Tim Date: Sat, 10 Dec 2016 16:39:55 -0500 Subject: [PATCH] Cleanup and license the dongle drivers code --- mbed-dongle-firmware/drivers/BNO055.cpp | 485 ---------------- mbed-dongle-firmware/drivers/BNO055.h | 539 ------------------ mbed-dongle-firmware/drivers/analog_button.h | 23 +- mbed-dongle-firmware/drivers/at42qt1070.cpp | 329 ----------- mbed-dongle-firmware/drivers/at42qt1070.h | 378 ------------ mbed-dongle-firmware/drivers/flex_sensor.cpp | 66 --- mbed-dongle-firmware/drivers/flex_sensor.h | 103 +--- .../drivers/glove_sensors.cpp | 23 +- mbed-dongle-firmware/drivers/glove_sensors.h | 26 +- mbed-dongle-firmware/drivers/imu.cpp | 87 --- mbed-dongle-firmware/drivers/imu.h | 108 +--- mbed-dongle-firmware/drivers/scanner.h | 24 +- mbed-dongle-firmware/drivers/serial_com.h | 24 +- mbed-dongle-firmware/drivers/touch_sensor.cpp | 169 ------ mbed-dongle-firmware/drivers/touch_sensor.h | 208 +------ .../drivers/translate_task.cpp | 26 +- mbed-dongle-firmware/drivers/translate_task.h | 41 +- mbed-dongle-firmware/drivers/translator.cpp | 35 +- mbed-dongle-firmware/drivers/translator.h | 40 +- 19 files changed, 289 insertions(+), 2445 deletions(-) delete mode 100644 mbed-dongle-firmware/drivers/BNO055.cpp delete mode 100644 mbed-dongle-firmware/drivers/BNO055.h delete mode 100644 mbed-dongle-firmware/drivers/at42qt1070.cpp delete mode 100644 mbed-dongle-firmware/drivers/at42qt1070.h delete mode 100644 mbed-dongle-firmware/drivers/flex_sensor.cpp delete mode 100644 mbed-dongle-firmware/drivers/imu.cpp delete mode 100644 mbed-dongle-firmware/drivers/touch_sensor.cpp diff --git a/mbed-dongle-firmware/drivers/BNO055.cpp b/mbed-dongle-firmware/drivers/BNO055.cpp deleted file mode 100644 index 26becb7..0000000 --- a/mbed-dongle-firmware/drivers/BNO055.cpp +++ /dev/null @@ -1,485 +0,0 @@ -/* - * mbed library program - * BNO055 Intelligent 9-axis absolute orientation sensor - * by Bosch Sensortec - * - * Copyright (c) 2015 Kenji Arai / JH1PJL - * http://www.page.sannet.ne.jp/kenjia/index.html - * http://mbed.org/users/kenjiArai/ - * Created: March 30th, 2015 - * Revised: April 16th, 2015 - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, - * INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE - * AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, - * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - */ - -#include "mbed.h" -#include "BNO055.h" - -BNO055::BNO055 (PinName p_sda, PinName p_scl, PinName p_reset, uint8_t addr, uint8_t mode): - _i2c(p_sda, p_scl), _res(p_reset) -{ - chip_addr = addr; - chip_mode = mode; - initialize (); -} - -BNO055::BNO055 (PinName p_sda, PinName p_scl, PinName p_reset) : - _i2c(p_sda, p_scl), _res(p_reset) -{ - chip_addr = BNO055_G_CHIP_ADDR; - chip_mode = MODE_NDOF; - initialize (); -} - -BNO055::BNO055 (I2C& p_i2c, PinName p_reset, uint8_t addr, uint8_t mode) : - _i2c(p_i2c), _res(p_reset) -{ - chip_addr = addr; - chip_mode = mode; - initialize (); -} - -BNO055::BNO055 (I2C& p_i2c, PinName p_reset) : - _i2c(p_i2c), _res(p_reset) -{ - chip_addr = BNO055_G_CHIP_ADDR; - chip_mode = MODE_NDOF; - initialize (); -} - -/////////////// Read data & normalize ///////////////////// -void BNO055::get_Euler_Angles(BNO055_EULER_TypeDef *el) -{ - uint8_t deg_or_rad; - int16_t h,p,r; - - select_page(0); - dt[0] = BNO055_UNIT_SEL; - _i2c.write(chip_addr, dt, 1, true); - _i2c.read(chip_addr, dt, 1, false); - if (dt[0] & 0x04) { - deg_or_rad = 1; // Radian - } else { - deg_or_rad = 0; // Degree - } - dt[0] = BNO055_EULER_H_LSB; - _i2c.write(chip_addr, dt, 1, true); - _i2c.read(chip_addr, dt, 6, false); - h = dt[1] << 8 | dt[0]; - p = dt[3] << 8 | dt[2]; - r = dt[5] << 8 | dt[4]; - if (deg_or_rad) { - el->h = (double)h / 900; - el->p = (double)p / 900; - el->r = (double)r / 900; - } else { - el->h = (double)h / 16; - el->p = (double)p / 16; - el->r = (double)r / 16; - } -} - -void BNO055::get_quaternion(BNO055_QUATERNION_TypeDef *qua) -{ - select_page(0); - dt[0] = BNO055_QUATERNION_W_LSB; - _i2c.write(chip_addr, dt, 1, true); - _i2c.read(chip_addr, dt, 8, false); - qua->w = dt[1] << 8 | dt[0]; - qua->x = dt[3] << 8 | dt[2]; - qua->y = dt[5] << 8 | dt[4]; - qua->z = dt[7] << 8 | dt[6]; -} - -void BNO055::get_linear_accel(BNO055_LIN_ACC_TypeDef *la) -{ - uint8_t ms2_or_mg; - int16_t x,y,z; - - select_page(0); - dt[0] = BNO055_UNIT_SEL; - _i2c.write(chip_addr, dt, 1, true); - _i2c.read(chip_addr, dt, 1, false); - if (dt[0] & 0x01) { - ms2_or_mg = 1; // mg - } else { - ms2_or_mg = 0; // m/s*s - } - dt[0] = BNO055_LINEAR_ACC_X_LSB; - _i2c.write(chip_addr, dt, 1, true); - _i2c.read(chip_addr, dt, 6, false); - x = dt[1] << 8 | dt[0]; - y = dt[3] << 8 | dt[2]; - z = dt[5] << 8 | dt[4]; - if (ms2_or_mg) { - la->x = (double)x; - la->y = (double)y; - la->z = (double)z; - } else { - la->x = (double)x / 100; - la->y = (double)y / 100; - la->z = (double)z / 100; - } -} - -void BNO055::get_gravity(BNO055_GRAVITY_TypeDef *gr) -{ - uint8_t ms2_or_mg; - int16_t x,y,z; - - select_page(0); - dt[0] = BNO055_UNIT_SEL; - _i2c.write(chip_addr, dt, 1, true); - _i2c.read(chip_addr, dt, 1, false); - if (dt[0] & 0x01) { - ms2_or_mg = 1; // mg - } else { - ms2_or_mg = 0; // m/s*s - } - dt[0] = BNO055_GRAVITY_X_LSB; - _i2c.write(chip_addr, dt, 1, true); - _i2c.read(chip_addr, dt, 6, false); - x = dt[1] << 8 | dt[0]; - y = dt[3] << 8 | dt[2]; - z = dt[5] << 8 | dt[4]; - if (ms2_or_mg) { - gr->x = (double)x; - gr->y = (double)y; - gr->z = (double)z; - } else { - gr->x = (double)x / 100; - gr->y = (double)y / 100; - gr->z = (double)z / 100; - } -} - -void BNO055::get_chip_temperature(BNO055_TEMPERATURE_TypeDef *tmp) -{ - uint8_t c_or_f; - - select_page(0); - dt[0] = BNO055_UNIT_SEL; - _i2c.write(chip_addr, dt, 1, true); - _i2c.read(chip_addr, dt, 1, false); - if (dt[0] & 0x10) { - c_or_f = 1; // Fahrenheit - } else { - c_or_f = 0; // degrees Celsius - } - dt[0] = BNO055_TEMP_SOURCE; - dt[1] = 0; - _i2c.write(chip_addr, dt, 2, false); - wait_ms(1); // Do I need to wait? - dt[0] = BNO055_TEMP; - _i2c.write(chip_addr, dt, 1, true); - _i2c.read(chip_addr, dt, 1, false); - if (c_or_f) { - tmp->acc_chip = (int8_t)dt[0] * 2; - } else { - tmp->acc_chip = (int8_t)dt[0]; - } - dt[0] = BNO055_TEMP_SOURCE; - dt[1] = 1; - _i2c.write(chip_addr, dt, 2, false); - wait_ms(1); // Do I need to wait? - dt[0] = BNO055_TEMP; - _i2c.write(chip_addr, dt, 1, true); - _i2c.read(chip_addr, dt, 1, false); - if (c_or_f) { - tmp->gyr_chip = (int8_t)dt[0] * 2; - } else { - tmp->gyr_chip = (int8_t)dt[0]; - } -} - -/////////////// Initialize //////////////////////////////// -void BNO055::initialize (void) -{ - _res = 1; -#if defined(TARGET_STM32L152RE) - _i2c.frequency(100000); -#else - _i2c.frequency(400000); -#endif - page_flag = 0xff; - select_page(0); - // Check Acc & Mag & Gyro are available of not - check_id(); - // Set initial data - set_initial_dt_to_regs(); - // Unit selection - unit_selection(); - // Set fusion mode - change_fusion_mode(chip_mode); -} - -void BNO055::unit_selection(void) -{ - select_page(0); - dt[0] = BNO055_UNIT_SEL; - dt[1] = UNIT_ORI_WIN + UNIT_ACC_MSS + UNIT_GYR_DPS + UNIT_EULER_DEG + UNIT_TEMP_C; - _i2c.write(chip_addr, dt, 2, false); -} - -uint8_t BNO055::select_page(uint8_t page) -{ - if (page != page_flag){ - dt[0] = BNO055_PAGE_ID; - if (page == 1) { - dt[1] = 1; // select page 1 - } else { - dt[1] = 0; // select page 0 - } - - _i2c.write(chip_addr, dt, 2, false); - dt[0] = BNO055_PAGE_ID; - _i2c.write(chip_addr, dt, 1, true); - _i2c.read(chip_addr, dt, 1, false); - page_flag = dt[0]; - } - return page_flag; -} - -uint8_t BNO055::reset(void) -{ - _res = 0; - wait_ms(1); // Reset 1mS - _res = 1; - wait(0.7); // Need to wait at least 650mS -#if defined(TARGET_STM32L152RE) - _i2c.frequency(400000); -#else - _i2c.frequency(400000); -#endif - _i2c.stop(); - page_flag = 0xff; - select_page(0); - check_id(); - if (chip_id != I_AM_BNO055_CHIP){ - return 1; - } else { - initialize(); - return 0; - } -} - -////// Set initialize data to related registers /////////// -void BNO055::set_initial_dt_to_regs(void) -{ - // select_page(0); - // current setting is only used default values -} - -/////////////// Check Who am I? /////////////////////////// -void BNO055::check_id(void) -{ - select_page(0); - // ID - dt[0] = BNO055_CHIP_ID; - _i2c.write(chip_addr, dt, 1, true); - _i2c.read(chip_addr, dt, 7, false); - chip_id = dt[0]; - if (chip_id == I_AM_BNO055_CHIP) { - ready_flag = 1; - } else { - ready_flag = 0; - } - acc_id = dt[1]; - if (acc_id == I_AM_BNO055_ACC) { - ready_flag |= 2; - } - mag_id = dt[2]; - if (mag_id == I_AM_BNO055_MAG) { - ready_flag |= 4; - } - gyr_id = dt[3]; - if (mag_id == I_AM_BNO055_MAG) { - ready_flag |= 8; - } - bootldr_rev_id = dt[5]<< 8 | dt[4]; - sw_rev_id = dt[6]; -} - -void BNO055::read_id_inf(BNO055_ID_INF_TypeDef *id) -{ - id->chip_id = chip_id; - id->acc_id = acc_id; - id->mag_id = mag_id; - id->gyr_id = gyr_id; - id->bootldr_rev_id = bootldr_rev_id; - id->sw_rev_id = sw_rev_id; -} - -/////////////// Check chip ready or not ////////////////// -uint8_t BNO055::chip_ready(void) -{ - if (ready_flag == 0x0f) { - return 1; - } - return 0; -} - -/////////////// Read Calibration status ////////////////// -uint8_t BNO055::read_calib_status(void) -{ - select_page(0); - dt[0] = BNO055_CALIB_STAT; - _i2c.write(chip_addr, dt, 1, true); - _i2c.read(chip_addr, dt, 1, false); - return dt[0]; -} - -/////////////// Change Fusion mode /////////////////////// -void BNO055::change_fusion_mode(uint8_t mode) -{ - uint8_t current_mode; - - select_page(0); - current_mode = check_operating_mode(); - switch (mode) { - case CONFIGMODE: - dt[0] = BNO055_OPR_MODE; - dt[1] = mode; - _i2c.write(chip_addr, dt, 2, false); - wait_ms(19); // wait 19mS - break; - case MODE_IMU: - case MODE_COMPASS: - case MODE_M4G: - case MODE_NDOF_FMC_OFF: - case MODE_NDOF: - if (current_mode != CONFIGMODE) { // Can we change the mode directry? - dt[0] = BNO055_OPR_MODE; - dt[1] = CONFIGMODE; - _i2c.write(chip_addr, dt, 2, false); - wait_ms(19); // wait 19mS - } - dt[0] = BNO055_OPR_MODE; - dt[1] = mode; - _i2c.write(chip_addr, dt, 2, false); - wait_ms(7); // wait 7mS - break; - default: - break; - } -} - -uint8_t BNO055::check_operating_mode(void) -{ - select_page(0); - dt[0] = BNO055_OPR_MODE; - _i2c.write(chip_addr, dt, 1, true); - _i2c.read(chip_addr, dt, 1, false); - return dt[0]; -} - -/////////////// Set Mouting position ///////////////////// -void BNO055::set_mounting_position(uint8_t position) -{ - uint8_t remap_config; - uint8_t remap_sign; - uint8_t current_mode; - - current_mode = check_operating_mode(); - change_fusion_mode(CONFIGMODE); - switch (position) { - case MT_P0: - remap_config = 0x21; - remap_sign = 0x04; - break; - case MT_P2: - remap_config = 0x24; - remap_sign = 0x06; - break; - case MT_P3: - remap_config = 0x21; - remap_sign = 0x02; - break; - case MT_P4: - remap_config = 0x24; - remap_sign = 0x03; - break; - case MT_P5: - remap_config = 0x21; - remap_sign = 0x01; - break; - case MT_P6: - remap_config = 0x21; - remap_sign = 0x07; - break; - case MT_P7: - remap_config = 0x24; - remap_sign = 0x05; - break; - case MT_P1: - default: - remap_config = 0x24; - remap_sign = 0x00; - break; - } - dt[0] = BNO055_AXIS_MAP_CONFIG; - dt[1] = remap_config; - dt[2] = remap_sign; - _i2c.write(chip_addr, dt, 3, false); - change_fusion_mode(current_mode); -} - -/////////////// I2C Freq. ///////////////////////////////// -void BNO055::frequency(int hz) -{ - _i2c.frequency(hz); -} - -/////////////// Read/Write specific register ////////////// -uint8_t BNO055::read_reg0(uint8_t addr) -{ - select_page(0); - dt[0] = addr; - _i2c.write(chip_addr, dt, 1, true); - _i2c.read(chip_addr, dt, 1, false); - return (uint8_t)dt[0]; -} - -uint8_t BNO055::write_reg0(uint8_t addr, uint8_t data) -{ - uint8_t current_mode; - uint8_t d; - - current_mode = check_operating_mode(); - change_fusion_mode(CONFIGMODE); - dt[0] = addr; - dt[1] = data; - _i2c.write(chip_addr, dt, 2, false); - d = dt[0]; - change_fusion_mode(current_mode); - return d; -} - -uint8_t BNO055::read_reg1(uint8_t addr) -{ - select_page(1); - dt[0] = addr; - _i2c.write(chip_addr, dt, 1, true); - _i2c.read(chip_addr, dt, 1, false); - return (uint8_t)dt[0]; -} - -uint8_t BNO055::write_reg1(uint8_t addr, uint8_t data) -{ - uint8_t current_mode; - uint8_t d; - - current_mode = check_operating_mode(); - change_fusion_mode(CONFIGMODE); - select_page(1); - dt[0] = addr; - dt[1] = data; - _i2c.write(chip_addr, dt, 2, false); - d = dt[0]; - change_fusion_mode(current_mode); - return d; -} diff --git a/mbed-dongle-firmware/drivers/BNO055.h b/mbed-dongle-firmware/drivers/BNO055.h deleted file mode 100644 index a5c944b..0000000 --- a/mbed-dongle-firmware/drivers/BNO055.h +++ /dev/null @@ -1,539 +0,0 @@ -/* - * mbed library program - * BNO055 Intelligent 9-axis absolute orientation sensor - * by Bosch Sensortec - * - * Copyright (c) 2015 Kenji Arai / JH1PJL - * http://www.page.sannet.ne.jp/kenjia/index.html - * http://mbed.org/users/kenjiArai/ - * Created: March 30th, 2015 - * Revised: April 16th, 2015 - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, - * INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE - * AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, - * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - */ -/* - *---------------- REFERENCE ---------------------------------------------------------------------- - * Original Information - * https://www.bosch-sensortec.com/en/homepage/products_3/sensor_hubs/iot_solutions/bno055_1/bno055_4 - * Intelligent 9-axis absolute orientation sensor / Data Sheet BST_BNO055_DS000_12 Nov. 2014 rev.1.2 - * Sample software https://github.com/BoschSensortec/BNO055_driver - * Sensor board - * https://www.rutronik24.com/product/bosch+se/bno055+shuttle+board+mems/6431291.html - * http://microcontrollershop.com/product_info.php?products_id=7140&osCsid=10645k86db2crld4tfi0vol5g5 - */ - -#ifndef BNO055_H -#define BNO055_H - -#include "mbed.h" - -// BNO055 -// 7bit address = 0b010100x(0x28 or 0x29 depends on COM3) -#define BNO055_G_CHIP_ADDR (0x28 << 1) // COM3 = GND -#define BNO055_V_CHIP_ADDR (0x29 << 1) // COM3 = Vdd - -// Fusion mode -#define CONFIGMODE 0x00 -#define MODE_IMU 0x08 -#define MODE_COMPASS 0x09 -#define MODE_M4G 0x0a -#define MODE_NDOF_FMC_OFF 0x0b -#define MODE_NDOF 0x0c - -// UNIT -#define UNIT_ACC_MSS 0x00 // acc m/s2 -#define UNIT_ACC_MG 0x01 // acc mg -#define UNIT_GYR_DPS 0x00 // gyro Dps -#define UNIT_GYR_RPS 0x02 // gyro Rps -#define UNIT_EULER_DEG 0x00 // euler Degrees -#define UNIT_EULER_RAD 0x04 // euler Radians -#define UNIT_TEMP_C 0x00 // temperature degC -#define UNIT_TEMP_F 0x10 // temperature degF -#define UNIT_ORI_WIN 0x00 // Windows orientation -#define UNIT_ORI_ANDROID 0x80 // Android orientation - -// ID's -#define I_AM_BNO055_CHIP 0xa0 // CHIP ID -#define I_AM_BNO055_ACC 0xfb // ACC ID -#define I_AM_BNO055_MAG 0x32 // MAG ID -#define I_AM_BNO055_GYR 0x0f // GYR ID - -////////////// DATA TYPE DEFINITION /////////////////////// -typedef struct { - uint8_t chip_id; - uint8_t acc_id; - uint8_t mag_id; - uint8_t gyr_id; - uint8_t bootldr_rev_id; - uint16_t sw_rev_id; -} BNO055_ID_INF_TypeDef; - -typedef struct { - double h; - double r; - double p; -} BNO055_EULER_TypeDef; - -typedef struct { - int16_t x; - int16_t y; - int16_t z; - int16_t w; -} BNO055_QUATERNION_TypeDef; - -typedef struct { - double x; - double y; - double z; -} BNO055_LIN_ACC_TypeDef; - -typedef struct { - double x; - double y; - double z; -} BNO055_GRAVITY_TypeDef; - -typedef struct { - int8_t acc_chip; - int8_t gyr_chip; -} BNO055_TEMPERATURE_TypeDef; - -typedef enum {MT_P0 = 0, MT_P1, MT_P2, MT_P3, MT_P4, MT_P5, MT_P6, MT_P7 -} BNO055_MOUNT_POSITIONS_TypeDef ; - -/** Interface for Bosch Sensortec Intelligent 9-axis absolute orientation sensor - * Chip: BNO055 - * - * @code - * #include "mbed.h" - * #include "BNO055.h" - * - * Serial pc(USBTX,USBRX); - * I2C i2c(PB_9, PB_8); // SDA, SCL - * BNO055 imu(i2c, PA_8); // Reset - * - * BNO055_ID_INF_TypeDef bno055_id_inf; - * BNO055_EULER_TypeDef euler_angles; - * - * int main() { - * pc.printf("Bosch Sensortec BNO055 test program on " __DATE__ "/" __TIME__ "\r\n"); - * if (imu.chip_ready() == 0){ - * pc.printf("Bosch BNO055 is NOT avirable!!\r\n"); - * } - * imu.read_id_inf(&bno055_id_inf); - * pc.printf("CHIP:0x%02x, ACC:0x%02x, MAG:0x%02x, GYR:0x%02x, , SW:0x%04x, , BL:0x%02x\r\n", - * bno055_id_inf.chip_id, bno055_id_inf.acc_id, bno055_id_inf.mag_id, - * bno055_id_inf.gyr_id, bno055_id_inf.sw_rev_id, bno055_id_inf.bootldr_rev_id); - * while(1) { - * imu.get_Euler_Angles(&euler_angles); - * pc.printf("Heading:%+6.1f [deg], Roll:%+6.1f [deg], Pich:%+6.1f [deg]\r\n", - * euler_angles.h, euler_angles.r, euler_angles.p); - * wait(0.5); - * } - * } - * @endcode - */ - -class BNO055 -{ -public: - /** Configure data pin - * @param data SDA and SCL pins - * @param device address - */ - BNO055(PinName p_sda, PinName p_scl, PinName p_reset, uint8_t addr, uint8_t mode); - - /** Configure data pin - * @param data SDA and SCL pins - * @param Other parameters are set default data - */ - BNO055(PinName p_sda, PinName p_scl, PinName p_reset); - - /** Configure data pin (with other devices on I2C line) - * @param I2C previous definition - * @param device address - */ - BNO055(I2C& p_i2c, PinName p_reset, uint8_t addr, uint8_t mode); - - /** Configure data pin (with other devices on I2C line) - * @param I2C previous definition - * @param Other parameters are set default data - */ - BNO055(I2C& p_i2c, PinName p_reset); - - /** Get Euler Angles - * @param double type of 3D data address - */ - void get_Euler_Angles(BNO055_EULER_TypeDef *el); - - /** Get Quaternion XYZ&W - * @param int16_t type of 4D data address - */ - void get_quaternion(BNO055_QUATERNION_TypeDef *qua); - - /** Get Linear accel data - * @param double type of 3D data address - */ - void get_linear_accel(BNO055_LIN_ACC_TypeDef *la); - - /** Get Gravity data - * @param double type of 3D data address - */ - void get_gravity(BNO055_GRAVITY_TypeDef *gr); - - /** Get Chip temperature data both Acc & Gyro - * @param int8_t type of data address - */ - void get_chip_temperature(BNO055_TEMPERATURE_TypeDef *tmp); - - /** Change fusion mode - * @param fusion mode - * @return none - */ - void change_fusion_mode(uint8_t mode); - - /** Set Mouting position - * Please make sure your mounting direction of BNO055 chip - * refrence: BNO055 data sheet BST-BNO055-DS000-12 3.4 Axis remap - * @param Set P0 to P7 mounting position data - * @return none - */ - void set_mounting_position(uint8_t position); - - /** Read BNO055 ID information - * @param ID information address - * @return none - */ - void read_id_inf(BNO055_ID_INF_TypeDef *id); - - /** Check chip is avairable or not - * @param none - * @return OK = 1, NG = 0; - */ - uint8_t chip_ready(void); - - /** Read calibration status - * @param none - * @return SYS(7:6),GYR(5:4),ACC(3:2),MAG(1:0) 3 = Calibrated, 0= not yet - */ - uint8_t read_calib_status(void); - - /** Reset - * @param none - * @return 0 = sucess, 1 = Not available chip - */ - uint8_t reset(void); - - /** Set I2C clock frequency - * @param freq. - * @return none - */ - void frequency(int hz); - - /** Read page 0 register - * @param register's address - * @return register data - */ - uint8_t read_reg0(uint8_t addr); - - /** Write page 0 register - * @param register's address - * @param data - * @return register data - */ - uint8_t write_reg0(uint8_t addr, uint8_t data); - - /** Read page 1 register - * @param register's address - * @return register data - */ - uint8_t read_reg1(uint8_t addr); - - /** Write page 1 register - * @param register's address - * @param data - * @return register data - */ - uint8_t write_reg1(uint8_t addr, uint8_t data); - -protected: - void initialize(void); - void check_id(void); - void set_initial_dt_to_regs(void); - void unit_selection(void); - uint8_t check_operating_mode(void); - uint8_t select_page(uint8_t page); - - I2C _i2c; - DigitalOut _res; - -private: - char dt[10]; // working buffer - uint8_t chip_addr; - uint8_t chip_mode; - uint8_t ready_flag; - uint8_t page_flag; - - uint8_t chip_id; - uint8_t acc_id; - uint8_t mag_id; - uint8_t gyr_id; - uint8_t bootldr_rev_id; - uint16_t sw_rev_id; - -}; - -//--------------------------------------------------------- -//----- Register's definition ----------------------------- -//--------------------------------------------------------- -// Page id register definition -#define BNO055_PAGE_ID 0x07 - -//----- page0 --------------------------------------------- -#define BNO055_CHIP_ID 0x00 -#define BNO055_ACCEL_REV_ID 0x01 -#define BNO055_MAG_REV_ID 0x02 -#define BNO055_GYRO_REV_ID 0x03 -#define BNO055_SW_REV_ID_LSB 0x04 -#define BNO055_SW_REV_ID_MSB 0x05 -#define BNO055_BL_REV_ID 0x06 - -// Accel data register*/ -#define BNO055_ACC_X_LSB 0x08 -#define BNO055_ACC_X_MSB 0x09 -#define BNO055_ACC_Y_LSB 0x0a -#define BNO055_ACC_Y_MSB 0x0b -#define BNO055_ACC_Z_LSB 0x0c -#define BNO055_ACC_Z_MSB 0x0d - -// Mag data register -#define BNO055_MAG_X_LSB 0x0e -#define BNO055_MAG_X_MSB 0x0f -#define BNO055_MAG_Y_LSB 0x10 -#define BNO055_MAG_Y_MSB 0x11 -#define BNO055_MAG_Z_LSB 0x12 -#define BNO055_MAG_Z_MSB 0x13 - -// Gyro data registers -#define BNO055_GYR_X_LSB 0x14 -#define BNO055_GYR_X_MSB 0x15 -#define BNO055_GYR_Y_LSB 0x16 -#define BNO055_GYR_Y_MSB 0x17 -#define BNO055_GYR_Z_LSB 0x18 -#define BNO055_GYR_Z_MSB 0x19 - -// Euler data registers -#define BNO055_EULER_H_LSB 0x1a -#define BNO055_EULER_H_MSB 0x1b - -#define BNO055_EULER_R_LSB 0x1c -#define BNO055_EULER_R_MSB 0x1d - -#define BNO055_EULER_P_LSB 0x1e -#define BNO055_EULER_P_MSB 0x1f - -// Quaternion data registers -#define BNO055_QUATERNION_W_LSB 0x20 -#define BNO055_QUATERNION_W_MSB 0x21 -#define BNO055_QUATERNION_X_LSB 0x22 -#define BNO055_QUATERNION_X_MSB 0x23 -#define BNO055_QUATERNION_Y_LSB 0x24 -#define BNO055_QUATERNION_Y_MSB 0x25 -#define BNO055_QUATERNION_Z_LSB 0x26 -#define BNO055_QUATERNION_Z_MSB 0x27 - -// Linear acceleration data registers -#define BNO055_LINEAR_ACC_X_LSB 0x28 -#define BNO055_LINEAR_ACC_X_MSB 0x29 -#define BNO055_LINEAR_ACC_Y_LSB 0x2a -#define BNO055_LINEAR_ACC_Y_MSB 0x2b -#define BNO055_LINEAR_ACC_Z_LSB 0x2c -#define BNO055_LINEAR_ACC_Z_MSB 0x2d - -// Gravity data registers -#define BNO055_GRAVITY_X_LSB 0x2e -#define BNO055_GRAVITY_X_MSB 0x2f -#define BNO055_GRAVITY_Y_LSB 0x30 -#define BNO055_GRAVITY_Y_MSB 0x31 -#define BNO055_GRAVITY_Z_LSB 0x32 -#define BNO055_GRAVITY_Z_MSB 0x33 - -// Temperature data register -#define BNO055_TEMP 0x34 - -// Status registers -#define BNO055_CALIB_STAT 0x35 -#define BNO055_SELFTEST_RESULT 0x36 -#define BNO055_INTR_STAT 0x37 -#define BNO055_SYS_CLK_STAT 0x38 -#define BNO055_SYS_STAT 0x39 -#define BNO055_SYS_ERR 0x3a - -// Unit selection register -#define BNO055_UNIT_SEL 0x3b -#define BNO055_DATA_SELECT 0x3c - -// Mode registers -#define BNO055_OPR_MODE 0x3d -#define BNO055_PWR_MODE 0x3e -#define BNO055_SYS_TRIGGER 0x3f -#define BNO055_TEMP_SOURCE 0x40 - -// Axis remap registers -#define BNO055_AXIS_MAP_CONFIG 0x41 -#define BNO055_AXIS_MAP_SIGN 0x42 - -// SIC registers -#define BNO055_SIC_MTRX_0_LSB 0x43 -#define BNO055_SIC_MTRX_0_MSB 0x44 -#define BNO055_SIC_MTRX_1_LSB 0x45 -#define BNO055_SIC_MTRX_1_MSB 0x46 -#define BNO055_SIC_MTRX_2_LSB 0x47 -#define BNO055_SIC_MTRX_2_MSB 0x48 -#define BNO055_SIC_MTRX_3_LSB 0x49 -#define BNO055_SIC_MTRX_3_MSB 0x4a -#define BNO055_SIC_MTRX_4_LSB 0x4b -#define BNO055_SIC_MTRX_4_MSB 0x4c -#define BNO055_SIC_MTRX_5_LSB 0x4d -#define BNO055_SIC_MTRX_5_MSB 0x4e -#define BNO055_SIC_MTRX_6_LSB 0x4f -#define BNO055_SIC_MTRX_6_MSB 0x50 -#define BNO055_SIC_MTRX_7_LSB 0x51 -#define BNO055_SIC_MTRX_7_MSB 0x52 -#define BNO055_SIC_MTRX_8_LSB 0x53 -#define BNO055_SIC_MTRX_8_MSB 0x54 - -// Accelerometer Offset registers -#define ACCEL_OFFSET_X_LSB 0x55 -#define ACCEL_OFFSET_X_MSB 0x56 -#define ACCEL_OFFSET_Y_LSB 0x57 -#define ACCEL_OFFSET_Y_MSB 0x58 -#define ACCEL_OFFSET_Z_LSB 0x59 -#define ACCEL_OFFSET_Z_MSB 0x5a - -// Magnetometer Offset registers -#define MAG_OFFSET_X_LSB 0x5b -#define MAG_OFFSET_X_MSB 0x5c -#define MAG_OFFSET_Y_LSB 0x5d -#define MAG_OFFSET_Y_MSB 0x5e -#define MAG_OFFSET_Z_LSB 0x5f -#define MAG_OFFSET_Z_MSB 0x60 - -// Gyroscope Offset registers -#define GYRO_OFFSET_X_LSB 0x61 -#define GYRO_OFFSET_X_MSB 0x62 -#define GYRO_OFFSET_Y_LSB 0x63 -#define GYRO_OFFSET_Y_MSB 0x64 -#define GYRO_OFFSET_Z_LSB 0x65 -#define GYRO_OFFSET_Z_MSB 0x66 - -// Radius registers -#define ACCEL_RADIUS_LSB 0x67 -#define ACCEL_RADIUS_MSB 0x68 -#define MAG_RADIUS_LSB 0x69 -#define MAG_RADIUS_MSB 0x6a - -//----- page1 --------------------------------------------- -// Configuration registers -#define ACCEL_CONFIG 0x08 -#define MAG_CONFIG 0x09 -#define GYRO_CONFIG 0x0a -#define GYRO_MODE_CONFIG 0x0b -#define ACCEL_SLEEP_CONFIG 0x0c -#define GYRO_SLEEP_CONFIG 0x0d -#define MAG_SLEEP_CONFIG 0x0e - -// Interrupt registers -#define INT_MASK 0x0f -#define INT 0x10 -#define ACCEL_ANY_MOTION_THRES 0x11 -#define ACCEL_INTR_SETTINGS 0x12 -#define ACCEL_HIGH_G_DURN 0x13 -#define ACCEL_HIGH_G_THRES 0x14 -#define ACCEL_NO_MOTION_THRES 0x15 -#define ACCEL_NO_MOTION_SET 0x16 -#define GYRO_INTR_SETING 0x17 -#define GYRO_HIGHRATE_X_SET 0x18 -#define GYRO_DURN_X 0x19 -#define GYRO_HIGHRATE_Y_SET 0x1a -#define GYRO_DURN_Y 0x1b -#define GYRO_HIGHRATE_Z_SET 0x1c -#define GYRO_DURN_Z 0x1d -#define GYRO_ANY_MOTION_THRES 0x1e -#define GYRO_ANY_MOTION_SET 0x1f - -//--------------------------------------------------------- -//----- Calibration example ------------------------------- -//--------------------------------------------------------- -#if 0 -// Calibration -// Please refer BNO055 Data sheet 3.10 Calibration & 3.6.4 Sensor calibration data -void bno055_calbration(void){ - uint8_t d; - - pc.printf("------ Enter BNO055 Manual Calibration Mode ------\r\n"); - //---------- Gyroscope Caliblation ------------------------------------------------------------ - // (a) Place the device in a single stable position for a period of few seconds to allow the - // gyroscope to calibrate - pc.printf("Step1) Please wait few seconds\r\n"); - t.start(); - while (t.read() < 10){ - d = imu.read_calib_status(); - pc.printf("Calb dat = 0x%x target = 0x30(at least)\r\n", d); - if ((d & 0x30) == 0x30){ - break; - } - wait(1.0); - } - pc.printf("-> Step1) is done\r\n\r\n"); - //---------- Magnetometer Caliblation --------------------------------------------------------- - // (a) Make some random movements (for example: writing the number ‘8’ on air) until the - // CALIB_STAT register indicates fully calibrated. - // (b) It takes more calibration movements to get the magnetometer calibrated than in the - // NDOF mode. - pc.printf("Step2) random moving (try to change the BNO055 axis)\r\n"); - t.start(); - while (t.read() < 30){ - d = imu.read_calib_status(); - pc.printf("Calb dat = 0x%x target = 0x33(at least)\r\n", d); - if ((d & 0x03) == 0x03){ - break; - } - wait(1.0); - } - pc.printf("-> Step2) is done\r\n\r\n"); - //---------- Magnetometer Caliblation --------------------------------------------------------- - // a) Place the device in 6 different stable positions for a period of few seconds - // to allow the accelerometer to calibrate. - // b) Make sure that there is slow movement between 2 stable positions - // The 6 stable positions could be in any direction, but make sure that the device is - // lying at least once perpendicular to the x, y and z axis. - pc.printf("Step3) Change rotation each X,Y,Z axis KEEP SLOWLY!!"); - pc.printf(" Each 90deg stay a 5 sec and set at least 6 position.\r\n"); - pc.printf(" e.g. (1)ACC:X0,Y0,Z-9,(2)ACC:X9,Y0,Z0,(3)ACC:X0,Y0,Z9,"); - pc.printf("(4)ACC:X-9,Y0,Z0,(5)ACC:X0,Y-9,Z0,(6)ACC:X0,Y9,Z0,\r\n"); - pc.printf(" If you will give up, hit any key.\r\n", d); - t.stop(); - while (true){ - d = imu.read_calib_status(); - imu.get_gravity(&gravity); - pc.printf("Calb dat = 0x%x target = 0xff ACC:X %3.0f, Y %3.0f, Z %3.0f\r\n", - d, gravity.x, gravity.y, gravity.z); - if (d == 0xff){ break;} - if (pc.readable()){ break;} - wait(1.0); - } - if (imu.read_calib_status() == 0xff){ - pc.printf("-> All of Calibration steps are done successfully!\r\n\r\n"); - } else { - pc.printf("-> Calibration steps are suspended!\r\n\r\n"); - } - t.stop(); -} -#endif - -#endif // BNO055_H diff --git a/mbed-dongle-firmware/drivers/analog_button.h b/mbed-dongle-firmware/drivers/analog_button.h index 98185ba..c88bd6a 100644 --- a/mbed-dongle-firmware/drivers/analog_button.h +++ b/mbed-dongle-firmware/drivers/analog_button.h @@ -13,11 +13,32 @@ * to translate to a binary value on threshold. * Also encapsulates some HID Functionality. * + * Copyright (c) 2016 by Nick Bertoldi, Ben Heckathorn, Ryan O'Keefe, + * Adrian Padin, Timothy Schumacher + * + * Permission is hereby granted, free of charge, to any person obtaining + * a copy of this software and associated documentation files (the "Software"), + * to deal in the Software without restriction, including without limitation + * the rights to use, copy, modify, merge, publish, distribute, sublicense, + * and/or sell copies of the Software, and to permit persons to whom the + * Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included + * in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS + * IN THE SOFTWARE. */ + #ifndef ANALOG_BUTTON_H_ #define ANALOG_BUTTON_H_ -#include +#include template class AnalogButton { diff --git a/mbed-dongle-firmware/drivers/at42qt1070.cpp b/mbed-dongle-firmware/drivers/at42qt1070.cpp deleted file mode 100644 index 5c7bb3a..0000000 --- a/mbed-dongle-firmware/drivers/at42qt1070.cpp +++ /dev/null @@ -1,329 +0,0 @@ -/* - * Author: Jon Trulson - * Copyright (c) 2015 Intel Corporation. - * - * Permission is hereby granted, free of charge, to any person obtaining - * a copy of this software and associated documentation files (the - * "Software"), to deal in the Software without restriction, including - * without limitation the rights to use, copy, modify, merge, publish, - * distribute, sublicense, and/or sell copies of the Software, and to - * permit persons to whom the Software is furnished to do so, subject to - * the following conditions: - * - * The above copyright notice and this permission notice shall be - * included in all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, - * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND - * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE - * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION - * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION - * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - */ - -//#include -#include -#include -#include - -#include "at42qt1070.h" - -using namespace std; - -const uint8_t AVE_KEY_MAX = 6; -const uint8_t AKS_KEY_MAX = 3; -const uint8_t NO_GUARD_KEY = 7; - -AT42QT1070::AT42QT1070(PinName sda, PinName scl, uint8_t address) - : _i2c(sda, scl), _addr(address << 1) { - - initialize(); -} - -AT42QT1070::AT42QT1070(I2C& i2c, uint8_t address) - : _i2c(i2c), _addr(address << 1) { - - initialize(); -} - -void AT42QT1070::initialize() { - _i2c.frequency(AT42QT1070_I2C_MAX_FREQUENCY); - - // spec list <230ms as boot up time, wait here to be sure - wait_ms(230); - reset(); - wait_ms(230); - - if (readChipID() != 0x2E) { - return; // throw std::runtime_error("Chip ID does not match the - // expected value (2Eh)"); - } - - _buttonStates = 0; - _calibrating = false; - _overflow = false; -} - -//-------------------------------------------------------------------------------- -AT42QT1070::~AT42QT1070() { _i2c.stop(); } - -//-------------------------------------------------------------------------------- -bool AT42QT1070::writeByte(uint8_t reg, uint8_t byte) { - const char cmd[] = { reg, byte }; - - if (0 == _i2c.write(_addr, cmd, 2)) - return true; - else - return false; -} - -//-------------------------------------------------------------------------------- -bool AT42QT1070::writeWord(uint8_t reg, uint16_t word) { - const char cmd[] = { reg, word & 0xff, (word & 0xff00) >> 8 }; - - if (0 == _i2c.write(_addr, cmd, 3)) - return true; - else - return false; -} - -//-------------------------------------------------------------------------------- -uint8_t AT42QT1070::readByte(uint8_t reg) { - char data = 0; - const char cmd = reg; - _i2c.write(_addr, &cmd, 1); - _i2c.read(_addr, &data, 1); - - return data; -} - -//-------------------------------------------------------------------------------- -uint16_t AT42QT1070::readWord(uint8_t reg) { - uint16_t res = 0; - char data[] = { 0, 0 }; - const char cmd = reg; - - _i2c.write(_addr, &cmd, 1); - _i2c.read(_addr, data, 2); - res = data[1] << 8 & data[0]; - - return res; -} - -//-------------------------------------------------------------------------------- -uint8_t AT42QT1070::readChipID(void) { return readByte(REG_CHIPID); } - -//-------------------------------------------------------------------------------- -void AT42QT1070::updateState() { - uint8_t status = readByte(REG_DETSTATUS); - - // if we are calibrating, don't change anything - if (status & DET_CALIBRATE) { - _calibrating = true; - return; - } else { - _calibrating = false; - } - - if (status & DET_OVERFLOW) - _overflow = true; - else - _overflow = false; - - // if a touch is occurring, read the button states - if (status & DET_TOUCH) { - uint8_t keys = readByte(REG_KEYSTATUS); - // high bit is reserved, filter it out - _buttonStates = keys & ~0x80; - } else { - _buttonStates = 0; - } -} - -//-------------------------------------------------------------------------------- -uint8_t AT42QT1070::getButtonsState() { - uint8_t status = readByte(REG_DETSTATUS); - uint8_t keys = readByte(REG_KEYSTATUS); - - // if we are calibrating, don't change anything - if (status & DET_CALIBRATE) { - _calibrating = true; - return 0; - } - - // Old library only read buttons if one of them was touched. - // We want to read either way so that change line gets reset. - // Therefore read command has been moved outside of if statement. - if (status & DET_TOUCH) { - // high bit is reserved, filter it out - _buttonStates = keys & ~0x80; - } else { - _buttonStates = 0; - } - - // set the top bit in _buttonStates to signal overflow - if (status & DET_OVERFLOW) { - _buttonStates |= 0x80; - } - - return _buttonStates; -} - -//-------------------------------------------------------------------------------- -bool AT42QT1070::isButtonPressed(const uint8_t button) { - uint8_t buttonsState = 0; - - if (button <= 6) { - buttonsState = getButtonsState(); - } - - return (buttonsState & (0x1 << button)); -} - -//-------------------------------------------------------------------------------- -uint8_t AT42QT1070::getLowPowerMode(void) { - return readByte(REG_LP); -} - -//-------------------------------------------------------------------------------- -uint8_t AT42QT1070::setLowPowerMode(uint8_t mode) { - writeByte(REG_LP, mode); - - return getLowPowerMode(); -} - -//-------------------------------------------------------------------------------- -uint8_t AT42QT1070::getMaxOn(void) { - return readByte(REG_MAXON); -} - -//-------------------------------------------------------------------------------- -uint8_t AT42QT1070::setMaxOn(uint8_t maxon) { - writeByte(REG_MAXON, maxon); - - return getMaxOn(); -} - -//-------------------------------------------------------------------------------- -uint8_t AT42QT1070::getAVE(uint8_t key) { - uint8_t value = 0; - uint8_t ave = 0; - - if (key <= AVE_KEY_MAX) { - value = readByte(REG_AVE0 + key); - ave = (value & 0xFC) >> 2; - } - - return ave; -} - -//-------------------------------------------------------------------------------- -uint8_t AT42QT1070::setAVE(uint8_t key, uint8_t ave) { - uint8_t value = 0; - - // if (key > AVE_KEY_MAX) { - // throw std::invalid_argument("Only keys 0-6 are allowed"); - // } - - // switch (ave) { - // case 1: - // case 2: - // case 4: - // case 8: - // case 16: - // case 32: - // break; - - // default: - // throw std::invalid_argument("Invalid averaging factor"); - // } - - value = readByte(REG_AVE0 + key); - value = value & 0x03; - value = value | (ave << 2); - writeByte(REG_AVE0 + key, value); - - return getAVE(key); -} - -//-------------------------------------------------------------------------------- -uint8_t AT42QT1070::getAKSGroup(uint8_t key) { - uint8_t value = 0; - uint8_t aks = 0; - - if (key <= AKS_KEY_MAX) { - value = readByte(REG_AVE0 + key); - aks = value & 0x03; - } - - return aks; -} - -//-------------------------------------------------------------------------------- -uint8_t AT42QT1070::setAKSGroup(uint8_t key, uint8_t group) { - uint8_t value = 0; - - if (key <= AVE_KEY_MAX && group <= AKS_KEY_MAX) { - value = readByte(REG_AVE0 + key); - value = value & 0xFC; - value = value | group; - writeByte(REG_AVE0 + key, value); - } - - return getAKSGroup(key); -} - -//-------------------------------------------------------------------------------- -uint8_t AT42QT1070::getDetectionIntegrator(uint8_t key) { - if (key <= AKS_KEY_MAX) { - return readByte(REG_DI0 + key); - } -} - -//-------------------------------------------------------------------------------- -uint8_t AT42QT1070::setDetectionIntegrator(uint8_t key, uint8_t di) { - if (key <= AVE_KEY_MAX) { - writeByte(REG_DI0 + key, di); - } - - return getDetectionIntegrator(key); -} - -//-------------------------------------------------------------------------------- -uint8_t AT42QT1070::getThreshold(uint8_t key) { - if (key <= AKS_KEY_MAX) { - return readByte(REG_NTHR0 + key); - } -} - -//-------------------------------------------------------------------------------- -uint8_t AT42QT1070::setThreshold(uint8_t key, uint8_t nthr) { - if (key <= AVE_KEY_MAX) { - writeByte(REG_NTHR0 + key, nthr); - } - - return getThreshold(key); -} - -//-------------------------------------------------------------------------------- -uint8_t AT42QT1070::setGuard(uint8_t key=NO_GUARD_KEY) { - // TODO add setters for FO/MaxCal instead of clearing here - if (key <= AVE_KEY_MAX || key == NO_GUARD_KEY) { - writeByte(REG_GUARD, (0x0f) & key); - } - - return (0x0f) & readByte(REG_GUARD); -} - -//-------------------------------------------------------------------------------- -bool AT42QT1070::reset() { - // write a non-zero value to the reset register - return writeByte(REG_RESET, 0xff); -} - -//-------------------------------------------------------------------------------- -bool AT42QT1070::calibrate() { - // write a non-zero value to the calibrate register - return writeByte(REG_CALIBRATE, 0xff); -} diff --git a/mbed-dongle-firmware/drivers/at42qt1070.h b/mbed-dongle-firmware/drivers/at42qt1070.h deleted file mode 100644 index f4109b6..0000000 --- a/mbed-dongle-firmware/drivers/at42qt1070.h +++ /dev/null @@ -1,378 +0,0 @@ -/* - g* Author: Jon Trulson - * Copyright (c) 2015 Intel Corporation. - * - * Permission is hereby granted, free of charge, to any person obtaining - * a copy of this software and associated documentation files (the - * "Software"), to deal in the Software without restriction, including - * without limitation the rights to use, copy, modify, merge, publish, - * distribute, sublicense, and/or sell copies of the Software, and to - * permit persons to whom the Software is furnished to do so, subject to - * the following conditions: - * - * The above copyright notice and this permission notice shall be - * included in all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, - * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND - * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE - * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION - * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION - * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - */ -#pragma once - -#include -#include -#include - -#include "mbed.h" - -#define AT42QT1070_I2C_BUS 0 -#define AT42QT1070_DEFAULT_I2C_ADDR 0x1B -#define AT42QT1070_I2C_MAX_FREQUENCY 400000 - -/** - * @brief Atmel* AT42QT1070 QTouch* Sensor library - * @defgroup at42qt1070 libupm-at42qt1070 - * @ingroup seeed i2c touch - */ - -/** - * @library at42qt1070 - * @sensor at42qt1070 - * @comname AT42QT1070 QTouch Sensor - * @altname Grove QTouch Sensor - * @type touch - * @man seeed - * @con i2c - * - * @brief API for the Atmel AT42QT1070 QTouch Sensor - * - * This class implements support for the Atmel AT42QT1070 QTouch - * sensor, which supports 7 capacitive buttons. - * - * It was developed using a Grove-Q Touch Sensor board. - * - * @image html at42qt1070.jpg - * @snippet at42qt1070.cxx Interesting - */ -class AT42QT1070 { -public: - // registers - typedef enum { - REG_CHIPID = 0, - REG_FWVERS = 1, - REG_DETSTATUS = 2, // detection status - REG_KEYSTATUS = 3, // key status - REG_KEYSIG0_H = 4, // key signal - REG_KEYSIG0_L = 5, - REG_KEYSIG1_H = 6, - REG_KEYSIG1_L = 7, - REG_KEYSIG2_H = 8, - REG_KEYSIG2_L = 9, - REG_KEYSIG3_H = 10, - REG_KEYSIG3_L = 11, - REG_KEYSIG4_H = 12, - REG_KEYSIG4_L = 13, - REG_KEYSIG5_H = 14, - REG_KEYSIG5_L = 15, - REG_KEYSIG6_H = 16, - REG_KEYSIG6_L = 17, - REG_REFDATA0_H = 18, // key reference data - REG_REFDATA0_L = 19, - REG_REFDATA1_H = 20, - REG_REFDATA1_L = 21, - REG_REFDATA2_H = 22, - REG_REFDATA2_L = 23, - REG_REFDATA3_H = 24, - REG_REFDATA3_L = 25, - REG_REFDATA4_H = 26, - REG_REFDATA4_L = 27, - REG_REFDATA5_H = 28, - REG_REFDATA5_L = 29, - REG_REFDATA6_H = 30, - REG_REFDATA6_L = 31, - REG_NTHR0 = 32, // negative threshold level - REG_NTHR1 = 33, - REG_NTHR2 = 34, - REG_NTHR3 = 35, - REG_NTHR4 = 36, - REG_NTHR5 = 37, - REG_NTHR6 = 38, - REG_AVE0 = 39, // key suppression - REG_AVE1 = 40, - REG_AVE2 = 41, - REG_AVE3 = 42, - REG_AVE4 = 43, - REG_AVE5 = 44, - REG_AVE6 = 45, - REG_DI0 = 46, // detection integrator - REG_DI1 = 47, - REG_DI2 = 48, - REG_DI3 = 49, - REG_DI4 = 50, - REG_DI5 = 51, - REG_DI6 = 52, - REG_GUARD = 53, // FastOutDI/Max Cal/Guard channel - REG_LP = 54, // low power mode register - REG_MAXON = 55, // max on duration - REG_CALIBRATE = 56, - REG_RESET = 57 - } AT42QT1070_REG_T; - - // detection register bits - typedef enum { - DET_TOUCH = 0x01, - // 0x02-0x20 reserved - DET_OVERFLOW = 0x40, - DET_CALIBRATE = 0x80 - } AT42QT1070_DET_T; - - /** - * AT42QT1070 constructor - * - * @param sda I2C data line - * @param scl I2C clock line - * @param address Address for this sensor - */ - AT42QT1070(PinName sda, PinName scl, - uint8_t address = AT42QT1070_DEFAULT_I2C_ADDR); - - /** - * AT42QT1070 alternate constructor - * - * @param i2c mbed::I2C object to use - * @param address Address for this sensor - */ - AT42QT1070(I2C& i2c, uint8_t address = AT42QT1070_DEFAULT_I2C_ADDR); - - /** - * AT42QT1070 destructor - */ - ~AT42QT1070(); - - /** - * Helper for the multiple constructor calls - */ - void initialize(); - - /** - * Reads the Chip ID register on the sensor - * - * @return Value of the Chip ID register - */ - uint8_t readChipID(void); - - /** - * Reads the current touch status and detection state - * - * @return Key status bits for all keys (0-6) - */ - void updateState(); - - /** - * Reads the current low-power mode setting - * - * @return Low-power mode setting from the sensor - */ - uint8_t getLowPowerMode(void); - - /** - * Changes the low-pomer mode setting on the sensor - * - * @param mode Dsired new mode - * @return New setting on the sensor - */ - uint8_t setLowPowerMode(uint8_t mode); - - /** - * Reads the current max on duration - * - * @return Max-On Duration from the sensor - */ - uint8_t getMaxOn(void); - - /** - * Changes the current max on duration - * - * @param maxon Desired max on duration (0 for off) - * @return Max-On Duration from the sensor - */ - uint8_t setMaxOn(uint8_t maxon); - - /** - * Reads the current averaging factor setting for a key - * - * @param key Key being read - * @return Averaging factor - */ - uint8_t getAVE(uint8_t key); - - /** - * Changes the averaging factor setting for a key - * values restricted internally to 1,2,4,8,16,32 (default 8) - * - * @param key Key being changed - * @param ave New averaging factor - * @return New averaging factor as read from the device - */ - uint8_t setAVE(uint8_t key, uint8_t ave); - - /** - * Reads the AKS group of which a key is part - * - * 0: no group - * 1..3: available AKS groups - * - * @param key Key (0-6) being queried - * @return AKS group of which the key is part - */ - uint8_t getAKSGroup(uint8_t key); - - /** - * Changes the AKS group of which a key is part - * - * 0: no group - * 1..3: available AKS groups - * - * @param key Key (0-6) being changed - * @param group New group for the key - * @return New value on the sensor - */ - uint8_t setAKSGroup(uint8_t key, uint8_t group); - - /** - * Reads the Detection Integrator (DI) level on key - * - * @param key Key (0-6) being changed - * @return DI level on the key - */ - uint8_t getDetectionIntegrator(uint8_t key); - - /** - * Set the Detection Integrator (DI) level on key - * Default is 4, minimum 2 - * - * @param key Key (0-6) being changed - * @param di New DI level - * @return New DI on the key - */ - uint8_t setDetectionIntegrator(uint8_t key, uint8_t di); - - /** - * Reads the Negative Threshold for key to register touch - * - * @param key Key (0-6) being changed - * @return NTHR level on the key - */ - uint8_t getThreshold(uint8_t key); - - /** - * Reads the Negative Threshold for key to register touch - * Default is 20 - * - * @param key Key (0-6) being changed - * @param di New NTHR level - * @return New NTHR on the key - */ - uint8_t setThreshold(uint8_t key, uint8_t nthr); - - /** - * Returns the overflow indicator - * - * @return True if overflow is indicated - */ - bool isOverflowed() { - return _overflow; - }; - - /** - * Returns the calibrating indicator - * - * @return True if calibration is in progress - */ - bool isCalibrating() { - return _calibrating; - }; - - /** - * Sets which key is the guard key - * - * Defaults to disabling the GUARD_KEY feature - * - * @param key Key to set as guard key - * @return Value of the Guard key register - */ - uint8_t setGuard(uint8_t key); - - /** - * Issues a reset command - * - * @return True if successful - */ - bool reset(); - - /** - * Issues a calibrate command - * - * @return True if successful - */ - bool calibrate(); - - /** - * Gets the current button states - * - * @returns Button states - */ - uint8_t getButtonsState(); - - bool isButtonPressed(const uint8_t button); - -private: - /** - * Writes a byte value into the register - * - * @param reg Register location to write into - * @param byte Byte to write - * @return True if successful - */ - bool writeByte(uint8_t reg, uint8_t byte); - - /** - * Writes a word value into the register. Note: the device must have the - * auto-increment bit set in the MODE1 register to work. - * - * @param reg Register location to write into - * @param word Word to write - * @return True if successful - */ - bool writeWord(uint8_t reg, uint16_t word); - - /** - * Read a byte value from the register - * - * @param reg Register location to read from - * @return Value in the specified register - */ - uint8_t readByte(uint8_t reg); - - /** - * Read a word value from the register. Note: the device must have the - * auto-increment bit set in the MODE1 register to work. - * - * @param reg Register location to read from - * @return Value in the specified register - */ - uint16_t readWord(uint8_t reg); - -private: - uint8_t _buttonStates; - bool _calibrating; - bool _overflow; - - I2C _i2c; - uint8_t _addr; -}; - diff --git a/mbed-dongle-firmware/drivers/flex_sensor.cpp b/mbed-dongle-firmware/drivers/flex_sensor.cpp deleted file mode 100644 index 4b7e131..0000000 --- a/mbed-dongle-firmware/drivers/flex_sensor.cpp +++ /dev/null @@ -1,66 +0,0 @@ -/* - * Filename: flex_sensor.c - * Project: EECS 473 - Team GLOVE - * Date: Fall 2016 - * Authors: - * Nick Bertoldi - * Ben Heckathorn - * Ryan O’Keefe - * Adrian Padin - * Tim Schumacher - * - * Purpose: - * Implementation for the FlexSensors class in flex_sensor.h - */ -#include "flex_sensor.h" - -const PinName FLEX_DEBUG_PIN = p15; - -FlexSensors::FlexSensors() { - pins[0] = new AnalogIn(FLEX_0); - pins[1] = new AnalogIn(FLEX_1); - pins[2] = new AnalogIn(FLEX_2); - pins[3] = new AnalogIn(FLEX_3); - - //update_task_timer = new RtosTimer(this, &FlexSensors::update, osTimerPeriodic); -} - -void FlexSensors::update() { - for (uint8_t i = 0; i < FLEX_SENSORS_COUNT; i++) { - values[i] = pins[i]->read_u16(); - } -} - -/* -void FlexSensors::startUpdateTask(uint32_t ms) { - update_task_timer->start(ms); -} - -void FlexSensors::stopUpdateTask() { - update_task_timer->stop(); -} -*/ - -void FlexSensors::writeSensors(flex_sensor_t* buf) { - for (uint8_t i = 0; i < FLEX_SENSORS_COUNT; i++) { - buf[i] = values[i]; - } -} - -void FlexSensors::updateAndWrite(flex_sensor_t* buf) { - for (uint8_t i = 0; i < FLEX_SENSORS_COUNT; i++) { - values[i] = pins[i]->read_u16(); - buf[i] = values[i]; - } -} - -void FlexSensors::print(Serial& pc) { - pc.printf("Flex: %hu, %hu, %hu, %hu\r\n", - values[0], values[1], values[2], values[3]); -} - -void FlexSensors::printSingle(Serial& pc, uint8_t index) { - if (index < FLEX_SENSORS_COUNT) { - pc.printf("Flex %hu: %hu\r\n", index, values[index]); - } -} diff --git a/mbed-dongle-firmware/drivers/flex_sensor.h b/mbed-dongle-firmware/drivers/flex_sensor.h index 7846949..6f6b760 100644 --- a/mbed-dongle-firmware/drivers/flex_sensor.h +++ b/mbed-dongle-firmware/drivers/flex_sensor.h @@ -10,7 +10,28 @@ * Tim Schumacher * * Purpose: - * Top-level interface to the flex sensors + * Define the data structure for the flex sensor data + * + * Copyright (c) 2016 by Nick Bertoldi, Ben Heckathorn, Ryan O'Keefe, + * Adrian Padin, Timothy Schumacher + * + * Permission is hereby granted, free of charge, to any person obtaining + * a copy of this software and associated documentation files (the "Software"), + * to deal in the Software without restriction, including without limitation + * the rights to use, copy, modify, merge, publish, distribute, sublicense, + * and/or sell copies of the Software, and to permit persons to whom the + * Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included + * in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS + * IN THE SOFTWARE. */ #ifndef FLEX_SENSOR_H_ @@ -18,92 +39,12 @@ #include -#include "mbed.h" - #define FLEX_SENSORS_COUNT 4 -#if defined(TARGET_NRF51_DK) -const PinName FLEX_0 = A0; -const PinName FLEX_1 = A1; -const PinName FLEX_2 = A2; -const PinName FLEX_3 = A3; -#elif defined(TARGET_MCU_NRF51822) -const PinName FLEX_0 = p1; -const PinName FLEX_1 = p2; -const PinName FLEX_2 = p3; -const PinName FLEX_3 = p4; -#endif - -/* - * Update Period (in milliseconds) - */ -const uint32_t FLEX_UPDATE_PERIOD = 10; - /* flex_sensor_t * * deflection: scaled analog-to-digital value read from the GPIO */ typedef uint16_t flex_sensor_t; - -/* FlexSensors - * - * Single class to handle the flex sensor analog read objects, - * with methods to update internally, and write into the - * marshelled all sensors data structure - */ -class FlexSensors { -public: - /* - * Constructor initializes the AnalogIn objects - */ - FlexSensors(); - - /* - * Update the deflection for all flex sensors - */ - void update(); - - /* - * Calls the start() method on the periodic update task, - * an internal timer is set up in the constructor - * - * Measured to take approximately 520us - */ - //void startUpdateTask(uint32_t ms=FLEX_UPDATE_PERIOD); - - /* - * Calls the stop() method on the periodic update timer, - */ - //void stopUpdateTask(); - - /* - * Write the flex sensor values to the given array. - * This assumes no ownership or locking of the given container - */ - void writeSensors(flex_sensor_t* buf); - - /* - * Alternative interface to both update each pin - * And write it to the destination buffer - */ - void updateAndWrite(flex_sensor_t* buf); - - /* - * Print the value of all the flex sensors for debugging - */ - void print(Serial& debug_out); - - /* - * Print the value of one sensor - */ - void printSingle(Serial& pc, uint8_t index); - - - -private: - flex_sensor_t values[FLEX_SENSORS_COUNT]; - AnalogIn* pins[FLEX_SENSORS_COUNT]; - //RtosTimer* update_task_timer; -}; #endif /* FLEX_SENSOR_H_ */ diff --git a/mbed-dongle-firmware/drivers/glove_sensors.cpp b/mbed-dongle-firmware/drivers/glove_sensors.cpp index a927db6..c12d930 100644 --- a/mbed-dongle-firmware/drivers/glove_sensors.cpp +++ b/mbed-dongle-firmware/drivers/glove_sensors.cpp @@ -14,6 +14,27 @@ * of the bluetooth connection, and it contains synchronization things. * * Implements the compression/decompression for glove sensors + * + * Copyright (c) 2016 by Nick Bertoldi, Ben Heckathorn, Ryan O'Keefe, + * Adrian Padin, Timothy Schumacher + * + * Permission is hereby granted, free of charge, to any person obtaining + * a copy of this software and associated documentation files (the "Software"), + * to deal in the Software without restriction, including without limitation + * the rights to use, copy, modify, merge, publish, distribute, sublicense, + * and/or sell copies of the Software, and to permit persons to whom the + * Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included + * in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS + * IN THE SOFTWARE. */ #include "glove_sensors.h" @@ -34,12 +55,10 @@ void compressGloveSensors(glove_sensors_raw_t* raw, glove_sensors_compressed_t* int extractGloveSensors(glove_sensors_raw_t& raw, glove_sensors_compressed_t* compressed) { - /* uint16_t crc_result = crcFast((uint8_t*)compressed, glove_sensors_compressed_size_no_crc); if (crc_result != compressed->checksum) { return -1; } - */ raw.flex_sensors[0] = (compressed->f[0] >> 4); raw.flex_sensors[1] = ((compressed->f[0] & 0x000F) << 8) | (compressed->f[1] >> 8); diff --git a/mbed-dongle-firmware/drivers/glove_sensors.h b/mbed-dongle-firmware/drivers/glove_sensors.h index f3f4246..469d9e3 100644 --- a/mbed-dongle-firmware/drivers/glove_sensors.h +++ b/mbed-dongle-firmware/drivers/glove_sensors.h @@ -13,11 +13,33 @@ * This is the definition of the struct used on either end * of the bluetooth connection, and it contains synchronization things. * + * Copyright (c) 2016 by Nick Bertoldi, Ben Heckathorn, Ryan O'Keefe, + * Adrian Padin, Timothy Schumacher + * + * Permission is hereby granted, free of charge, to any person obtaining + * a copy of this software and associated documentation files (the "Software"), + * to deal in the Software without restriction, including without limitation + * the rights to use, copy, modify, merge, publish, distribute, sublicense, + * and/or sell copies of the Software, and to permit persons to whom the + * Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included + * in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS + * IN THE SOFTWARE. */ #ifndef GLOVE_SENSORS_H_ #define GLOVE_SENSORS_H_ +#include + #include "flex_sensor.h" #include "touch_sensor.h" #include "imu.h" @@ -37,8 +59,8 @@ typedef struct { * compressed version of all the * sensor data that fits in a BLE advertisement */ -const size_t glove_sensors_compressed_size = 22; -const size_t glove_sensors_compressed_size_no_crc = 20; +const uint8_t glove_sensors_compressed_size = 22; +const uint8_t glove_sensors_compressed_size_no_crc = 20; typedef struct { // flex sensors (12*4 = 48b = 6B) uint16_t f[3]; diff --git a/mbed-dongle-firmware/drivers/imu.cpp b/mbed-dongle-firmware/drivers/imu.cpp deleted file mode 100644 index 8c5523e..0000000 --- a/mbed-dongle-firmware/drivers/imu.cpp +++ /dev/null @@ -1,87 +0,0 @@ -/* - * Filename: imu.cpp - * Project: EECS 473 - Team GLOVE - * Date: Fall 2016 - * Authors: - * Nick Bertoldi - * Ben Heckathorn - * Ryan O’Keefe - * Adrian Padin - * Tim Schumacher - * - * Purpose: - * Implement the top-level interface with the specific configuration - * and core functionality for the GLOVE - * - * Uses the BNO055_fusion mbed library by Kenji Arai - */ - -#include "imu.h" - -IMU_BNO055::IMU_BNO055(I2C& i2c) - : imu(i2c, IMU_RST, BNO055_G_CHIP_ADDR, MODE_NDOF) { - - imu.set_mounting_position(IMU_MOUNT_POSITION); - - if (imu.chip_ready() == 0) { - do { - wait_ms(10); - } while (imu.reset()); - } - - imu.read_id_inf(&bno055_id_inf); - - //update_task_timer = new RtosTimer(this, &IMU_BNO055::update, osTimerPeriodic); -} - -void IMU_BNO055::update() { - imu.get_Euler_Angles(&euler_angles); - imu.get_linear_accel(&linear_acc); - - imu_data.orient_pitch = euler_angles.p; - imu_data.orient_roll = euler_angles.r; - imu_data.orient_yaw = euler_angles.h; - - imu_data.accel_x = linear_acc.x; - imu_data.accel_y = linear_acc.y; - imu_data.accel_z = linear_acc.z; -} - -/* -void IMU_BNO055::startUpdateTask(uint32_t ms) { - update_task_timer->start(ms); -} - -void IMU_BNO055::stopUpdateTask() { - update_task_timer->stop(); -} -*/ - -void IMU_BNO055::writeSensors(bno_imu_t* imu_) { - imu_->orient_pitch = imu_data.orient_pitch; - imu_->orient_roll = imu_data.orient_roll; - imu_->orient_yaw = imu_data.orient_yaw; - imu_->accel_x = imu_data.accel_x; - imu_->accel_y = imu_data.accel_y; - imu_->accel_z = imu_data.accel_z; -} - -extern DigitalOut l3; -void IMU_BNO055::updateAndWrite(bno_imu_t* imu_) { - l3 = 0; - update(); - l3 = 1; - writeSensors(imu_); -} - -void IMU_BNO055::print(Serial& pc) { - pc.printf("Y%+6.1f, P%+6.1f, R%+6.1f\r\n", - imu_data.orient_yaw, imu_data.orient_pitch, imu_data.orient_roll); - - /* - pc.printf("[E] %+6.1f Yaw, %+6.1f Pitch, %+6.1f Roll, ", - imu_data.orient_yaw, imu_data.orient_pitch, imu_data.orient_roll); - pc.printf(" [L] %+6.1f X, %+6.1f Y, %+6.1f Z\r\n", - imu_data.accel_x, imu_data.accel_y, imu_data.accel_z); - */ -} diff --git a/mbed-dongle-firmware/drivers/imu.h b/mbed-dongle-firmware/drivers/imu.h index 1ca1212..3b19d31 100644 --- a/mbed-dongle-firmware/drivers/imu.h +++ b/mbed-dongle-firmware/drivers/imu.h @@ -10,34 +10,33 @@ * Tim Schumacher * * Purpose: - * Top-level interface for a task to get data from the IMU + * Define the data structure for the flex sensor data * - * Uses the BNO055_fusion mbed library by Kenji Arai + * Copyright (c) 2016 by Nick Bertoldi, Ben Heckathorn, Ryan O'Keefe, + * Adrian Padin, Timothy Schumacher + * + * Permission is hereby granted, free of charge, to any person obtaining + * a copy of this software and associated documentation files (the "Software"), + * to deal in the Software without restriction, including without limitation + * the rights to use, copy, modify, merge, publish, distribute, sublicense, + * and/or sell copies of the Software, and to permit persons to whom the + * Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included + * in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS + * IN THE SOFTWARE. */ #ifndef IMU_H_ #define IMU_H_ -#include "BNO055.h" -/* - * PinName definitions for the BNO055 on the board - */ -//const PinName IMU_I2C_SCL = I2C_SCL0; // = p7 -//const PinName IMU_I2C_SDA = I2C_SDA0; // = p30 -const PinName IMU_RST = p12; - -/* - * Update Period (in milliseconds) - */ -const uint32_t IMU_UPDATE_PERIOD = 10; - -/* - * Section 3.4 Axis Remap, p.25 - * On prototype in P1 - * On PCB in P? - */ -const BNO055_MOUNT_POSITIONS_TypeDef IMU_MOUNT_POSITION = MT_P1; - /* bno_imu_t * * Euler orientation in degrees (pitch, roll, yaw) @@ -56,69 +55,4 @@ typedef struct { float accel_z; } bno_imu_t; -class IMU_BNO055 { -public: - /* - * Constructor initializes the BNO055 and takes care - * of the default configuration. - */ - IMU_BNO055(I2C& i2c); - - /* - * Update the orientation and acceleration information - * Callback for the periodic mode - */ - void update(); - - /* - * Calls the start() method on the periodic update task, - * an internal timer is set up in the constructor - */ - //void startUpdateTask(uint32_t ms=IMU_UPDATE_PERIOD); - - /* - * Calls the stop() method on the periodic update timer, - */ - //void stopUpdateTask(); - - /* - * Write the imu orientation values to the given struct - * This assumes no ownership or locking of the given container - */ - void writeSensors(bno_imu_t*); - - /* - * Single function call for manual polling - * Calls update then writes to the provided - */ - void updateAndWrite(bno_imu_t*); - - /* - * something something do manual calibration - */ - // .manualCalibration() - - /* - * For debuggs - */ - void print(Serial& debug_out); - -private: - BNO055 imu; - bno_imu_t imu_data; - - BNO055_ID_INF_TypeDef bno055_id_inf; - BNO055_EULER_TypeDef euler_angles; - BNO055_LIN_ACC_TypeDef linear_acc; - - //RtosTimer* update_task_timer; -}; - -/* - * Need some way to save the calibration for the IMU - * and then reload it on setup - */ -void saveIMUCalibration(); -void loadIMUCalibration(); - #endif /* IMU_H_ */ diff --git a/mbed-dongle-firmware/drivers/scanner.h b/mbed-dongle-firmware/drivers/scanner.h index bdf855b..4ed29ea 100644 --- a/mbed-dongle-firmware/drivers/scanner.h +++ b/mbed-dongle-firmware/drivers/scanner.h @@ -1,4 +1,26 @@ -/* scanner.h */ +/* scanner.h + * + * Copyright (c) 2016 by Nick Bertoldi, Ben Heckathorn, Ryan O'Keefe, + * Adrian Padin, Timothy Schumacher + * + * Permission is hereby granted, free of charge, to any person obtaining + * a copy of this software and associated documentation files (the "Software"), + * to deal in the Software without restriction, including without limitation + * the rights to use, copy, modify, merge, publish, distribute, sublicense, + * and/or sell copies of the Software, and to permit persons to whom the + * Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included + * in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS + * IN THE SOFTWARE. + */ #ifndef SCANNER_H_ #define SCANNER_H_ diff --git a/mbed-dongle-firmware/drivers/serial_com.h b/mbed-dongle-firmware/drivers/serial_com.h index a2bd6e3..8a33d10 100644 --- a/mbed-dongle-firmware/drivers/serial_com.h +++ b/mbed-dongle-firmware/drivers/serial_com.h @@ -1,4 +1,26 @@ -// serial_com.h +/* serial_com.h + * + * Copyright (c) 2016 by Nick Bertoldi, Ben Heckathorn, Ryan O'Keefe, + * Adrian Padin, Timothy Schumacher + * + * Permission is hereby granted, free of charge, to any person obtaining + * a copy of this software and associated documentation files (the "Software"), + * to deal in the Software without restriction, including without limitation + * the rights to use, copy, modify, merge, publish, distribute, sublicense, + * and/or sell copies of the Software, and to permit persons to whom the + * Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included + * in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS + * IN THE SOFTWARE. + */ #ifndef SERIAL_COM_H_ #define SERIAL_COM_H_ diff --git a/mbed-dongle-firmware/drivers/touch_sensor.cpp b/mbed-dongle-firmware/drivers/touch_sensor.cpp deleted file mode 100644 index 70d1829..0000000 --- a/mbed-dongle-firmware/drivers/touch_sensor.cpp +++ /dev/null @@ -1,169 +0,0 @@ -/* - * Filename: touch_sensor.cpp - * Project: EECS 473 - Team GLOVE - * Date: Fall 2016 - * Authors: - * Nick Bertoldi - * Ben Heckathorn - * Ryan O’Keefe - * Adrian Padin - * Tim Schumacher - * - * Purpose: - * Top-level interface for working with capacitive sensor chip, - * which uses I2C and can communicate the values of up to 7 sensors - * - * The AT42QT1070 in I2C comms mode can use a single interrupt line - * to indicate a change in state of the sensors. - */ -#include "touch_sensor.h" - -TouchSensor::TouchSensor(PinName sda, PinName scl, PinName intr) : qt(sda, scl) { - initialize(intr); -} - -TouchSensor::TouchSensor(I2C& i2c, PinName intr) - : qt(i2c) { - initialize(intr); -} - - -void TouchSensor::initialize(PinName intr) { - needs_restart = false; - writeStaticConfig(); - qt.getButtonsState(); - - // Associate the update function with the interrupt CHANGE line - if (intr != NC) { - if (TOUCH_DIGITALIN_CHANGE) { - change_line = new DigitalIn(intr); - } - else { - change_event = new InterruptIn(intr); - change_event->fall(this, &TouchSensor::changeEventHandler); - } - } -} - -void TouchSensor::writeStaticConfig() { - qt.setGuard(TOUCH_GUARD_KEY); - qt.setLowPowerMode(TOUCH_LP_MODE); - qt.setMaxOn(TOUCH_MAX_ON); - - for (uint8_t k = 0; k < 7; ++k) { - qt.setThreshold(k, TOUCH_NTHRESHOLD); - qt.setDetectionIntegrator(k, TOUCH_DI); - qt.setAVE(k, TOUCH_AVE); - qt.setAKSGroup(k, TOUCH_AKS[k]); - } -} - -void TouchSensor::writeKeys(key_states_t* key_states) { - key_states->a = keys.a; - key_states->b = keys.b; - key_states->c = keys.c; - key_states->d = keys.d; -} - -/* XXX -extern DigitalOut l4; -extern DigitalOut l2; -uint16_t faaiil = 0; -volatile uint8_t count; -*/ // XXX - -void TouchSensor::update() { - - /* XXX - if (faaiil++ > 50) { - faaiil = 0; - for (;;) {count += 1;} - } - */ // XXX - - /* Use the change line to avoid unnessescary - * I2C I/O, but without being an interrupt - */ - if (*change_line == 1) { - return; - } - uint8_t buttons = qt.getButtonsState(); - - // Check overflow flag - if (buttons & 0x80) { - // do something about it - return; - } - - // just get the keys we want - keys.a = (buttons & 0x01); // key 0 - keys.b = (buttons & 0x02) >> 1; // key 1 - keys.c = (buttons & 0x04) >> 2; // key 2 - keys.d = (buttons & 0x08) >> 3; // key 3 - //keys.e = buttons & 0x10; // key 4 - //keys.f = buttons & 0x20; // key 5 - //keys.g = buttons & 0x40; // key 6 -} - -void TouchSensor::updateAndWrite(key_states_t* key_states) { - update(); - writeKeys(key_states); -} - -void TouchSensor::reset() { - qt.reset(); - writeStaticConfig(); - qt.getButtonsState(); -} - -void TouchSensor::changeEventHandler() { - do_update.release(); -} - -void TouchSensor::updateTask() { - for (;;) { - do_update.wait(osWaitForever); - update(); - } -} - -void TouchSensor::singleUpdate() { - if (needs_restart) { - //reset(); // This broke everything :( cuz it takes too long (disable irq??) - //qt.reset(); - //qt.getButtonsState(); - } - - //l4 = 0; // XXX - needs_restart = true; - update(); - //l4 = 1; // XXX - needs_restart = false; - - update_thread->terminate(); -} - -void TouchSensor::spawnUpdateThread() { - update_thread = new Thread; - update_thread->start(this, &TouchSensor::singleUpdate); - Thread::yield(); -} - -void TouchSensor::terminateUpdateThreadIfBlocking() { - if (needs_restart) { - //l2 = 0; // XXX - //l4 = 1; // XXX - update_thread->terminate(); - // Leave reset in the update funtion cuz don't block here - // Might skip full reset??? Maybe count then do it after X hangs - //l2 = 1; // XXX - } - delete update_thread; - update_thread = NULL; -} - -void TouchSensor::print(Serial& pc, key_states_t& keys_) { - pc.printf("Keys: %hu %hu %hu %hu\r\n", - keys_.a, keys_.b, keys_.c, keys_.d); -} - diff --git a/mbed-dongle-firmware/drivers/touch_sensor.h b/mbed-dongle-firmware/drivers/touch_sensor.h index 4e0a317..cd12bd1 100644 --- a/mbed-dongle-firmware/drivers/touch_sensor.h +++ b/mbed-dongle-firmware/drivers/touch_sensor.h @@ -1,5 +1,6 @@ /* - * Filename: touch_sensor.h * Project: EECS 473 - Team GLOVE + * Filename: touch_sensor.h + * Project: EECS 473 - Team GLOVE * Date: Fall 2016 * Authors: * Nick Bertoldi @@ -8,25 +9,29 @@ * Adrian Padin * Tim Schumacher * - * Purpose: * Top-level interface for working with capacitive sensor chip, - * which uses I2C and can communicate the values of up to 7 sensors + * Purpose: + * Define the data structure for the touch sensor data * - * The AT42QT1070 in I2C comms mode can use a single interrupt line - * to indicate a change in state of the sensors. + * Copyright (c) 2016 by Nick Bertoldi, Ben Heckathorn, Ryan O'Keefe, + * Adrian Padin, Timothy Schumacher * - * Usage: needs Thread and TouchSensor objects - * TouchSensor touch_sensor; - * Thread touch_sensor_thread; - * touch_sensor_thread.start(&touch_sensor, &TouchSensor::updateTask); + * Permission is hereby granted, free of charge, to any person obtaining + * a copy of this software and associated documentation files (the "Software"), + * to deal in the Software without restriction, including without limitation + * the rights to use, copy, modify, merge, publish, distribute, sublicense, + * and/or sell copies of the Software, and to permit persons to whom the + * Software is furnished to do so, subject to the following conditions: * - ************************ - * NOTES - * Calibrate: - * - can send into "calibration cycle" with any non-zero value + * The above copyright notice and this permission notice shall be included + * in all copies or substantial portions of the Software. * - * Reset: - * - soft reset with any non-zero value - * - hard reset with minimum 5us pulse to reset line + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS + * IN THE SOFTWARE. */ #ifndef TOUCH_SENSOR_H_ @@ -34,62 +39,6 @@ #include -#include "mbed.h" - -#include "at42qt1070.h" - -const PinName TOUCH_I2C_SCL = I2C_SCL0; // = p7 -const PinName TOUCH_I2C_SDA = I2C_SDA0; // = p30 -const PinName TOUCH_INTERRUPT = p13; // CHANGE interrupt line (active low) -const PinName TOUCH_NO_INTERRUPT = NC; // Don't use an interrupt -const bool TOUCH_DIGITALIN_CHANGE = true; // use DigitalIn instead of InterruptIn - -/* Low-Power Mode: - * - set multiple of 8ms between key measurements, default 2 (16ms) - * - using 0, for best response time - */ -const uint8_t TOUCH_LP_MODE = 0; - -/* Max On: - * - default is 180 steps of 160ms (28.8 seconds) - * - might want this to be off (0) - */ -const uint8_t TOUCH_MAX_ON = 0; - -/* Guard Key: - * - default is key 0 - * - 0..6 valid as guard key, 7 disables guard key function - */ -const uint8_t TOUCH_GUARD_KEY = 7; - -/* Negative Threshold: - * - default is 20 - * - unsure what units these are, but more is less sensitive - */ -const uint8_t TOUCH_NTHRESHOLD = 255; //seem to need the maximum to avoid accidental touch/proximity - -/* Averaging Factor: - * - default is 8 - * - number of pulses to average for a channel - * - values restricted internally to 1,2,4,8,16,32 - */ -const uint8_t TOUCH_AVE = 8; - -/* Detection Integrator: - * - default is 4 - * - number of consecutive measurementsthat must be confirmed as - * having passed the hey threshold before key is registered in detect - */ -const uint8_t TOUCH_DI = 4; - -/* Adjacent Key Suppression: - * - group 0 disables feature - * - 1, 2, 3 are available groups - * - only one key in each group can be in detect simultaniously - * - group for each key [0..7] - */ -const uint8_t TOUCH_AKS[] = {0, 0, 0, 0, 0, 0, 0}; //{0, 1, 2, 1, 2, 0, 0}; - /* * Unpacks the _buttonStates byte in AT42QT1070 to * the desired keys as struct members @@ -105,119 +54,4 @@ typedef struct { } } key_states_t; -class TouchSensor { -public: - /* - * Default constructor - * - * Writes all the static config settings to the sensor - * Assosciates the update() method with the CHANGE event line - */ - TouchSensor(PinName sda=TOUCH_I2C_SDA, - PinName scl=TOUCH_I2C_SCL, - PinName intr=TOUCH_NO_INTERRUPT); - - /* - * Alternate constructor - takes refrecne to mbed::I2C object - * - * Writes all the static config settings to the sensor - * Assosciates the update() method with the CHANGE event line - */ - TouchSensor(I2C& i2c, PinName intr=TOUCH_NO_INTERRUPT); - - /* - * Write the configuration values defined above - */ - void writeStaticConfig(); - - /* - * Copy the key states to the given key states struct - * Internal mutual exclusion is used to exclude update() - */ - void writeKeys(key_states_t* key_states); - - /* - * Update the in memory state for the keys, - * asking for the key states over I2C - * - * Measured to take approximately 1.01 ms - */ - void update(); - - /* - * Do both the update and then write the key states - * - * Use with polling - */ - void updateAndWrite(key_states_t* key_states); - - /* - * Does a soft reset then re-configured the chip - */ - void reset(); - - /* - * Callback for the change event interrupt line - */ - void changeEventHandler(); - - /* - * Task loop for updating the buttons on change event - * - * Usage: needs Thread and TouchSensor objects - * TouchSensor touch_sensor; - * Thread touch_sensor_thread; - * touch_sensor_thread.start(&touch_sensor, &TouchSensor::updateTask); - */ - void updateTask(); - - /* - * This update task check to see if a reset is required, - * runs the update() function, - */ - void singleUpdate(); - - /* - * Spawns a thread to run singleUpdate() then yields. - * Use at the beginning of sensor-polling periodic function. - */ - void spawnUpdateThread(); - - /* - * If using spawnUpdateThread MUST be called at the end - * of the same periodic funciton. - * - * Terminates the update thread if hung and sets up for a reset - * on next update called. - */ - void terminateUpdateThreadIfBlocking(); - - /* - * Print out the given key states - */ - static void print(Serial& pc, key_states_t&); - -private: - void initialize(PinName intr); - -private: - AT42QT1070 qt; - key_states_t keys; - - /* - * Deferred-interrupt based touch sensor - */ - InterruptIn* change_event; - Semaphore do_update; - - /* Polling in spawned thread - * - * needs_restart signals if the touch sensor was killed - * while hanging on the bus, thus needs to get restarted - */ - Thread* update_thread; - DigitalIn* change_line; - bool needs_restart; -}; - #endif /* TOUCH_SENSOR_H_ */ diff --git a/mbed-dongle-firmware/drivers/translate_task.cpp b/mbed-dongle-firmware/drivers/translate_task.cpp index df0780f..d1e1bf2 100644 --- a/mbed-dongle-firmware/drivers/translate_task.cpp +++ b/mbed-dongle-firmware/drivers/translate_task.cpp @@ -1,5 +1,5 @@ /* - * Filename: translator.cpp + * Filename: translate_task.cpp * Project: EECS 473 - Team GLOVE * Date: Fall 2016 * Authors: @@ -10,8 +10,30 @@ * Tim Schumacher * * Purpose: - * Implementation of translatorTask + * Implementation of TranslateTask + * + * Copyright (c) 2016 by Nick Bertoldi, Ben Heckathorn, Ryan O'Keefe, + * Adrian Padin, Timothy Schumacher + * + * Permission is hereby granted, free of charge, to any person obtaining + * a copy of this software and associated documentation files (the "Software"), + * to deal in the Software without restriction, including without limitation + * the rights to use, copy, modify, merge, publish, distribute, sublicense, + * and/or sell copies of the Software, and to permit persons to whom the + * Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included + * in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS + * IN THE SOFTWARE. */ + #include "translate_task.h" TranslateTask::TranslateTask(Translator& left_, Translator& right_, KeyboardMouse& input_) diff --git a/mbed-dongle-firmware/drivers/translate_task.h b/mbed-dongle-firmware/drivers/translate_task.h index cdad47b..1c7ad86 100644 --- a/mbed-dongle-firmware/drivers/translate_task.h +++ b/mbed-dongle-firmware/drivers/translate_task.h @@ -1,10 +1,46 @@ +/* + * Filename: translate_task.h + * Project: EECS 473 - Team GLOVE + * Date: Fall 2016 + * Authors: + * Nick Bertoldi + * Ben Heckathorn + * Ryan O’Keefe + * Adrian Padin + * Tim Schumacher + * + * Purpose: + * Encapsulate the Translator objects and control their periodic + * execution and then updates on the BLE HID connection + * + * Copyright (c) 2016 by Nick Bertoldi, Ben Heckathorn, Ryan O'Keefe, + * Adrian Padin, Timothy Schumacher + * + * Permission is hereby granted, free of charge, to any person obtaining + * a copy of this software and associated documentation files (the "Software"), + * to deal in the Software without restriction, including without limitation + * the rights to use, copy, modify, merge, publish, distribute, sublicense, + * and/or sell copies of the Software, and to permit persons to whom the + * Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included + * in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS + * IN THE SOFTWARE. + */ + #ifndef TRANSLATE_TASK_H_ #define TRANSLATE_TASK_H_ #include "translator.h" -#include "gpio.h" #include "keyboard_mouse.h" -#include "mbed.h" +#include "gpio.h" class TranslateTask { public: @@ -20,5 +56,4 @@ class TranslateTask { RtosTimer* update_task_timer; }; - #endif diff --git a/mbed-dongle-firmware/drivers/translator.cpp b/mbed-dongle-firmware/drivers/translator.cpp index 7d69080..b833c91 100644 --- a/mbed-dongle-firmware/drivers/translator.cpp +++ b/mbed-dongle-firmware/drivers/translator.cpp @@ -11,6 +11,27 @@ * * Purpose: * Implementation of translator.h + * + * Copyright (c) 2016 by Nick Bertoldi, Ben Heckathorn, Ryan O'Keefe, + * Adrian Padin, Timothy Schumacher + * + * Permission is hereby granted, free of charge, to any person obtaining + * a copy of this software and associated documentation files (the "Software"), + * to deal in the Software without restriction, including without limitation + * the rights to use, copy, modify, merge, publish, distribute, sublicense, + * and/or sell copies of the Software, and to permit persons to whom the + * Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included + * in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS + * IN THE SOFTWARE. */ #include "translator.h" @@ -18,17 +39,18 @@ #define ACTIVE_LOW true #define ACTIVE_HIGH false -/* DEBUG */ -const PinName TRANSLATOR_DEBUG_PIN = p26; - Translator::Translator(glove_sensors_raw_t& _glove_data, KeyboardMouse& _HIDinput, bool is_l, flexToHID* f, touchToHID* t, imuToHID* i) - : glove_data(_glove_data), HIDinput(_HIDinput), is_left(is_l), flex_sensors(f), touch_sensors(t), imu_axis(i), - working(TRANSLATOR_DEBUG_PIN) { + : glove_data(_glove_data), + HIDinput(_HIDinput), + is_left(is_l), + flex_sensors(f), + touch_sensors(t), + imu_axis(i) { /* FLEX */ flex_sensors[FLEX1].init(glove_data.flex_sensors, 380, 820, 0.25); @@ -301,6 +323,3 @@ void Translator::handleMouseInput(mouseData& mouse) { } } // if valid } - -void Translator::startUpdateTask(uint32_t ms) { update_task_timer->start(ms); } -void Translator::stopUpdateTask() { update_task_timer->stop(); } diff --git a/mbed-dongle-firmware/drivers/translator.h b/mbed-dongle-firmware/drivers/translator.h index 29f419c..2bf18df 100644 --- a/mbed-dongle-firmware/drivers/translator.h +++ b/mbed-dongle-firmware/drivers/translator.h @@ -6,17 +6,37 @@ * Nick Bertoldi * Ben Heckathorn * Ryan O’Keefe - * Adrian Padin * Tim Schumacher + * Adrian Padin + * Tim Schumacher * * Purpose: * Translator to interpret glove data as HID input + * + * Copyright (c) 2016 by Nick Bertoldi, Ben Heckathorn, Ryan O'Keefe, + * Adrian Padin, Timothy Schumacher + * + * Permission is hereby granted, free of charge, to any person obtaining + * a copy of this software and associated documentation files (the "Software"), + * to deal in the Software without restriction, including without limitation + * the rights to use, copy, modify, merge, publish, distribute, sublicense, + * and/or sell copies of the Software, and to permit persons to whom the + * Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included + * in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS + * IN THE SOFTWARE. */ #ifndef TRANSLATOR_H_ #define TRANSLATOR_H_ -#include - #include "mbed.h" #include "analog_button.h" @@ -80,17 +100,6 @@ class Translator { */ void gestureCheck(); - /* - * Calls the start() method on the periodic update task, - * an internal timer is set up in the constructor - */ - void startUpdateTask(uint32_t ms); - - /* - * Calls the stop() method on the periodic update timer, - */ - void stopUpdateTask(); - private: void handleKeyboardInput(keyboardData&); void handleMouseInput(mouseData&); @@ -107,9 +116,6 @@ class Translator { flexToHID* flex_sensors; touchToHID* touch_sensors; imuToHID* imu_axis; - - RtosTimer* update_task_timer; - DigitalOut working; }; #endif /* TRANSLATOR_H_ */