annotate Discovery/Src/tInfoCompass.c @ 1046:1d7c7a36df15 GasConsumption

Bugfix OSTC5 BT and enabling fast mode: The OSTC5 BT was operating at default speed of 115200. To enable the faster communication some init steps have been added to set speed to 460800. Having the UART enabled while the module was shut down caused problems during initialisation. To avoid these the BT UART is now initialized after the the module is powered on and deinitialized while the module is switched off.
author Ideenmodellierer
date Fri, 14 Nov 2025 18:54:20 +0100
parents 65d35e66efb9
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
38
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1 ///////////////////////////////////////////////////////////////////////////////
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2 /// -*- coding: UTF-8 -*-
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
3 ///
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
4 /// \file Discovery/Src/tInfoCompass.c
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
5 /// \brief there is only compass_DX_f, compass_DY_f, compass_DZ_f output during this mode
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
6 /// \author heinrichs weikamp gmbh
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
7 /// \date 23-Feb-2015
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
8 ///
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
9 /// \details
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
10 ///
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
11 /// $Id$
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
12 ///////////////////////////////////////////////////////////////////////////////
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
13 /// \par Copyright (c) 2014-2018 Heinrichs Weikamp gmbh
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
14 ///
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
15 /// This program is free software: you can redistribute it and/or modify
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
16 /// it under the terms of the GNU General Public License as published by
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
17 /// the Free Software Foundation, either version 3 of the License, or
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
18 /// (at your option) any later version.
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
19 ///
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
20 /// This program is distributed in the hope that it will be useful,
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
21 /// but WITHOUT ANY WARRANTY; without even the implied warranty of
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
22 /// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
23 /// GNU General Public License for more details.
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
24 ///
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
25 /// You should have received a copy of the GNU General Public License
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
26 /// along with this program. If not, see <http://www.gnu.org/licenses/>.
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
27 //////////////////////////////////////////////////////////////////////////////
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
28
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
29 /* Includes ------------------------------------------------------------------*/
243
b7b481df4f22 debug: add SPI error counter to compass calibration
Jan Mulder <jlmulder@xs4all.nl>
parents: 38
diff changeset
30
1007
65d35e66efb9 Improve compass calibration dialog:
Ideenmodellierer
parents: 243
diff changeset
31
243
b7b481df4f22 debug: add SPI error counter to compass calibration
Jan Mulder <jlmulder@xs4all.nl>
parents: 38
diff changeset
32 #include "gfx_fonts.h"
b7b481df4f22 debug: add SPI error counter to compass calibration
Jan Mulder <jlmulder@xs4all.nl>
parents: 38
diff changeset
33 #include "tHome.h"
b7b481df4f22 debug: add SPI error counter to compass calibration
Jan Mulder <jlmulder@xs4all.nl>
parents: 38
diff changeset
34 #include "tInfo.h"
38
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
35 #include "tInfoCompass.h"
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
36
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
37 #include <string.h>
1007
65d35e66efb9 Improve compass calibration dialog:
Ideenmodellierer
parents: 243
diff changeset
38 #include <math.h>
65d35e66efb9 Improve compass calibration dialog:
Ideenmodellierer
parents: 243
diff changeset
39
65d35e66efb9 Improve compass calibration dialog:
Ideenmodellierer
parents: 243
diff changeset
40 #define PI 3.14159265358979323846
65d35e66efb9 Improve compass calibration dialog:
Ideenmodellierer
parents: 243
diff changeset
41
65d35e66efb9 Improve compass calibration dialog:
Ideenmodellierer
parents: 243
diff changeset
42 #define PITCH (0)
65d35e66efb9 Improve compass calibration dialog:
Ideenmodellierer
parents: 243
diff changeset
43 #define ROLL (1)
65d35e66efb9 Improve compass calibration dialog:
Ideenmodellierer
parents: 243
diff changeset
44 #define YAW (2)
38
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
45
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
46 /* Private variables ---------------------------------------------------------*/
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
47
1007
65d35e66efb9 Improve compass calibration dialog:
Ideenmodellierer
parents: 243
diff changeset
48 static uint16_t tInfoCompassTimeout = 0;
65d35e66efb9 Improve compass calibration dialog:
Ideenmodellierer
parents: 243
diff changeset
49 static int16_t minMaxCompassDX[3][2] = { 0 };
65d35e66efb9 Improve compass calibration dialog:
Ideenmodellierer
parents: 243
diff changeset
50
65d35e66efb9 Improve compass calibration dialog:
Ideenmodellierer
parents: 243
diff changeset
51 static axisIndicator_t axis[3];
65d35e66efb9 Improve compass calibration dialog:
Ideenmodellierer
parents: 243
diff changeset
52 static uint8_t activeAxis = PITCH;
65d35e66efb9 Improve compass calibration dialog:
Ideenmodellierer
parents: 243
diff changeset
53 static uint32_t checkTick = 0;
38
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
54
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
55 /* Exported functions --------------------------------------------------------*/
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
56 void openInfo_Compass(void)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
57 {
1007
65d35e66efb9 Improve compass calibration dialog:
Ideenmodellierer
parents: 243
diff changeset
58 uint16_t angle = 0;
65d35e66efb9 Improve compass calibration dialog:
Ideenmodellierer
parents: 243
diff changeset
59 uint8_t axisIndex = 0;
38
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
60 set_globalState(StICOMPASS);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
61 tInfoCompassTimeout = settingsGetPointer()->timeoutInfoCompass;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
62 tInfoCompassTimeout *= 10;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
63
1007
65d35e66efb9 Improve compass calibration dialog:
Ideenmodellierer
parents: 243
diff changeset
64 for(axisIndex = 0; axisIndex < 3; axisIndex++)
65d35e66efb9 Improve compass calibration dialog:
Ideenmodellierer
parents: 243
diff changeset
65 {
65d35e66efb9 Improve compass calibration dialog:
Ideenmodellierer
parents: 243
diff changeset
66 memset(axis[axisIndex].check,0, 360);
65d35e66efb9 Improve compass calibration dialog:
Ideenmodellierer
parents: 243
diff changeset
67 }
65d35e66efb9 Improve compass calibration dialog:
Ideenmodellierer
parents: 243
diff changeset
68 for(angle = 170; angle < 360; angle++)
65d35e66efb9 Improve compass calibration dialog:
Ideenmodellierer
parents: 243
diff changeset
69 {
65d35e66efb9 Improve compass calibration dialog:
Ideenmodellierer
parents: 243
diff changeset
70 axis[PITCH].check[angle] = 1; /* pitch only from -90 to +90 */
65d35e66efb9 Improve compass calibration dialog:
Ideenmodellierer
parents: 243
diff changeset
71 }
65d35e66efb9 Improve compass calibration dialog:
Ideenmodellierer
parents: 243
diff changeset
72 axis[YAW].coord.x = 100;
65d35e66efb9 Improve compass calibration dialog:
Ideenmodellierer
parents: 243
diff changeset
73 axis[YAW].coord.y = 70;
65d35e66efb9 Improve compass calibration dialog:
Ideenmodellierer
parents: 243
diff changeset
74 axis[PITCH].coord.x = 100;
65d35e66efb9 Improve compass calibration dialog:
Ideenmodellierer
parents: 243
diff changeset
75 axis[PITCH].coord.y = 300;
65d35e66efb9 Improve compass calibration dialog:
Ideenmodellierer
parents: 243
diff changeset
76 axis[ROLL].coord.x = 100;
65d35e66efb9 Improve compass calibration dialog:
Ideenmodellierer
parents: 243
diff changeset
77 axis[ROLL].coord.y = 200;
65d35e66efb9 Improve compass calibration dialog:
Ideenmodellierer
parents: 243
diff changeset
78
65d35e66efb9 Improve compass calibration dialog:
Ideenmodellierer
parents: 243
diff changeset
79 axis[YAW].eclipse.x = 50;
65d35e66efb9 Improve compass calibration dialog:
Ideenmodellierer
parents: 243
diff changeset
80 axis[YAW].eclipse.y = 50;
65d35e66efb9 Improve compass calibration dialog:
Ideenmodellierer
parents: 243
diff changeset
81 axis[PITCH].eclipse.x = 20;
65d35e66efb9 Improve compass calibration dialog:
Ideenmodellierer
parents: 243
diff changeset
82 axis[PITCH].eclipse.y = 50;
65d35e66efb9 Improve compass calibration dialog:
Ideenmodellierer
parents: 243
diff changeset
83 axis[ROLL].eclipse.x = 50;
65d35e66efb9 Improve compass calibration dialog:
Ideenmodellierer
parents: 243
diff changeset
84 axis[ROLL].eclipse.y = 20;
65d35e66efb9 Improve compass calibration dialog:
Ideenmodellierer
parents: 243
diff changeset
85
38
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
86 for(int i = 0; i<3;i ++)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
87 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
88 minMaxCompassDX[i][0] = 999;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
89 minMaxCompassDX[i][1] = -999;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
90 }
1007
65d35e66efb9 Improve compass calibration dialog:
Ideenmodellierer
parents: 243
diff changeset
91 checkTick = HAL_GetTick();
65d35e66efb9 Improve compass calibration dialog:
Ideenmodellierer
parents: 243
diff changeset
92
65d35e66efb9 Improve compass calibration dialog:
Ideenmodellierer
parents: 243
diff changeset
93 activeAxis = PITCH;
38
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
94 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
95
1007
65d35e66efb9 Improve compass calibration dialog:
Ideenmodellierer
parents: 243
diff changeset
96 void getElipsePoint(uint16_t elipseX , int16_t elipseY, int16_t degree, int16_t *x, int16_t *y)
65d35e66efb9 Improve compass calibration dialog:
Ideenmodellierer
parents: 243
diff changeset
97 {
65d35e66efb9 Improve compass calibration dialog:
Ideenmodellierer
parents: 243
diff changeset
98 double rad = degree * (PI / 180.0);
65d35e66efb9 Improve compass calibration dialog:
Ideenmodellierer
parents: 243
diff changeset
99 *x = (int16_t) (elipseX * cos(rad));
65d35e66efb9 Improve compass calibration dialog:
Ideenmodellierer
parents: 243
diff changeset
100 *y = (int16_t) (elipseY * sin(rad));
65d35e66efb9 Improve compass calibration dialog:
Ideenmodellierer
parents: 243
diff changeset
101 }
38
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
102 // ===============================================================================
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
103 // refreshInfo_Compass
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
104 /// @brief there is only compass_DX_f, compass_DY_f, compass_DZ_f output during this mode
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
105 /// the accel is not called during this process
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
106 // ===============================================================================
243
b7b481df4f22 debug: add SPI error counter to compass calibration
Jan Mulder <jlmulder@xs4all.nl>
parents: 38
diff changeset
107 void refreshInfo_Compass(GFX_DrawCfgScreen s)
38
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
108 {
1007
65d35e66efb9 Improve compass calibration dialog:
Ideenmodellierer
parents: 243
diff changeset
109 static int16_t cursorAngle = 0;
65d35e66efb9 Improve compass calibration dialog:
Ideenmodellierer
parents: 243
diff changeset
110
65d35e66efb9 Improve compass calibration dialog:
Ideenmodellierer
parents: 243
diff changeset
111 int16_t angle = 0.0;
65d35e66efb9 Improve compass calibration dialog:
Ideenmodellierer
parents: 243
diff changeset
112 int16_t drawX = 0;
65d35e66efb9 Improve compass calibration dialog:
Ideenmodellierer
parents: 243
diff changeset
113 int16_t drawY = 0;
65d35e66efb9 Improve compass calibration dialog:
Ideenmodellierer
parents: 243
diff changeset
114 uint8_t color = 0;
65d35e66efb9 Improve compass calibration dialog:
Ideenmodellierer
parents: 243
diff changeset
115 point_t start;
65d35e66efb9 Improve compass calibration dialog:
Ideenmodellierer
parents: 243
diff changeset
116 point_t stop;
65d35e66efb9 Improve compass calibration dialog:
Ideenmodellierer
parents: 243
diff changeset
117 point_t center;
65d35e66efb9 Improve compass calibration dialog:
Ideenmodellierer
parents: 243
diff changeset
118
65d35e66efb9 Improve compass calibration dialog:
Ideenmodellierer
parents: 243
diff changeset
119 int8_t offset = 0;
65d35e66efb9 Improve compass calibration dialog:
Ideenmodellierer
parents: 243
diff changeset
120 uint8_t axisIndex = 0;
65d35e66efb9 Improve compass calibration dialog:
Ideenmodellierer
parents: 243
diff changeset
121 int16_t index = 0;
65d35e66efb9 Improve compass calibration dialog:
Ideenmodellierer
parents: 243
diff changeset
122 uint8_t textIndex = 0;
243
b7b481df4f22 debug: add SPI error counter to compass calibration
Jan Mulder <jlmulder@xs4all.nl>
parents: 38
diff changeset
123
b7b481df4f22 debug: add SPI error counter to compass calibration
Jan Mulder <jlmulder@xs4all.nl>
parents: 38
diff changeset
124 tHome_show_lost_connection_count(&s);
38
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
125 tInfoCompassTimeout--;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
126 if(tInfoCompassTimeout == 0)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
127 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
128 exitInfo();
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
129 return;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
130 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
131
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
132 char text[80];
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
133
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
134 int16_t compassValues[3];
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
135
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
136 compassValues[0] = stateUsed->lifeData.compass_DX_f;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
137 compassValues[1] = stateUsed->lifeData.compass_DY_f;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
138 compassValues[2] = stateUsed->lifeData.compass_DZ_f;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
139
1007
65d35e66efb9 Improve compass calibration dialog:
Ideenmodellierer
parents: 243
diff changeset
140 /* draw indicator */
65d35e66efb9 Improve compass calibration dialog:
Ideenmodellierer
parents: 243
diff changeset
141 for(axisIndex = 0; axisIndex < 3; axisIndex++)
65d35e66efb9 Improve compass calibration dialog:
Ideenmodellierer
parents: 243
diff changeset
142 {
65d35e66efb9 Improve compass calibration dialog:
Ideenmodellierer
parents: 243
diff changeset
143 switch(axisIndex)
65d35e66efb9 Improve compass calibration dialog:
Ideenmodellierer
parents: 243
diff changeset
144 {
65d35e66efb9 Improve compass calibration dialog:
Ideenmodellierer
parents: 243
diff changeset
145 default:
65d35e66efb9 Improve compass calibration dialog:
Ideenmodellierer
parents: 243
diff changeset
146 case YAW: index = (uint16_t)(stateUsed->lifeData.compass_heading);
65d35e66efb9 Improve compass calibration dialog:
Ideenmodellierer
parents: 243
diff changeset
147 textIndex = snprintf(text,80,"yaw %.1f", stateUsed->lifeData.compass_heading);
65d35e66efb9 Improve compass calibration dialog:
Ideenmodellierer
parents: 243
diff changeset
148
65d35e66efb9 Improve compass calibration dialog:
Ideenmodellierer
parents: 243
diff changeset
149 if((tInfoCompassTimeout < 50) && (activeAxis == YAW))
65d35e66efb9 Improve compass calibration dialog:
Ideenmodellierer
parents: 243
diff changeset
150 {
65d35e66efb9 Improve compass calibration dialog:
Ideenmodellierer
parents: 243
diff changeset
151 snprintf(&text[textIndex],80,"\023\t(%i, %i)", minMaxCompassDX[YAW][0], minMaxCompassDX[YAW][1]);
65d35e66efb9 Improve compass calibration dialog:
Ideenmodellierer
parents: 243
diff changeset
152 }
65d35e66efb9 Improve compass calibration dialog:
Ideenmodellierer
parents: 243
diff changeset
153
65d35e66efb9 Improve compass calibration dialog:
Ideenmodellierer
parents: 243
diff changeset
154 start.x = axis[axisIndex].coord.x - 1;
65d35e66efb9 Improve compass calibration dialog:
Ideenmodellierer
parents: 243
diff changeset
155 start.y = axis[axisIndex].coord.y;
65d35e66efb9 Improve compass calibration dialog:
Ideenmodellierer
parents: 243
diff changeset
156 stop.x = axis[axisIndex].coord.x + 1;
65d35e66efb9 Improve compass calibration dialog:
Ideenmodellierer
parents: 243
diff changeset
157 stop.y = axis[axisIndex].coord.y;
65d35e66efb9 Improve compass calibration dialog:
Ideenmodellierer
parents: 243
diff changeset
158 break;
65d35e66efb9 Improve compass calibration dialog:
Ideenmodellierer
parents: 243
diff changeset
159 case PITCH: index = (uint16_t)(stateUsed->lifeData.compass_pitch + 90);
65d35e66efb9 Improve compass calibration dialog:
Ideenmodellierer
parents: 243
diff changeset
160 textIndex = snprintf(text,80,"pitch %.1f", stateUsed->lifeData.compass_pitch);
65d35e66efb9 Improve compass calibration dialog:
Ideenmodellierer
parents: 243
diff changeset
161 if((tInfoCompassTimeout < 50) && (activeAxis == YAW))
65d35e66efb9 Improve compass calibration dialog:
Ideenmodellierer
parents: 243
diff changeset
162 {
65d35e66efb9 Improve compass calibration dialog:
Ideenmodellierer
parents: 243
diff changeset
163 snprintf(&text[textIndex],80,"\023\t(%i, %i)", minMaxCompassDX[PITCH][0], minMaxCompassDX[PITCH][1]);
65d35e66efb9 Improve compass calibration dialog:
Ideenmodellierer
parents: 243
diff changeset
164 }
65d35e66efb9 Improve compass calibration dialog:
Ideenmodellierer
parents: 243
diff changeset
165 start.x = axis[axisIndex].coord.x - 30;
65d35e66efb9 Improve compass calibration dialog:
Ideenmodellierer
parents: 243
diff changeset
166 start.y = axis[axisIndex].coord.y;
65d35e66efb9 Improve compass calibration dialog:
Ideenmodellierer
parents: 243
diff changeset
167 stop.x = axis[axisIndex].coord.x + 30;
65d35e66efb9 Improve compass calibration dialog:
Ideenmodellierer
parents: 243
diff changeset
168 stop.y = axis[axisIndex].coord.y;
65d35e66efb9 Improve compass calibration dialog:
Ideenmodellierer
parents: 243
diff changeset
169
65d35e66efb9 Improve compass calibration dialog:
Ideenmodellierer
parents: 243
diff changeset
170 break;
65d35e66efb9 Improve compass calibration dialog:
Ideenmodellierer
parents: 243
diff changeset
171 case ROLL: index = (uint16_t)(stateUsed->lifeData.compass_roll + 180);
65d35e66efb9 Improve compass calibration dialog:
Ideenmodellierer
parents: 243
diff changeset
172 textIndex = snprintf(text,80,"roll %.1f", stateUsed->lifeData.compass_roll);
65d35e66efb9 Improve compass calibration dialog:
Ideenmodellierer
parents: 243
diff changeset
173 if((tInfoCompassTimeout < 50) && (activeAxis == YAW))
65d35e66efb9 Improve compass calibration dialog:
Ideenmodellierer
parents: 243
diff changeset
174 {
65d35e66efb9 Improve compass calibration dialog:
Ideenmodellierer
parents: 243
diff changeset
175 snprintf(&text[textIndex],80,"\023\t(%i, %i)", minMaxCompassDX[ROLL][0], minMaxCompassDX[ROLL][1]);
65d35e66efb9 Improve compass calibration dialog:
Ideenmodellierer
parents: 243
diff changeset
176 }
65d35e66efb9 Improve compass calibration dialog:
Ideenmodellierer
parents: 243
diff changeset
177 start.x = axis[axisIndex].coord.x;
65d35e66efb9 Improve compass calibration dialog:
Ideenmodellierer
parents: 243
diff changeset
178 start.y = axis[axisIndex].coord.y - 30;
65d35e66efb9 Improve compass calibration dialog:
Ideenmodellierer
parents: 243
diff changeset
179 stop.x = axis[axisIndex].coord.x;
65d35e66efb9 Improve compass calibration dialog:
Ideenmodellierer
parents: 243
diff changeset
180 stop.y = axis[axisIndex].coord.y +30;
65d35e66efb9 Improve compass calibration dialog:
Ideenmodellierer
parents: 243
diff changeset
181 break;
65d35e66efb9 Improve compass calibration dialog:
Ideenmodellierer
parents: 243
diff changeset
182 }
65d35e66efb9 Improve compass calibration dialog:
Ideenmodellierer
parents: 243
diff changeset
183 if(settingsGetPointer()->FlipDisplay)
65d35e66efb9 Improve compass calibration dialog:
Ideenmodellierer
parents: 243
diff changeset
184 {
65d35e66efb9 Improve compass calibration dialog:
Ideenmodellierer
parents: 243
diff changeset
185 start.x = 800 - start.x;
65d35e66efb9 Improve compass calibration dialog:
Ideenmodellierer
parents: 243
diff changeset
186 stop.x = 800 - stop.x;
65d35e66efb9 Improve compass calibration dialog:
Ideenmodellierer
parents: 243
diff changeset
187 start.y = 480 - start.y;
65d35e66efb9 Improve compass calibration dialog:
Ideenmodellierer
parents: 243
diff changeset
188 stop.y = 480 - stop.y;
65d35e66efb9 Improve compass calibration dialog:
Ideenmodellierer
parents: 243
diff changeset
189 }
65d35e66efb9 Improve compass calibration dialog:
Ideenmodellierer
parents: 243
diff changeset
190 if(activeAxis == axisIndex) /* only check one axis at a time. reason: yaw will be unstable at the beginning of calibration */
65d35e66efb9 Improve compass calibration dialog:
Ideenmodellierer
parents: 243
diff changeset
191 {
65d35e66efb9 Improve compass calibration dialog:
Ideenmodellierer
parents: 243
diff changeset
192 for(offset = -6; offset <= 6; offset++) /* it is hard to hit every single angle and the resolution is not needed */
65d35e66efb9 Improve compass calibration dialog:
Ideenmodellierer
parents: 243
diff changeset
193 {
65d35e66efb9 Improve compass calibration dialog:
Ideenmodellierer
parents: 243
diff changeset
194 if(( (index + offset) >= 0) && (index + offset < 360))
65d35e66efb9 Improve compass calibration dialog:
Ideenmodellierer
parents: 243
diff changeset
195 {
65d35e66efb9 Improve compass calibration dialog:
Ideenmodellierer
parents: 243
diff changeset
196 axis[axisIndex].check[index + offset] = 1; /* => check surrounding angles as well */
65d35e66efb9 Improve compass calibration dialog:
Ideenmodellierer
parents: 243
diff changeset
197 }
65d35e66efb9 Improve compass calibration dialog:
Ideenmodellierer
parents: 243
diff changeset
198 }
65d35e66efb9 Improve compass calibration dialog:
Ideenmodellierer
parents: 243
diff changeset
199 }
65d35e66efb9 Improve compass calibration dialog:
Ideenmodellierer
parents: 243
diff changeset
200 if(axisIndex == activeAxis)
65d35e66efb9 Improve compass calibration dialog:
Ideenmodellierer
parents: 243
diff changeset
201 {
65d35e66efb9 Improve compass calibration dialog:
Ideenmodellierer
parents: 243
diff changeset
202 color = CLUT_InfoCompass;
65d35e66efb9 Improve compass calibration dialog:
Ideenmodellierer
parents: 243
diff changeset
203 getElipsePoint(axis[axisIndex].eclipse.x,axis[axisIndex].eclipse.y,cursorAngle, &drawX, &drawY);
65d35e66efb9 Improve compass calibration dialog:
Ideenmodellierer
parents: 243
diff changeset
204 center.x = axis[axisIndex].coord.x + drawX;
65d35e66efb9 Improve compass calibration dialog:
Ideenmodellierer
parents: 243
diff changeset
205 center.y = axis[axisIndex].coord.y + drawY;
65d35e66efb9 Improve compass calibration dialog:
Ideenmodellierer
parents: 243
diff changeset
206
65d35e66efb9 Improve compass calibration dialog:
Ideenmodellierer
parents: 243
diff changeset
207 t_Info_draw_circle(center, 4, CLUT_Font020);
65d35e66efb9 Improve compass calibration dialog:
Ideenmodellierer
parents: 243
diff changeset
208 cursorAngle += 15;
65d35e66efb9 Improve compass calibration dialog:
Ideenmodellierer
parents: 243
diff changeset
209 if(cursorAngle >= 360)
65d35e66efb9 Improve compass calibration dialog:
Ideenmodellierer
parents: 243
diff changeset
210 {
65d35e66efb9 Improve compass calibration dialog:
Ideenmodellierer
parents: 243
diff changeset
211 cursorAngle = 0;
65d35e66efb9 Improve compass calibration dialog:
Ideenmodellierer
parents: 243
diff changeset
212 }
65d35e66efb9 Improve compass calibration dialog:
Ideenmodellierer
parents: 243
diff changeset
213 }
65d35e66efb9 Improve compass calibration dialog:
Ideenmodellierer
parents: 243
diff changeset
214 else
65d35e66efb9 Improve compass calibration dialog:
Ideenmodellierer
parents: 243
diff changeset
215 {
65d35e66efb9 Improve compass calibration dialog:
Ideenmodellierer
parents: 243
diff changeset
216 color = CLUT_Font021;
65d35e66efb9 Improve compass calibration dialog:
Ideenmodellierer
parents: 243
diff changeset
217 }
65d35e66efb9 Improve compass calibration dialog:
Ideenmodellierer
parents: 243
diff changeset
218 tInfo_write_content_simple( 200, 600, 480 - axis[axisIndex].coord.y - 35 , &FontT42, text, color);
65d35e66efb9 Improve compass calibration dialog:
Ideenmodellierer
parents: 243
diff changeset
219 tInfo_draw_colorline(start, stop, CLUT_Font020);
65d35e66efb9 Improve compass calibration dialog:
Ideenmodellierer
parents: 243
diff changeset
220 for(angle = 0; angle < 360; angle = angle + 3)
65d35e66efb9 Improve compass calibration dialog:
Ideenmodellierer
parents: 243
diff changeset
221 {
65d35e66efb9 Improve compass calibration dialog:
Ideenmodellierer
parents: 243
diff changeset
222 if(axis[axisIndex].check[angle])
65d35e66efb9 Improve compass calibration dialog:
Ideenmodellierer
parents: 243
diff changeset
223 {
65d35e66efb9 Improve compass calibration dialog:
Ideenmodellierer
parents: 243
diff changeset
224 color = CLUT_NiceGreen;
65d35e66efb9 Improve compass calibration dialog:
Ideenmodellierer
parents: 243
diff changeset
225 }
65d35e66efb9 Improve compass calibration dialog:
Ideenmodellierer
parents: 243
diff changeset
226 else
65d35e66efb9 Improve compass calibration dialog:
Ideenmodellierer
parents: 243
diff changeset
227 {
65d35e66efb9 Improve compass calibration dialog:
Ideenmodellierer
parents: 243
diff changeset
228 color = CLUT_WarningRed;
65d35e66efb9 Improve compass calibration dialog:
Ideenmodellierer
parents: 243
diff changeset
229 }
65d35e66efb9 Improve compass calibration dialog:
Ideenmodellierer
parents: 243
diff changeset
230 getElipsePoint(axis[axisIndex].eclipse.x,axis[axisIndex].eclipse.y,angle, &drawX, &drawY);
65d35e66efb9 Improve compass calibration dialog:
Ideenmodellierer
parents: 243
diff changeset
231 tInfo_drawPixel(axis[axisIndex].coord.x + drawX, axis[axisIndex].coord.y + drawY,color);
65d35e66efb9 Improve compass calibration dialog:
Ideenmodellierer
parents: 243
diff changeset
232 if((axisIndex == PITCH) && (angle == 180)) /* pitch only from -90 to +90 */
65d35e66efb9 Improve compass calibration dialog:
Ideenmodellierer
parents: 243
diff changeset
233 {
65d35e66efb9 Improve compass calibration dialog:
Ideenmodellierer
parents: 243
diff changeset
234 break;
65d35e66efb9 Improve compass calibration dialog:
Ideenmodellierer
parents: 243
diff changeset
235 }
65d35e66efb9 Improve compass calibration dialog:
Ideenmodellierer
parents: 243
diff changeset
236 }
65d35e66efb9 Improve compass calibration dialog:
Ideenmodellierer
parents: 243
diff changeset
237
65d35e66efb9 Improve compass calibration dialog:
Ideenmodellierer
parents: 243
diff changeset
238 }
65d35e66efb9 Improve compass calibration dialog:
Ideenmodellierer
parents: 243
diff changeset
239
38
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
240 for(int i = 0; i<3;i ++)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
241 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
242 // do not accept zero
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
243 if(minMaxCompassDX[i][0] == 0)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
244 minMaxCompassDX[i][0] = compassValues[i];
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
245
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
246 // do not accept zero
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
247 if(minMaxCompassDX[i][1] == 0)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
248 minMaxCompassDX[i][1] = compassValues[i];
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
249
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
250 if(compassValues[i] < minMaxCompassDX[i][0])
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
251 minMaxCompassDX[i][0] = compassValues[i];
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
252
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
253 if(compassValues[i] > minMaxCompassDX[i][1])
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
254 minMaxCompassDX[i][1] = compassValues[i];
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
255 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
256
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
257 snprintf(text,80,"Time left: %u s",(tInfoCompassTimeout+9)/10);
243
b7b481df4f22 debug: add SPI error counter to compass calibration
Jan Mulder <jlmulder@xs4all.nl>
parents: 38
diff changeset
258 tInfo_write_content_simple( 20,800, 25, &FontT42, text, CLUT_InfoCompass);
38
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
259
1007
65d35e66efb9 Improve compass calibration dialog:
Ideenmodellierer
parents: 243
diff changeset
260
65d35e66efb9 Improve compass calibration dialog:
Ideenmodellierer
parents: 243
diff changeset
261 if(time_elapsed_ms(checkTick, HAL_GetTick() > 1000))
38
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
262 {
1007
65d35e66efb9 Improve compass calibration dialog:
Ideenmodellierer
parents: 243
diff changeset
263 index = 0;
65d35e66efb9 Improve compass calibration dialog:
Ideenmodellierer
parents: 243
diff changeset
264 for(angle = 0; angle < 360; angle++)
65d35e66efb9 Improve compass calibration dialog:
Ideenmodellierer
parents: 243
diff changeset
265 {
65d35e66efb9 Improve compass calibration dialog:
Ideenmodellierer
parents: 243
diff changeset
266 if(axis[activeAxis].check[angle])
65d35e66efb9 Improve compass calibration dialog:
Ideenmodellierer
parents: 243
diff changeset
267 {
65d35e66efb9 Improve compass calibration dialog:
Ideenmodellierer
parents: 243
diff changeset
268 index++;
65d35e66efb9 Improve compass calibration dialog:
Ideenmodellierer
parents: 243
diff changeset
269 }
65d35e66efb9 Improve compass calibration dialog:
Ideenmodellierer
parents: 243
diff changeset
270 }
65d35e66efb9 Improve compass calibration dialog:
Ideenmodellierer
parents: 243
diff changeset
271 if(index > 350)
65d35e66efb9 Improve compass calibration dialog:
Ideenmodellierer
parents: 243
diff changeset
272 {
65d35e66efb9 Improve compass calibration dialog:
Ideenmodellierer
parents: 243
diff changeset
273 if(activeAxis < 2)
65d35e66efb9 Improve compass calibration dialog:
Ideenmodellierer
parents: 243
diff changeset
274 {
65d35e66efb9 Improve compass calibration dialog:
Ideenmodellierer
parents: 243
diff changeset
275 activeAxis++;
65d35e66efb9 Improve compass calibration dialog:
Ideenmodellierer
parents: 243
diff changeset
276 }
65d35e66efb9 Improve compass calibration dialog:
Ideenmodellierer
parents: 243
diff changeset
277 else
65d35e66efb9 Improve compass calibration dialog:
Ideenmodellierer
parents: 243
diff changeset
278 {
65d35e66efb9 Improve compass calibration dialog:
Ideenmodellierer
parents: 243
diff changeset
279 if(tInfoCompassTimeout > 50)
65d35e66efb9 Improve compass calibration dialog:
Ideenmodellierer
parents: 243
diff changeset
280 {
65d35e66efb9 Improve compass calibration dialog:
Ideenmodellierer
parents: 243
diff changeset
281 tInfoCompassTimeout = 50; /* reduce exit time to five seconds */
65d35e66efb9 Improve compass calibration dialog:
Ideenmodellierer
parents: 243
diff changeset
282 }
65d35e66efb9 Improve compass calibration dialog:
Ideenmodellierer
parents: 243
diff changeset
283 }
65d35e66efb9 Improve compass calibration dialog:
Ideenmodellierer
parents: 243
diff changeset
284 }
65d35e66efb9 Improve compass calibration dialog:
Ideenmodellierer
parents: 243
diff changeset
285
65d35e66efb9 Improve compass calibration dialog:
Ideenmodellierer
parents: 243
diff changeset
286
65d35e66efb9 Improve compass calibration dialog:
Ideenmodellierer
parents: 243
diff changeset
287 checkTick = HAL_GetTick();
38
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
288 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
289 }