Compare commits
3 Commits
9820b1ddb0
...
eaf5473928
Author | SHA1 | Date | |
---|---|---|---|
|
eaf5473928 | ||
|
a636659a95 | ||
|
4f65089b22 |
@ -2,10 +2,6 @@
|
|||||||
#include "i2c.h"
|
#include "i2c.h"
|
||||||
#include "QMC5883L.h"
|
#include "QMC5883L.h"
|
||||||
|
|
||||||
#ifndef PI
|
|
||||||
#define PI 3.14159265358979f
|
|
||||||
#endif
|
|
||||||
|
|
||||||
typedef struct
|
typedef struct
|
||||||
{
|
{
|
||||||
int16_t x_min;
|
int16_t x_min;
|
||||||
@ -14,6 +10,7 @@ typedef struct
|
|||||||
int16_t y_max;
|
int16_t y_max;
|
||||||
int16_t z_min;
|
int16_t z_min;
|
||||||
int16_t z_max;
|
int16_t z_max;
|
||||||
|
float temperature_offset;
|
||||||
} _QMC5883L_calibration_data;
|
} _QMC5883L_calibration_data;
|
||||||
|
|
||||||
static _QMC5883L_calibration_data calibration_data = {0};
|
static _QMC5883L_calibration_data calibration_data = {0};
|
||||||
@ -42,7 +39,7 @@ float QMC5883L_get_temperature(void)
|
|||||||
|
|
||||||
raw_temp |= data;
|
raw_temp |= data;
|
||||||
|
|
||||||
return (float) raw_temp / 100.0;
|
return (float) raw_temp / 100.0 + calibration_data.temperature_offset;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool QMC5883L_is_data_available(void)
|
bool QMC5883L_is_data_available(void)
|
||||||
@ -54,7 +51,7 @@ bool QMC5883L_is_data_available(void)
|
|||||||
return data & QMC5883L_DRDY_BIT ? true : false;
|
return data & QMC5883L_DRDY_BIT ? true : false;
|
||||||
}
|
}
|
||||||
|
|
||||||
void QMC5883L_set_calibration_data(int16_t x_min, int16_t x_max, int16_t y_min, int16_t y_max, int16_t z_min, int16_t z_max)
|
void QMC5883L_set_calibration_data(int16_t x_min, int16_t x_max, int16_t y_min, int16_t y_max, int16_t z_min, int16_t z_max, float temperature_offset)
|
||||||
{
|
{
|
||||||
calibration_data.x_min = x_min;
|
calibration_data.x_min = x_min;
|
||||||
calibration_data.x_max = x_max;
|
calibration_data.x_max = x_max;
|
||||||
@ -62,6 +59,7 @@ void QMC5883L_set_calibration_data(int16_t x_min, int16_t x_max, int16_t y_min,
|
|||||||
calibration_data.y_max = y_max;
|
calibration_data.y_max = y_max;
|
||||||
calibration_data.z_min = z_min;
|
calibration_data.z_min = z_min;
|
||||||
calibration_data.z_max = z_max;
|
calibration_data.z_max = z_max;
|
||||||
|
calibration_data.temperature_offset = temperature_offset;
|
||||||
}
|
}
|
||||||
|
|
||||||
QMC5883L_MData_t QMC5883L_get_MFields_raw(void)
|
QMC5883L_MData_t QMC5883L_get_MFields_raw(void)
|
||||||
@ -111,9 +109,9 @@ QMC5883L_MData_calibrated_t QMC5883L_get_MFields_calibrated(void)
|
|||||||
return Mdata;
|
return Mdata;
|
||||||
}
|
}
|
||||||
|
|
||||||
int16_t QMC5883L_get_azimuth(const QMC5883L_MData_calibrated_t data)
|
uint16_t QMC5883L_get_azimuth(const QMC5883L_MData_calibrated_t data)
|
||||||
{
|
{
|
||||||
int16_t angle = atan2(data.MFieldY, data.MFieldX) * 180.0 / PI;
|
int16_t angle = atan2(data.MFieldY, data.MFieldX) * 180.0 / M_PI;
|
||||||
return angle < 0 ? 360 + angle : angle;
|
return angle < 0 ? 360 + angle : angle;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -63,27 +63,116 @@ typedef struct
|
|||||||
} QMC5883L_MData_calibrated_t;
|
} QMC5883L_MData_calibrated_t;
|
||||||
|
|
||||||
|
|
||||||
/* QMC5883L Driver API */
|
/**
|
||||||
|
* @brief Initializes the QMC5883L sensor. This must be called before any other API functions.
|
||||||
|
* Don't forget to initialize the I2C peripheral using the i2c_init function first !
|
||||||
|
*
|
||||||
|
* @return true on success
|
||||||
|
* @return false on failure
|
||||||
|
*/
|
||||||
bool QMC5883L_init(void);
|
bool QMC5883L_init(void);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Issues a software reset of the sensor.
|
||||||
|
*
|
||||||
|
* @return true on success
|
||||||
|
* @return false on failure
|
||||||
|
*/
|
||||||
bool QMC5883L_software_reset(void);
|
bool QMC5883L_software_reset(void);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Gets the temperature measured by the sensor in degrees celsius.
|
||||||
|
* Only the relative temperature value is accurate !
|
||||||
|
* If you need the real temperature, a calibration offset IS NEEDED using the @ref QMC5883L_set_calibration_data function !
|
||||||
|
*
|
||||||
|
* @return float the temperature in °C
|
||||||
|
*/
|
||||||
float QMC5883L_get_temperature(void);
|
float QMC5883L_get_temperature(void);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Indicates if data is ready to be read from the sensor or not.
|
||||||
|
* You can check the ouput of this function before calling @ref QMC5883L_get_MFields_raw or @ref QMC5883L_get_MFields_calibrated.
|
||||||
|
*
|
||||||
|
* @return true if data is available
|
||||||
|
* @return false if no data is available
|
||||||
|
*/
|
||||||
bool QMC5883L_is_data_available(void);
|
bool QMC5883L_is_data_available(void);
|
||||||
|
|
||||||
void QMC5883L_set_calibration_data(int16_t x_min, int16_t x_max, int16_t y_min, int16_t y_max, int16_t z_min, int16_t z_max);
|
/**
|
||||||
|
* @brief Sets all the calibration data needed to get accurate readings from the sensor.
|
||||||
|
* Default value if not set is 0.
|
||||||
|
* You can use the @ref QMC5883L_get_MFields_raw function to get raw readings from the sensor in order to find the min and max values of the three axes.
|
||||||
|
*
|
||||||
|
* @param x_min the min value of the magnetic field on the X axis
|
||||||
|
* @param x_max the max value of the magnetic field on the X axis
|
||||||
|
* @param y_min the min value of the magnetic field on the Y axis
|
||||||
|
* @param y_max the max value of the magnetic field on the Y axis
|
||||||
|
* @param z_min the min value of the magnetic field on the Z axis
|
||||||
|
* @param z_max the max value of the magnetic field on the Z axis
|
||||||
|
* @param temperature_offset the temperature offset needed to be applied to get an accurate reading
|
||||||
|
*/
|
||||||
|
void QMC5883L_set_calibration_data(int16_t x_min, int16_t x_max, int16_t y_min, int16_t y_max, int16_t z_min, int16_t z_max, float temperature_offset);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Reads the latest data available from the sensor and returns a structure containing :
|
||||||
|
* The magnetic field value for the X axis as a signed integer on 16 bits
|
||||||
|
* The magnetic field value for the Y axis as a signed integer on 16 bits
|
||||||
|
* The magnetic field value for the Z axis as a signed integer on 16 bits
|
||||||
|
* These values are raw data, this means that they are not calibrated ! Use the @ref QMC5883L_get_MFields_calibrated instead.
|
||||||
|
*
|
||||||
|
* @return QMC5883L_MData_t the structure containing the fields
|
||||||
|
*/
|
||||||
QMC5883L_MData_t QMC5883L_get_MFields_raw(void);
|
QMC5883L_MData_t QMC5883L_get_MFields_raw(void);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Reads the latest data available from the sensor, calibrates them and returns a structure containing :
|
||||||
|
* The calibrated magnetic field value for the X axis as a signed integer on 16 bits
|
||||||
|
* The calibrated magnetic field value for the Y axis as a signed integer on 16 bits
|
||||||
|
* The calibrated magnetic field value for the Z axis as a signed integer on 16 bits
|
||||||
|
*
|
||||||
|
* @return QMC5883L_MData_calibrated_t the structure containing the calibrated fields
|
||||||
|
*/
|
||||||
QMC5883L_MData_calibrated_t QMC5883L_get_MFields_calibrated(void);
|
QMC5883L_MData_calibrated_t QMC5883L_get_MFields_calibrated(void);
|
||||||
|
|
||||||
int16_t QMC5883L_get_azimuth(const QMC5883L_MData_calibrated_t data);
|
/**
|
||||||
|
* @brief Returns the azimuth (the angle to north) in degrees.
|
||||||
|
*
|
||||||
|
* @param data a previously retrieved calibrated data using the @ref QMC5883L_get_MFields_calibrated function
|
||||||
|
* @return uint16_t the angle in degrees between 0 and 359.
|
||||||
|
*/
|
||||||
|
uint16_t QMC5883L_get_azimuth(const QMC5883L_MData_calibrated_t data);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Configures the sensor by setting the Output Data Rate, the Range of Scale and the Over Sampling Rate.
|
||||||
|
*
|
||||||
|
* @param ODR the output data rate, can be ODR_10HZ, ODR_50HZ, ODR_100HZ or ODR_200HZ
|
||||||
|
* @param RNG the range or scale, can be FS_2G or FS_8G.
|
||||||
|
* @param OSR the over sampling rate, can be OSR_512, OSR_256, OSR_128 or OSR_64.
|
||||||
|
* @return true on success
|
||||||
|
* @return false on failure
|
||||||
|
*/
|
||||||
bool QMC5883L_configure_1(QMC5883L_Output_Data_Rate_e ODR, QMC5883L_Full_Scale_e RNG, QMC5883L_Over_Sample_Ratio_e OSR);
|
bool QMC5883L_configure_1(QMC5883L_Output_Data_Rate_e ODR, QMC5883L_Full_Scale_e RNG, QMC5883L_Over_Sample_Ratio_e OSR);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Configures the sensor by enabling the rolling pointer functionality (not useful) and the data ready interrupt pin.
|
||||||
|
*
|
||||||
|
* @param rolling_ptr true to enable or false to disable
|
||||||
|
* @param data_ready_int true to enable or false to disable
|
||||||
|
* @return true on success
|
||||||
|
* @return false on failure
|
||||||
|
*/
|
||||||
bool QMC5883L_configure_2(bool rolling_ptr, bool data_ready_int);
|
bool QMC5883L_configure_2(bool rolling_ptr, bool data_ready_int);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Toggles between the two availables power modes :
|
||||||
|
* Standby : puts the sensor in standby modes. In this mode, no measurements are performed and the power consumption is lowest.
|
||||||
|
* Continuous : puts the sensor in active mode by continuously performing measurement that can be retrieved using the @ref QMC5883L_get_MFields_raw
|
||||||
|
* or @ref QMC5883L_get_MFields_calibrated functions.
|
||||||
|
*
|
||||||
|
* @param MC
|
||||||
|
* @return true on success
|
||||||
|
* @return false on failure
|
||||||
|
*/
|
||||||
bool QMC5883L_set_power_mode(QMC5883L_Mode_Control_e MC);
|
bool QMC5883L_set_power_mode(QMC5883L_Mode_Control_e MC);
|
||||||
|
|
||||||
#endif //QMC5883L_H
|
#endif //QMC5883L_H
|
@ -6,12 +6,47 @@
|
|||||||
#include "wm_type_def.h"
|
#include "wm_type_def.h"
|
||||||
#include "wm_io.h"
|
#include "wm_io.h"
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Initializes the I2C peripheral by defining the SDA and SCL pin used as well as the clock frequency.
|
||||||
|
*
|
||||||
|
* @param SDAPin the Serial DAta pin to use (check the datasheet to find an I2C capable pin)
|
||||||
|
* @param SCLPin the Serial CLock pin to use (check the datasheet to find an I2C capable pin)
|
||||||
|
* @param frequency the clock frequency between 100000 and 400000 Hz
|
||||||
|
*/
|
||||||
void i2c_init(enum tls_io_name SDAPin, enum tls_io_name SCLPin, uint32_t frequency);
|
void i2c_init(enum tls_io_name SDAPin, enum tls_io_name SCLPin, uint32_t frequency);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Writes the given data to the provided register of the slave device.
|
||||||
|
*
|
||||||
|
* @param address the 7 bit address of the slave device
|
||||||
|
* @param reg the address of the register
|
||||||
|
* @param data the data to write
|
||||||
|
* @return true on success
|
||||||
|
* @return false on failure
|
||||||
|
*/
|
||||||
bool i2c_write_reg(uint8_t address, uint8_t reg, uint8_t data);
|
bool i2c_write_reg(uint8_t address, uint8_t reg, uint8_t data);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Reads multiple data in one I2C transaction from the slave device.
|
||||||
|
*
|
||||||
|
* @param address the 7 bit address of the slave device
|
||||||
|
* @param reg the address of the register from where the read will start (the device should have read with autoincrement register functionality)
|
||||||
|
* @param data a pointer to an array of uint8_t to store the read data
|
||||||
|
* @param length the size in bytes of the data array
|
||||||
|
* @return true on success
|
||||||
|
* @return false on failure
|
||||||
|
*/
|
||||||
bool i2c_read(uint8_t address, uint8_t reg, uint8_t * const data, size_t length);
|
bool i2c_read(uint8_t address, uint8_t reg, uint8_t * const data, size_t length);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Reads a single data from the provided register of the slave device.
|
||||||
|
*
|
||||||
|
* @param address the 7 bit address of the slave device
|
||||||
|
* @param reg the address of the register
|
||||||
|
* @param data a pointer to an uint8_t variable for storing the data to be read
|
||||||
|
* @return true on success
|
||||||
|
* @return false on failure
|
||||||
|
*/
|
||||||
bool i2c_read_reg(uint8_t address, uint8_t reg, uint8_t * const data);
|
bool i2c_read_reg(uint8_t address, uint8_t reg, uint8_t * const data);
|
||||||
|
|
||||||
|
|
||||||
|
@ -51,14 +51,6 @@ static void cleanup_event_cb(lv_event_t * e)
|
|||||||
LV_LOG_USER("cleanup");
|
LV_LOG_USER("cleanup");
|
||||||
}
|
}
|
||||||
|
|
||||||
//To delete
|
|
||||||
/*static void timer_anim_cb(lv_timer_t *timer)
|
|
||||||
{
|
|
||||||
CompassScreen_t *compassScreen = timer->user_data;
|
|
||||||
static uint16_t azimuth = 0;
|
|
||||||
compass_screen_set_azimuth(compassScreen, azimuth++);
|
|
||||||
}*/
|
|
||||||
|
|
||||||
static void create_cardinal(CompassCardinal_t *cardidanl, const char *cardinalText, lv_color_t textColor, lv_coord_t x, lv_coord_t y, lv_obj_t *parent)
|
static void create_cardinal(CompassCardinal_t *cardidanl, const char *cardinalText, lv_color_t textColor, lv_coord_t x, lv_coord_t y, lv_obj_t *parent)
|
||||||
{
|
{
|
||||||
cardidanl->label = lv_label_create(parent);
|
cardidanl->label = lv_label_create(parent);
|
||||||
@ -110,33 +102,36 @@ void compass_screen_set_azimuth(CompassScreen_t * const compassScreen, uint16_t
|
|||||||
|
|
||||||
//We make sure the azimuth is in the right range ie 0 to 359
|
//We make sure the azimuth is in the right range ie 0 to 359
|
||||||
azimuth %= 360;
|
azimuth %= 360;
|
||||||
|
uint16_t azimuthAdjusted = 359 - azimuth;
|
||||||
|
|
||||||
uint8_t index;
|
uint8_t index;
|
||||||
|
|
||||||
if(azimuth >= 23 && azimuth <= 67)
|
if(azimuthAdjusted >= 23 && azimuthAdjusted <= 67)
|
||||||
index = 1;//NE
|
index = 1;//NE
|
||||||
else if(azimuth >= 68 && azimuth <= 112)
|
else if(azimuthAdjusted >= 68 && azimuthAdjusted <= 112)
|
||||||
index = 2;//E
|
index = 2;//E
|
||||||
else if(azimuth >= 113 && azimuth <= 157)
|
else if(azimuthAdjusted >= 113 && azimuthAdjusted <= 157)
|
||||||
index = 3;//SE
|
index = 3;//SE
|
||||||
else if(azimuth >= 158 && azimuth <= 202)
|
else if(azimuthAdjusted >= 158 && azimuthAdjusted <= 202)
|
||||||
index = 4;//S
|
index = 4;//S
|
||||||
else if(azimuth >= 203 && azimuth <= 247)
|
else if(azimuthAdjusted >= 203 && azimuthAdjusted <= 247)
|
||||||
index = 5;//SW
|
index = 5;//SW
|
||||||
else if(azimuth >= 248 && azimuth <= 292)
|
else if(azimuthAdjusted >= 248 && azimuthAdjusted <= 292)
|
||||||
index = 6;//W
|
index = 6;//W
|
||||||
else if(azimuth >= 293 && azimuth <= 337)
|
else if(azimuthAdjusted >= 293 && azimuthAdjusted <= 337)
|
||||||
index = 7;//NW
|
index = 7;//NW
|
||||||
else
|
else
|
||||||
index = 0;//N
|
index = 0;//N
|
||||||
|
|
||||||
//Update the center label
|
//Update the center label
|
||||||
sprintf(compassScreen->compassAzimuth.text, "%u° %s", azimuth, cardinals[index]);
|
sprintf(compassScreen->compassAzimuth.text, "%u° %s", azimuthAdjusted, cardinals[index]);
|
||||||
lv_label_set_text_static(compassScreen->compassAzimuth.label, compassScreen->compassAzimuth.text);
|
lv_label_set_text_static(compassScreen->compassAzimuth.label, compassScreen->compassAzimuth.text);
|
||||||
|
|
||||||
//Rotate each cardinal with the current azimuth
|
//Rotate each cardinal with the current azimuth
|
||||||
rotate_cardinal(&compassScreen->northCardinal, azimuth);
|
rotate_cardinal(&compassScreen->northCardinal, azimuth);
|
||||||
lv_img_set_angle(compassScreen->northMarker, azimuth*10);
|
lv_img_set_angle(compassScreen->northMarker, azimuth*10);
|
||||||
|
//lv_meter_set_scale_range(compassScreen->compassGraduation.meter, compassScreen->compassGraduation.scale, 0, 330, 330, azimuth-90);
|
||||||
|
|
||||||
rotate_cardinal(&compassScreen->eastCardinal, azimuth);
|
rotate_cardinal(&compassScreen->eastCardinal, azimuth);
|
||||||
rotate_cardinal(&compassScreen->southCardinal, azimuth);
|
rotate_cardinal(&compassScreen->southCardinal, azimuth);
|
||||||
rotate_cardinal(&compassScreen->westCardinal, azimuth);
|
rotate_cardinal(&compassScreen->westCardinal, azimuth);
|
||||||
@ -165,22 +160,32 @@ void compass_screen_create(CompassScreen_t * const compassScreen)
|
|||||||
compassScreen->display = lv_obj_create(NULL);
|
compassScreen->display = lv_obj_create(NULL);
|
||||||
lv_obj_set_style_bg_color(compassScreen->display, lv_color_white(), LV_PART_MAIN);
|
lv_obj_set_style_bg_color(compassScreen->display, lv_color_white(), LV_PART_MAIN);
|
||||||
|
|
||||||
|
//Let's add some arcs
|
||||||
|
lv_obj_t *arc = lv_arc_create(compassScreen->display);
|
||||||
|
lv_arc_set_angles(arc, 0, 360);
|
||||||
|
lv_obj_set_style_arc_width(arc, 2, LV_PART_INDICATOR);
|
||||||
|
lv_obj_remove_style(arc, NULL, LV_PART_KNOB);
|
||||||
|
lv_obj_set_style_arc_width(arc, 0, LV_PART_MAIN);
|
||||||
|
lv_obj_clear_flag(arc, LV_OBJ_FLAG_CLICKABLE);
|
||||||
|
|
||||||
|
lv_obj_set_size(arc, 168, 168);
|
||||||
|
lv_obj_center(arc);
|
||||||
|
|
||||||
|
arc = lv_arc_create(compassScreen->display);
|
||||||
|
lv_arc_set_angles(arc, 0, 360);
|
||||||
|
lv_obj_set_style_arc_width(arc, 2, LV_PART_INDICATOR);
|
||||||
|
lv_obj_remove_style(arc, NULL, LV_PART_KNOB);
|
||||||
|
lv_obj_set_style_arc_width(arc, 0, LV_PART_MAIN);
|
||||||
|
lv_obj_clear_flag(arc, LV_OBJ_FLAG_CLICKABLE);
|
||||||
|
|
||||||
|
lv_obj_set_size(arc, 210, 210);
|
||||||
|
lv_obj_center(arc);
|
||||||
|
|
||||||
//Marker images are created here
|
//Marker images are created here
|
||||||
lv_obj_t *compassMarker = lv_img_create(compassScreen->display);
|
lv_obj_t *compassMarker = lv_img_create(compassScreen->display);
|
||||||
lv_img_set_src(compassMarker, &compass_marker);
|
lv_img_set_src(compassMarker, &compass_marker);
|
||||||
lv_obj_set_pos(compassMarker, 113, 0);
|
lv_obj_set_pos(compassMarker, 113, 0);
|
||||||
|
|
||||||
if(compassScreen->northMarker)
|
|
||||||
{
|
|
||||||
LV_LOG_ERROR("img should be NULL here !");
|
|
||||||
lv_obj_del(compassScreen->northMarker);
|
|
||||||
compassScreen->northMarker = NULL;
|
|
||||||
}
|
|
||||||
compassScreen->northMarker = lv_img_create(compassScreen->display);
|
|
||||||
lv_img_set_src(compassScreen->northMarker, &compass_marker_north);
|
|
||||||
lv_obj_set_pos(compassScreen->northMarker, 113, 20);
|
|
||||||
lv_img_set_pivot(compassScreen->northMarker, 7, 100);
|
|
||||||
|
|
||||||
//Azimuth label is created here
|
//Azimuth label is created here
|
||||||
if(compassScreen->compassAzimuth.label)
|
if(compassScreen->compassAzimuth.label)
|
||||||
{
|
{
|
||||||
@ -193,6 +198,35 @@ void compass_screen_create(CompassScreen_t * const compassScreen)
|
|||||||
lv_obj_set_style_text_font(compassScreen->compassAzimuth.label, &lv_font_montserrat_28, LV_PART_MAIN);
|
lv_obj_set_style_text_font(compassScreen->compassAzimuth.label, &lv_font_montserrat_28, LV_PART_MAIN);
|
||||||
lv_obj_center(compassScreen->compassAzimuth.label);
|
lv_obj_center(compassScreen->compassAzimuth.label);
|
||||||
|
|
||||||
|
//Add some graduation : ( was nice but is too CPU intensive :( )
|
||||||
|
/*if(compassScreen->compassGraduation.meter)
|
||||||
|
{
|
||||||
|
LV_LOG_ERROR("meter should be NULL here !");
|
||||||
|
lv_obj_del(compassScreen->compassGraduation.meter);
|
||||||
|
compassScreen->compassGraduation.meter = NULL;
|
||||||
|
}
|
||||||
|
compassScreen->compassGraduation.meter = lv_meter_create(compassScreen->display);
|
||||||
|
lv_obj_remove_style(compassScreen->compassGraduation.meter, NULL, LV_PART_INDICATOR);
|
||||||
|
lv_obj_remove_style(compassScreen->compassGraduation.meter, NULL, LV_PART_MAIN);
|
||||||
|
lv_obj_set_size(compassScreen->compassGraduation.meter, 204, 204);
|
||||||
|
lv_obj_center(compassScreen->compassGraduation.meter);
|
||||||
|
|
||||||
|
compassScreen->compassGraduation.scale = lv_meter_add_scale(compassScreen->compassGraduation.meter);
|
||||||
|
lv_meter_set_scale_ticks(compassScreen->compassGraduation.meter, compassScreen->compassGraduation.scale, 12, 1, 0, lv_color_black());
|
||||||
|
lv_meter_set_scale_major_ticks(compassScreen->compassGraduation.meter, compassScreen->compassGraduation.scale, 1, 1, 0, lv_color_black(), 11);
|
||||||
|
lv_meter_set_scale_range(compassScreen->compassGraduation.meter, compassScreen->compassGraduation.scale, 0, 330, 330, -90);*/
|
||||||
|
|
||||||
|
if(compassScreen->northMarker)
|
||||||
|
{
|
||||||
|
LV_LOG_ERROR("img should be NULL here !");
|
||||||
|
lv_obj_del(compassScreen->northMarker);
|
||||||
|
compassScreen->northMarker = NULL;
|
||||||
|
}
|
||||||
|
compassScreen->northMarker = lv_img_create(compassScreen->display);
|
||||||
|
lv_img_set_src(compassScreen->northMarker, &compass_marker_north);
|
||||||
|
lv_obj_set_pos(compassScreen->northMarker, 113, 18);
|
||||||
|
lv_img_set_pivot(compassScreen->northMarker, 7, 101);
|
||||||
|
|
||||||
//Cardinal labels are created here
|
//Cardinal labels are created here
|
||||||
if(compassScreen->northCardinal.label)
|
if(compassScreen->northCardinal.label)
|
||||||
{
|
{
|
||||||
@ -200,8 +234,7 @@ void compass_screen_create(CompassScreen_t * const compassScreen)
|
|||||||
lv_obj_del(compassScreen->northCardinal.label);
|
lv_obj_del(compassScreen->northCardinal.label);
|
||||||
compassScreen->northCardinal.label = NULL;
|
compassScreen->northCardinal.label = NULL;
|
||||||
}
|
}
|
||||||
create_cardinal(&compassScreen->northCardinal, cardinals[0], lv_palette_main(LV_PALETTE_RED), 120, 50, compassScreen->display);
|
create_cardinal(&compassScreen->northCardinal, cardinals[0], lv_palette_main(LV_PALETTE_RED), 120, 53, compassScreen->display);
|
||||||
|
|
||||||
|
|
||||||
if(compassScreen->eastCardinal.label)
|
if(compassScreen->eastCardinal.label)
|
||||||
{
|
{
|
||||||
@ -209,7 +242,7 @@ void compass_screen_create(CompassScreen_t * const compassScreen)
|
|||||||
lv_obj_del(compassScreen->eastCardinal.label);
|
lv_obj_del(compassScreen->eastCardinal.label);
|
||||||
compassScreen->eastCardinal.label = NULL;
|
compassScreen->eastCardinal.label = NULL;
|
||||||
}
|
}
|
||||||
create_cardinal(&compassScreen->eastCardinal, cardinals[2], lv_color_black(), 190, 120, compassScreen->display);
|
create_cardinal(&compassScreen->eastCardinal, cardinals[2], lv_color_black(), 187, 120, compassScreen->display);
|
||||||
|
|
||||||
if(compassScreen->southCardinal.label)
|
if(compassScreen->southCardinal.label)
|
||||||
{
|
{
|
||||||
@ -217,7 +250,7 @@ void compass_screen_create(CompassScreen_t * const compassScreen)
|
|||||||
lv_obj_del(compassScreen->southCardinal.label);
|
lv_obj_del(compassScreen->southCardinal.label);
|
||||||
compassScreen->southCardinal.label = NULL;
|
compassScreen->southCardinal.label = NULL;
|
||||||
}
|
}
|
||||||
create_cardinal(&compassScreen->southCardinal, cardinals[4], lv_color_black(), 120, 190, compassScreen->display);
|
create_cardinal(&compassScreen->southCardinal, cardinals[4], lv_color_black(), 120, 187, compassScreen->display);
|
||||||
|
|
||||||
if(compassScreen->westCardinal.label)
|
if(compassScreen->westCardinal.label)
|
||||||
{
|
{
|
||||||
@ -225,15 +258,12 @@ void compass_screen_create(CompassScreen_t * const compassScreen)
|
|||||||
lv_obj_del(compassScreen->westCardinal.label);
|
lv_obj_del(compassScreen->westCardinal.label);
|
||||||
compassScreen->westCardinal.label = NULL;
|
compassScreen->westCardinal.label = NULL;
|
||||||
}
|
}
|
||||||
create_cardinal(&compassScreen->westCardinal, cardinals[6], lv_color_black(), 50, 120, compassScreen->display);
|
create_cardinal(&compassScreen->westCardinal, cardinals[6], lv_color_black(), 53, 120, compassScreen->display);
|
||||||
|
|
||||||
//We register the event callback to handle gestures
|
//We register the event callback to handle gestures
|
||||||
lv_obj_add_event_cb(compassScreen->display, &(gesture_event_cb), LV_EVENT_GESTURE, compassScreen);
|
lv_obj_add_event_cb(compassScreen->display, &(gesture_event_cb), LV_EVENT_GESTURE, compassScreen);
|
||||||
//We register the event callback to handle the cleanup
|
//We register the event callback to handle the cleanup
|
||||||
lv_obj_add_event_cb(compassScreen->display, &(cleanup_event_cb), LV_EVENT_DELETE, compassScreen);
|
lv_obj_add_event_cb(compassScreen->display, &(cleanup_event_cb), LV_EVENT_DELETE, compassScreen);
|
||||||
|
|
||||||
//To delete
|
|
||||||
//lv_timer_create(&(timer_anim_cb), 2, compassScreen);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void compass_screen_destroy(CompassScreen_t * const compassScreen)
|
void compass_screen_destroy(CompassScreen_t * const compassScreen)
|
||||||
@ -244,11 +274,13 @@ void compass_screen_destroy(CompassScreen_t * const compassScreen)
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
compassScreen->display = NULL;
|
compassScreen->display = NULL;
|
||||||
compassScreen->compassAzimuth.label = NULL;
|
compassScreen->compassAzimuth.label = NULL;
|
||||||
compassScreen->northCardinal.label = NULL;
|
compassScreen->northCardinal.label = NULL;
|
||||||
compassScreen->eastCardinal.label = NULL;
|
compassScreen->eastCardinal.label = NULL;
|
||||||
compassScreen->southCardinal.label = NULL;
|
compassScreen->southCardinal.label = NULL;
|
||||||
compassScreen->westCardinal.label = NULL;
|
compassScreen->westCardinal.label = NULL;
|
||||||
compassScreen->northMarker = NULL;
|
compassScreen->northMarker = NULL;
|
||||||
|
//compassScreen->compassGraduation.meter = NULL;
|
||||||
|
//compassScreen->compassGraduation.scale = NULL;
|
||||||
}
|
}
|
||||||
|
@ -16,6 +16,12 @@ typedef struct CompassCardinal
|
|||||||
lv_point_t offset;
|
lv_point_t offset;
|
||||||
} CompassCardinal_t;
|
} CompassCardinal_t;
|
||||||
|
|
||||||
|
typedef struct CompassGraduation
|
||||||
|
{
|
||||||
|
lv_obj_t *meter;
|
||||||
|
lv_meter_scale_t *scale;
|
||||||
|
} CompassGraduation_t;
|
||||||
|
|
||||||
/* Compass screen context object */
|
/* Compass screen context object */
|
||||||
typedef struct CompassScreen
|
typedef struct CompassScreen
|
||||||
{
|
{
|
||||||
@ -24,6 +30,8 @@ typedef struct CompassScreen
|
|||||||
CompassCardinal_t southCardinal;
|
CompassCardinal_t southCardinal;
|
||||||
CompassCardinal_t westCardinal;
|
CompassCardinal_t westCardinal;
|
||||||
|
|
||||||
|
//CompassGraduation_t compassGraduation;
|
||||||
|
|
||||||
lv_obj_t *northMarker;
|
lv_obj_t *northMarker;
|
||||||
lv_obj_t *display;
|
lv_obj_t *display;
|
||||||
|
|
||||||
|
@ -61,6 +61,11 @@ WatchFace_t watchFace;
|
|||||||
MenuScreen_t menuScreen;
|
MenuScreen_t menuScreen;
|
||||||
CompassScreen_t compassScreen;
|
CompassScreen_t compassScreen;
|
||||||
|
|
||||||
|
static uint16_t angle_with_offset(uint16_t angle, uint16_t offset)
|
||||||
|
{
|
||||||
|
return (angle + offset) >= 360 ? angle + offset - 360 : angle + offset;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
void gfx_task(void *param)
|
void gfx_task(void *param)
|
||||||
{
|
{
|
||||||
@ -124,8 +129,9 @@ void gfx_task(void *param)
|
|||||||
|
|
||||||
uint8_t aliveCounter = 0;
|
uint8_t aliveCounter = 0;
|
||||||
|
|
||||||
QMC5883L_MData_calibrated_t temp;
|
//QMC5883L_MData_calibrated_t temp;
|
||||||
uint8_t average = 0;
|
//uint8_t average = 0;
|
||||||
|
//uint16_t angle;
|
||||||
|
|
||||||
if(!QMC5883L_init())
|
if(!QMC5883L_init())
|
||||||
APP_LOG_INFO("Failed to init QMC5883L");
|
APP_LOG_INFO("Failed to init QMC5883L");
|
||||||
@ -142,7 +148,7 @@ void gfx_task(void *param)
|
|||||||
else
|
else
|
||||||
APP_LOG_INFO("QMC5883L configured");
|
APP_LOG_INFO("QMC5883L configured");
|
||||||
|
|
||||||
QMC5883L_set_calibration_data(-900, 2500, -1400, 1400, 2300, 7500);
|
QMC5883L_set_calibration_data(-900, 2500, -1400, 1400, 2300, 7500, 0.0);
|
||||||
|
|
||||||
for(;;)
|
for(;;)
|
||||||
{
|
{
|
||||||
@ -156,7 +162,7 @@ void gfx_task(void *param)
|
|||||||
|
|
||||||
QMC5883L_MData_calibrated_t MData = QMC5883L_get_MFields_calibrated();
|
QMC5883L_MData_calibrated_t MData = QMC5883L_get_MFields_calibrated();
|
||||||
|
|
||||||
if(average++ == 0)
|
/*if(average++ == 0)
|
||||||
{
|
{
|
||||||
temp.MFieldX = MData.MFieldX;
|
temp.MFieldX = MData.MFieldX;
|
||||||
temp.MFieldY = MData.MFieldY;
|
temp.MFieldY = MData.MFieldY;
|
||||||
@ -165,19 +171,20 @@ void gfx_task(void *param)
|
|||||||
else
|
else
|
||||||
{
|
{
|
||||||
temp.MFieldX += MData.MFieldX;
|
temp.MFieldX += MData.MFieldX;
|
||||||
temp.MFieldX /= 2;
|
temp.MFieldX >>= 1;
|
||||||
temp.MFieldY += MData.MFieldY;
|
temp.MFieldY += MData.MFieldY;
|
||||||
temp.MFieldY /= 2;
|
temp.MFieldY >>= 1;
|
||||||
temp.MFieldZ += MData.MFieldZ;
|
temp.MFieldZ += MData.MFieldZ;
|
||||||
temp.MFieldZ /= 2;
|
temp.MFieldZ >>= 1;
|
||||||
}
|
}*/
|
||||||
|
|
||||||
if(average == 1)
|
/*if(average == 1)
|
||||||
{
|
{
|
||||||
average = 0;
|
average = 0;
|
||||||
int16_t angle = QMC5883L_get_azimuth(temp);
|
angle = angle_with_offset(QMC5883L_get_azimuth(MData), 180);
|
||||||
compass_screen_set_azimuth(&compassScreen, angle-180);
|
compass_screen_set_azimuth(&compassScreen, angle);
|
||||||
}
|
}*/
|
||||||
|
compass_screen_set_azimuth(&compassScreen, angle_with_offset(QMC5883L_get_azimuth(MData), 180));
|
||||||
}
|
}
|
||||||
|
|
||||||
if(++aliveCounter % 200 == 0)
|
if(++aliveCounter % 200 == 0)
|
||||||
@ -185,6 +192,5 @@ void gfx_task(void *param)
|
|||||||
APP_LOG_DEBUG("GFX thread");
|
APP_LOG_DEBUG("GFX thread");
|
||||||
aliveCounter = 0;
|
aliveCounter = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -17,14 +17,14 @@ static void menu_item_cb(lv_event_t *e)
|
|||||||
{
|
{
|
||||||
extern WatchFace_t watchFace;
|
extern WatchFace_t watchFace;
|
||||||
watch_face_create(&watchFace);
|
watch_face_create(&watchFace);
|
||||||
lv_scr_load_anim(watchFace.display, LV_SCR_LOAD_ANIM_FADE_ON, 400, 0, true);
|
lv_scr_load_anim(watchFace.display, LV_SCR_LOAD_ANIM_MOVE_LEFT, 400, 0, true);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case 1:
|
case 1:
|
||||||
{
|
{
|
||||||
extern CompassScreen_t compassScreen;
|
extern CompassScreen_t compassScreen;
|
||||||
compass_screen_create(&compassScreen);
|
compass_screen_create(&compassScreen);
|
||||||
lv_scr_load_anim(compassScreen.display, LV_SCR_LOAD_ANIM_FADE_ON, 400, 0, true);
|
lv_scr_load_anim(compassScreen.display, LV_SCR_LOAD_ANIM_MOVE_LEFT, 400, 0, true);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case 7:
|
case 7:
|
||||||
|
Loading…
Reference in New Issue
Block a user