-
Notifications
You must be signed in to change notification settings - Fork 4
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
0 parents
commit 10f5c67
Showing
26 changed files
with
3,190 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
|
||
|
||
# config: | ||
ROBOT_CONFIG.hpp | ||
|
||
__pycache__ | ||
|
||
## vim swap files: | ||
.*.swp | ||
|
||
|
||
|
||
## Mbed-os: | ||
|
||
.mbed | ||
BUILD/ | ||
GettingStarted.html | ||
Makefile | ||
mbed-os.lib | ||
mbed-os/ | ||
mbed_config.h | ||
mbed_settings.py | ||
|
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,79 @@ | ||
|
||
#include "Compass.hpp" | ||
|
||
|
||
// Compass chip is: ST LIS3MDL | ||
// (old compass chip was: AK09916 from the HERE2 GPS) | ||
|
||
Compass::Compass(PinName sda, PinName scl) { | ||
_i2c = new I2C(sda, scl); | ||
//_i2c.frequency(400000); | ||
_ready = false; | ||
|
||
_compass_addr8bit = 0x1e << 1; | ||
_leds_addr8bit = 0x55 << 1; | ||
} | ||
|
||
|
||
void Compass::_write_register(char reg, char value) { | ||
char txBuf[2] = {reg, value}; | ||
_i2c->write(_compass_addr8bit, txBuf, 2); | ||
} | ||
|
||
|
||
ssize_t Compass::init() { | ||
char txBuf[2]; | ||
char rxBuf[2] = {0, 0}; | ||
|
||
|
||
txBuf[0] = 0x0f; // WHO_AM_I | ||
_i2c->write(_compass_addr8bit, txBuf, 1); | ||
_i2c->read(_compass_addr8bit, rxBuf, 1); | ||
|
||
if (rxBuf[0] != 0x3d) { | ||
return -1; | ||
} | ||
|
||
_write_register(0x20, 0xfc); | ||
_write_register(0x21, 0x00); | ||
_write_register(0x22, 0x00); | ||
_write_register(0x23, 0x0c); | ||
_write_register(0x24, 0x40); | ||
|
||
_ready = true; | ||
return 0; | ||
} | ||
|
||
ssize_t Compass::get_data(int16_t *xyz) { | ||
|
||
char txBuf[2] = {0x28, 0x0}; | ||
|
||
if (!_ready) { | ||
return 0; | ||
} | ||
|
||
_i2c->write(_compass_addr8bit, txBuf, 1); | ||
_i2c->read(_compass_addr8bit, (char*) xyz, 6); | ||
|
||
return 6; | ||
} | ||
|
||
|
||
int Compass::set_leds(uint8_t red, uint8_t green, uint8_t blue) { | ||
|
||
// Inputs range from 0 to 15 (4 bits) | ||
|
||
char txBuf[5] = {0x01, 0,0,0, 0x83}; | ||
|
||
//txBuf[0] = 0x01; // pwm0 register | ||
txBuf[1] = blue & 0x0f; | ||
txBuf[2] = green & 0x0f; | ||
txBuf[3] = red & 0x0f; | ||
//txBuf[4] = 0x83; // enable, and stop auto-incrementing sequential writes | ||
_i2c->write(_leds_addr8bit, txBuf, 5); | ||
|
||
return 0; | ||
} | ||
|
||
|
||
|
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,41 @@ | ||
#ifndef __COMPASS_HPP_ | ||
#define __COMPASS_HPP_ | ||
|
||
#include "mbed.h" | ||
|
||
// This is for the HERE2 Compass, i2c portion | ||
|
||
// The HERE2 compass has a GPS on Async serial. | ||
// In i2c mode, it has a compass and an RGB LED. | ||
|
||
|
||
|
||
//#define ADDR_7_BIT 0x0c | ||
//#define ADDR_8_BIT 0x18 | ||
// ie: 0x0c << 1 | ||
|
||
class Compass { | ||
|
||
public: | ||
Compass(PinName, PinName); | ||
ssize_t init(); | ||
ssize_t get_data(int16_t*); | ||
|
||
int set_leds(uint8_t, uint8_t, uint8_t); | ||
|
||
private: | ||
I2C *_i2c; | ||
bool _ready; | ||
|
||
// WTF, why can't I make this work? | ||
//const int _addr8bit = ADDR_8_BIT; | ||
//const int _addr8bit = 0x18; | ||
|
||
int _compass_addr8bit; | ||
int _leds_addr8bit; | ||
|
||
void _write_register(char, char); | ||
|
||
}; | ||
|
||
#endif// __COMPASS_HPP_ |
Oops, something went wrong.