-
Notifications
You must be signed in to change notification settings - Fork 38
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Initial compass emu support. Impliment compass related api func symbo…
…ls, compass service, and qemu endpoints
- Loading branch information
Showing
11 changed files
with
223 additions
and
8 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
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,53 @@ | ||
/* compass.c | ||
* routines for controlling the compass (accelerometer + magnetometer) | ||
* RebbleOS | ||
* | ||
* Author: Taylor E. <taylor@stanivision.com> | ||
*/ | ||
|
||
#include "compass.h" | ||
#include "rebbleos.h" | ||
#include "compass_service.h" | ||
|
||
static uint8_t _calibration_mode = 0; | ||
static int32_t _compass_heading = 0; | ||
static int32_t _compass_heading_filter = (TRIG_MAX_ANGLE / 360); | ||
|
||
void compass_init() { | ||
|
||
} | ||
|
||
void compass_off() { | ||
|
||
} | ||
|
||
uint8_t compass_get_calibration_mode(void) { | ||
return _calibration_mode; | ||
} | ||
|
||
int32_t compass_get_heading(void) { | ||
return _compass_heading; | ||
} | ||
|
||
int32_t compass_get_heading_filter(void) { | ||
return _compass_heading_filter; | ||
} | ||
|
||
// These set functions have been put here so the Compass Emu protocol can update the Compass' values (this was made first). | ||
// However these functions probably shouldn't exist, as this file should be polling hardware to get latest values, not having hardware | ||
// push to this file... | ||
|
||
void compass_set_calibration_mode(uint8_t new_compass_calibration_mode) { | ||
_calibration_mode = new_compass_calibration_mode; | ||
compass_service_state_change(); | ||
} | ||
|
||
void compass_set_heading(int32_t new_compass_heading) { | ||
_compass_heading = new_compass_heading; | ||
compass_service_state_change(); | ||
} | ||
|
||
void compass_set_heading_filter(int32_t new_compass_heading_filter) { | ||
_compass_heading_filter = new_compass_heading_filter; | ||
compass_service_state_change(); | ||
} |
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,31 @@ | ||
#pragma once | ||
/* compass.c | ||
* routines for controlling the compass (accelerometer + magnetometer) | ||
* RebbleOS | ||
* | ||
* Author: Taylor E. <taylor@stanivision.com> | ||
*/ | ||
|
||
#include "FreeRTOS.h" | ||
|
||
/** | ||
* @brief Compass calibration modes. | ||
*/ | ||
#define COMPASS_CAL_STATUS_UNAVAILABLE 0 | ||
#define COMPASS_CAL_STATUS_DATA_INVALID 1 | ||
#define COMPASS_CAL_STATUS_CALIBRATING 2 | ||
#define COMPASS_CAL_STATUS_CALIBRATED 3 | ||
|
||
void compass_init(void); | ||
|
||
void compass_off(void); | ||
|
||
uint8_t compass_get_calibration_mode(void); | ||
|
||
int32_t compass_get_heading(void); | ||
|
||
int32_t compass_get_heading_filter(void); | ||
|
||
void compass_set_heading_filter(int32_t new_compass_heading_filter); | ||
void compass_set_calibration_mode(uint8_t new_compass_calibration_mode); | ||
void compass_set_heading(int32_t new_compass_heading); |
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,28 @@ | ||
/* protocol_compass.c | ||
* R/Pebble Protocol Compass requests. | ||
* libRebbleOS | ||
* | ||
* Author: Taylor E. <taylor@stanivision.com> | ||
*/ | ||
#include "rebbleos.h" | ||
#include "protocol.h" | ||
#include "protocol_service.h" | ||
#include "compass_service.h" | ||
/* Configure Logging */ | ||
#define MODULE_NAME "pcolcompass" | ||
#define MODULE_TYPE "SYS" | ||
#define LOG_LEVEL RBL_LOG_LEVEL_DEBUG //RBL_LOG_LEVEL_ERROR | ||
|
||
typedef struct qemu_compass_t { | ||
uint32_t heading; | ||
uint8_t calibrated; | ||
} __attribute__((__packed__)) qemu_compass; | ||
|
||
void protocol_compass_handler(const RebblePacket packet) | ||
{ | ||
qemu_compass *qemu_compass_payload = (qemu_compass *) packet_get_data(packet); | ||
qemu_compass_payload->heading = ntohl(qemu_compass_payload->heading); | ||
|
||
compass_set_calibration_mode(qemu_compass_payload->calibrated); | ||
compass_set_heading(qemu_compass_payload->heading); | ||
} |
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,5 @@ | ||
#pragma once | ||
|
||
#include "protocol.h" | ||
|
||
void protocol_compass_handler(const RebblePacket packet); |
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
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,50 @@ | ||
/* routines that implement the PebbleOS compass api | ||
* libRebbleOS | ||
* | ||
* Author: Taylor E. <taylor@stanivision.com> | ||
* | ||
*/ | ||
|
||
#include "librebble.h" | ||
#include "compass_service.h" | ||
|
||
static CompassHeadingHandler _state_handler; | ||
|
||
int compass_service_set_heading_filter(CompassHeading filter) { | ||
if (filter < 0 || filter > (TRIG_MAX_ANGLE / 2)) { | ||
return -1; | ||
} | ||
else { | ||
compass_set_heading_filter(filter); | ||
return 0; | ||
} | ||
|
||
} | ||
|
||
void compass_service_subscribe(CompassHeadingHandler handler) { | ||
_state_handler = handler; | ||
} | ||
|
||
void compass_service_unsubscribe(void) { | ||
_state_handler = NULL; | ||
} | ||
|
||
int compass_service_peek(CompassHeadingData * data) { | ||
data->magnetic_heading = compass_get_heading(); | ||
data->true_heading = compass_get_heading(); | ||
data->compass_status = compass_get_calibration_mode(); | ||
data->is_declination_valid = false; | ||
|
||
return 0; | ||
} | ||
|
||
void compass_service_state_change(void) | ||
{ | ||
SYS_LOG("COMP", APP_LOG_LEVEL_INFO, "Update"); | ||
|
||
CompassHeadingData new_compass_heading_data; | ||
compass_service_peek(&new_compass_heading_data); | ||
|
||
if (_state_handler != NULL) | ||
_state_handler(new_compass_heading_data); | ||
} |
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,38 @@ | ||
/* routines that implement the PebbleOS compass api | ||
*/ | ||
|
||
/** | ||
* @brief Represents an angle relative to get to a reference direction, e.g. (magnetic) north. The angle value is scaled linearly, such that a value of TRIG_MAX_ANGLE corresponds to 360 degrees or 2 PI radians. Thus, if heading towards north, north is 0, west is TRIG_MAX_ANGLE/4, south is TRIG_MAX_ANGLE/2, and so on. | ||
*/ | ||
typedef int32_t CompassHeading; | ||
|
||
typedef enum { | ||
CompassStatusUnavailable, /* The Compass Service is unavailable. */ | ||
CompassStatusDataInvalid, /* Compass is calibrating: data is invalid and should not be used Data will become valid once calibration is complete. */ | ||
CompassStatusCalibrating, /* Compass is calibrating: the data is valid but the calibration is still being refined. */ | ||
CompassStatusCalibrated /* Compass data is valid and the calibration has completed. */ | ||
} CompassStatus; | ||
|
||
typedef struct { | ||
CompassHeading magnetic_heading; /* Measured angle that increases counter-clockwise from magnetic north (use int clockwise_heading = TRIG_MAX_ANGLE - heading_data.magnetic_heading; for example to find your heading clockwise from magnetic north). */ | ||
CompassHeading true_heading; /* Currently same value as magnetic_heading (reserved for future implementation). */ | ||
CompassStatus compass_status; /* Indicates the current state of the Compass Service calibration. */ | ||
bool is_declination_valid; /* Currently always false (reserved for future implementation). */ | ||
} CompassHeadingData; | ||
|
||
/** | ||
* @brief Callback type for compass heading events. | ||
* @param heading A copy of last recorded heading. | ||
*/ | ||
typedef void(* CompassHeadingHandler)(CompassHeadingData heading); | ||
|
||
int compass_service_set_heading_filter(CompassHeading filter); | ||
|
||
void compass_service_subscribe(CompassHeadingHandler handler); | ||
|
||
void compass_service_unsubscribe(void); | ||
|
||
int compass_service_peek(CompassHeadingData * data); | ||
|
||
void compass_service_hw_state_change(void); | ||
void compass_service_emu_state_change(CompassHeadingData emu_data); |
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