Commit 7ffb3344 authored by Grzegorz Daniluk's avatar Grzegorz Daniluk

compass: wip

parent 3c417fb2
......@@ -130,32 +130,46 @@ static const uint8_t gps_receiving_data[] = {
0x01,
0x80,
0x04,
0x84,
0x01,
0x82,
0x05,
0x81,
0x03,
0x82,
0x0b,
0x80,
0x01,
0x00,
0x80,
0x02,
0x81,
0x06,
0x0b,
0x80,
0x00,
0x8d,
0x00};
const struct rle_bitmap battery_charging = { 15, 12, battery_charging_data };
static const uint8_t gps_searching_data[] = {
0x0c,
0x80,
0x01,
0x81,
0x0c,
0x80,
0x13,
0x82,
0x03,
0x81,
0x01,
0x80,
0x00,
0x05,
0x81,
0x04,
0x80,
0x01,
0x05,
0x81,
0x03,
0x81,
0x06,
0x82,
0x00,
0x83,
0x03,
0x80,
0x01,
0x06,
0x82,
0x02,
0x80,
......@@ -182,42 +196,7 @@ static const uint8_t gps_receiving_data[] = {
0x08,
0x86,
0x05};
const struct rle_bitmap gps_receiving = { 15, 15, gps_receiving_data };
static const uint8_t battery_data[] = {
0x8d,
0x00,
0x80,
0x0b,
0x80,
0x00,
0x80,
0x0b,
0x80,
0x00,
0x80,
0x0b,
0x82,
0x0b,
0x82,
0x0b,
0x82,
0x0b,
0x82,
0x0b,
0x82,
0x0b,
0x82,
0x0b,
0x80,
0x00,
0x80,
0x0b,
0x80,
0x00,
0x8d,
0x00};
const struct rle_bitmap battery = { 15, 12, battery_data };
const struct rle_bitmap gps_searching = { 15, 15, gps_searching_data };
static const uint8_t clock_icon_data[] = {
0x03,
......@@ -332,75 +311,141 @@ static const uint8_t example_icon_data[] = {
0x14};
const struct rle_bitmap example_icon = { 15, 15, example_icon_data };
static const uint8_t battery_charging_data[] = {
0x8d,
0x00,
static const uint8_t compass_arrow_data[] = {
0x08,
0x80,
0x0b,
0x11,
0x80,
0x00,
0x11,
0x80,
0x0b,
0x80,
0x00,
0x80,
0x05,
0x81,
0x03,
0x10,
0x82,
0x04,
0x84,
0x01,
0x0f,
0x82,
0x00,
0x86,
0x03,
0x0f,
0x82,
0x00,
0x86,
0x03,
0x0f,
0x82,
0x04,
0x84,
0x01,
0x0f,
0x82,
0x05,
0x81,
0x03,
0x0f,
0x82,
0x0e,
0x84,
0x0d,
0x84,
0x0d,
0x84,
0x0d,
0x84,
0x0d,
0x84,
0x0c,
0x86,
0x0b,
0x80,
0x00,
0x80,
0x86,
0x0b,
0x80,
0x86,
0x0b,
0x86,
0x0b,
0x86,
0x0b,
0x86,
0x0a,
0x88,
0x09,
0x88,
0x09,
0x88,
0x09,
0x88,
0x09,
0x88,
0x08,
0x8a,
0x07,
0x8a,
0x07,
0x8a,
0x07,
0x8a,
0x07,
0x8a,
0x06,
0x8c,
0x05,
0x8c,
0x05,
0x8c,
0x05,
0x8c,
0x05,
0x8c,
0x05,
0x8c,
0x04,
0x8e,
0x03,
0x8e,
0x03,
0x8e,
0x03,
0x8e,
0x03,
0x8e,
0x02,
0x90,
0x01,
0x90,
0x01,
0x90,
0x01,
0x90,
0x01,
0x90,
0x01,
0x90,
0x00,
0x8d,
0x00};
const struct rle_bitmap battery_charging = { 15, 12, battery_charging_data };
0xb8};
const struct rle_bitmap compass_arrow = { 19, 50, compass_arrow_data };
static const uint8_t gps_searching_data[] = {
0x0c,
static const uint8_t gps_receiving_data[] = {
0x06,
0x83,
0x0e,
0x80,
0x0c,
0x0a,
0x81,
0x01,
0x80,
0x13,
0x04,
0x82,
0x03,
0x80,
0x05,
0x01,
0x80,
0x02,
0x81,
0x04,
0x06,
0x80,
0x05,
0x00,
0x80,
0x01,
0x81,
0x03,
0x81,
0x06,
0x01,
0x80,
0x00,
0x80,
0x01,
0x82,
0x00,
0x83,
0x06,
0x03,
0x80,
0x01,
0x82,
0x02,
0x80,
......@@ -427,7 +472,7 @@ static const uint8_t gps_searching_data[] = {
0x08,
0x86,
0x05};
const struct rle_bitmap gps_searching = { 15, 15, gps_searching_data };
const struct rle_bitmap gps_receiving = { 15, 15, gps_receiving_data };
static const uint8_t settings_icon_data[] = {
0x02,
......
......@@ -19,5 +19,6 @@ extern const struct rle_bitmap example_icon;
extern const struct rle_bitmap battery_charging;
extern const struct rle_bitmap gps_searching;
extern const struct rle_bitmap settings_icon;
extern const struct rle_bitmap compass_arrow;
#endif /* BITMAPS_H */
......@@ -152,6 +152,7 @@ C_SRC += \
../common/drivers/max17047.c \
../common/drivers/rtc.c \
../common/drivers/vibra.c \
../common/drivers/LSM303C/lsm303c.c \
../common/gfx/font_helv11.c \
../common/gfx/font_helv17.c \
../common/gfx/font_helv17b.c \
......@@ -180,6 +181,7 @@ src/apps/widgets/status_bar.c \
src/apps/application.c \
src/apps/clock.c \
src/apps/example_app.c \
src/apps/compass.c \
src/apps/menu.c \
src/apps/menu_struct.c \
src/main.c \
......
......@@ -33,6 +33,7 @@
extern application menu;
extern application clock_app;
extern application example;
extern application compass;
#endif /* APP_LIST_H */
/*
* Copyright (C) 2014 Julian Lewis
* @author Grzegorz Daniluk <grzegorz.daniluk@cern.ch>
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, you may find one here:
* http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
* or you may search the http://www.gnu.org website for the version 2 license,
* or you may write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
*/
/**
* Compass application.
*/
#include "application.h"
#include "widgets/status_bar.h"
#include <drivers/LSM303C/lsm303c.h>
#include <bitmaps.h>
#include <sincos.h>
#define COMPASS_R 50
#define COMPASS_X0 64
#define COMPASS_Y0 64
static int x_lcd, y_lcd;
static void compass_redraw(struct ui_widget *w)
{
gfx_clear(&w->dc, 0);
//gfx_draw_bitmap(&w->dc, 64, 64, &compass_arrow);
gfx_line(&w->dc, COMPASS_X0, COMPASS_Y0, x_lcd, y_lcd, 1);
}
static void compass_event(struct ui_widget *w, const struct event *evt)
{
w->flags |= WF_DIRTY;
}
struct ui_widget compass_widget = {
compass_redraw,
compass_event,
{ 0, 0, 127, 127 },
0,
WF_ACTIVE | WF_VISIBLE
};
struct ui_widget compass_screen = {
NULL,
NULL,
{ 0, 0, 127, 127 },
0,
WF_ACTIVE | WF_VISIBLE
};
void compass_main(void *params)
{
(void)(params);
struct event evt;
lsm303_smpl acc, mag;
int pitch, roll, xh, yh, x_comp, y_comp;
unsigned int x2, y2, z2;
float xy_mean;
/*lsm303 init, we need both ACC & MAG for tilt/roll compensation*/
lsm303_init();
ui_clear();
ui_init_widget(&compass_screen);
ui_init_widget(&compass_widget);
ui_add_widget(&compass_widget);
ui_add_child(&compass_screen, &compass_widget);
ui_add_widget(&compass_screen);
/*TODO: comment this out ?*/
ui_init_widget(&status_bar);
ui_add_widget(&status_bar);
/*draw screen for the first time*/
ui_update(NULL);
/*main loop*/
while(1) {
if(xQueueReceive(appQueue, &evt, 0)) {
switch(evt.type) {
case BUTTON_PRESSED:
if(evt.data.button == BUT_TR)
return;
}
}
else {
lsm303_get_sample(DEV_ACC, &acc);
lsm303_get_sample(DEV_MAG, &mag);
/* calculate pitch and roll from accelerometer */
x2 = acc.x * acc.x;
y2 = acc.y * acc.y;
z2 = acc.z * acc.z;
pitch = -small_atan(acc.x, small_sqrt(acc.y*acc.y + acc.z*acc.z));
roll = small_atan(acc.y, small_sqrt(acc.x*acc.x + acc.z*acc.z));
/* work with compass readout, first revert it because magnetic south is north */
mag.x *= -1;
mag.y *= -1;
mag.z *= -1;
/*now calculate heading based on MAG readout and pinch/roll*/
xh = mag.x*small_cos(pitch) + mag.z*small_sin(pitch);
yh = mag.x*small_sin(roll)*small_sin(pitch) + mag.y*small_cos(roll) -
mag.z*small_sin(roll)*small_cos(pitch);
/* calculate x,y for compass in cartesian */
xy_mean = small_sqrt(xh*xh + yh*yh);
x_comp = COMPASS_R*yh / xy_mean;
y_comp = COMPASS_R*xh / xy_mean;
/* transform to LCD coordinates */
x_lcd = x_comp + COMPASS_X0;
y_lcd = -y_comp + COMPASS_Y0;
ui_update(&evt);
}
}
}
application compass = {
.name = "Compass",
.main = compass_main
};
......@@ -50,6 +50,7 @@ menu_list main_menu = {
"Main menu",
{
{ APP, &example_icon, { .app = &example } },
{ APP, NULL, { .app = &compass } },
{ SUBMENU, &settings_icon, { .submenu = &settings_menu } },
{ END, NULL, { NULL } }
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment