Mercurial > public > ostc4
diff Discovery/Src/tInfoCompass.c @ 1007:65d35e66efb9 GasConsumption
Improve compass calibration dialog:
The previous calibration dialog showed some "magic" numbers and a 60 second count down. The new version is trying to guide the user through the calibration process: first rotate pitch, then roll and at last yaw angle. A step to the next angle is taken when enough data per angle is collected (change from red to green). To enable the yaw visualization a simple calibration is done while rotating the axis.
The function behind the calibration was not modified => the suggested process can be ignored and the same handling as the with old dialog may be applied. With the new process the dialog may be left early. Anyhow it will still be left after 60 seconds and the fine calibration is performed in the same way as before.
| author | Ideenmodellierer |
|---|---|
| date | Mon, 05 May 2025 21:02:34 +0200 |
| parents | b7b481df4f22 |
| children |
line wrap: on
line diff
--- a/Discovery/Src/tInfoCompass.c Sat May 03 17:52:05 2025 +0200 +++ b/Discovery/Src/tInfoCompass.c Mon May 05 21:02:34 2025 +0200 @@ -28,34 +28,77 @@ /* Includes ------------------------------------------------------------------*/ -#include "gfx_engine.h" + #include "gfx_fonts.h" #include "tHome.h" #include "tInfo.h" #include "tInfoCompass.h" #include <string.h> +#include <math.h> + +#define PI 3.14159265358979323846 + +#define PITCH (0) +#define ROLL (1) +#define YAW (2) /* Private variables ---------------------------------------------------------*/ -uint16_t tInfoCompassTimeout = 0; -int16_t minMaxCompassDX[3][2] = { 0 }; +static uint16_t tInfoCompassTimeout = 0; +static int16_t minMaxCompassDX[3][2] = { 0 }; + +static axisIndicator_t axis[3]; +static uint8_t activeAxis = PITCH; +static uint32_t checkTick = 0; /* Exported functions --------------------------------------------------------*/ void openInfo_Compass(void) { + uint16_t angle = 0; + uint8_t axisIndex = 0; set_globalState(StICOMPASS); tInfoCompassTimeout = settingsGetPointer()->timeoutInfoCompass; tInfoCompassTimeout *= 10; + for(axisIndex = 0; axisIndex < 3; axisIndex++) + { + memset(axis[axisIndex].check,0, 360); + } + for(angle = 170; angle < 360; angle++) + { + axis[PITCH].check[angle] = 1; /* pitch only from -90 to +90 */ + } + axis[YAW].coord.x = 100; + axis[YAW].coord.y = 70; + axis[PITCH].coord.x = 100; + axis[PITCH].coord.y = 300; + axis[ROLL].coord.x = 100; + axis[ROLL].coord.y = 200; + + axis[YAW].eclipse.x = 50; + axis[YAW].eclipse.y = 50; + axis[PITCH].eclipse.x = 20; + axis[PITCH].eclipse.y = 50; + axis[ROLL].eclipse.x = 50; + axis[ROLL].eclipse.y = 20; + for(int i = 0; i<3;i ++) { minMaxCompassDX[i][0] = 999; minMaxCompassDX[i][1] = -999; } + checkTick = HAL_GetTick(); + + activeAxis = PITCH; } - +void getElipsePoint(uint16_t elipseX , int16_t elipseY, int16_t degree, int16_t *x, int16_t *y) +{ + double rad = degree * (PI / 180.0); + *x = (int16_t) (elipseX * cos(rad)); + *y = (int16_t) (elipseY * sin(rad)); +} // =============================================================================== // refreshInfo_Compass /// @brief there is only compass_DX_f, compass_DY_f, compass_DZ_f output during this mode @@ -63,6 +106,20 @@ // =============================================================================== void refreshInfo_Compass(GFX_DrawCfgScreen s) { + static int16_t cursorAngle = 0; + + int16_t angle = 0.0; + int16_t drawX = 0; + int16_t drawY = 0; + uint8_t color = 0; + point_t start; + point_t stop; + point_t center; + + int8_t offset = 0; + uint8_t axisIndex = 0; + int16_t index = 0; + uint8_t textIndex = 0; tHome_show_lost_connection_count(&s); tInfoCompassTimeout--; @@ -80,6 +137,106 @@ compassValues[1] = stateUsed->lifeData.compass_DY_f; compassValues[2] = stateUsed->lifeData.compass_DZ_f; + /* draw indicator */ + for(axisIndex = 0; axisIndex < 3; axisIndex++) + { + switch(axisIndex) + { + default: + case YAW: index = (uint16_t)(stateUsed->lifeData.compass_heading); + textIndex = snprintf(text,80,"yaw %.1f", stateUsed->lifeData.compass_heading); + + if((tInfoCompassTimeout < 50) && (activeAxis == YAW)) + { + snprintf(&text[textIndex],80,"\023\t(%i, %i)", minMaxCompassDX[YAW][0], minMaxCompassDX[YAW][1]); + } + + start.x = axis[axisIndex].coord.x - 1; + start.y = axis[axisIndex].coord.y; + stop.x = axis[axisIndex].coord.x + 1; + stop.y = axis[axisIndex].coord.y; + break; + case PITCH: index = (uint16_t)(stateUsed->lifeData.compass_pitch + 90); + textIndex = snprintf(text,80,"pitch %.1f", stateUsed->lifeData.compass_pitch); + if((tInfoCompassTimeout < 50) && (activeAxis == YAW)) + { + snprintf(&text[textIndex],80,"\023\t(%i, %i)", minMaxCompassDX[PITCH][0], minMaxCompassDX[PITCH][1]); + } + start.x = axis[axisIndex].coord.x - 30; + start.y = axis[axisIndex].coord.y; + stop.x = axis[axisIndex].coord.x + 30; + stop.y = axis[axisIndex].coord.y; + + break; + case ROLL: index = (uint16_t)(stateUsed->lifeData.compass_roll + 180); + textIndex = snprintf(text,80,"roll %.1f", stateUsed->lifeData.compass_roll); + if((tInfoCompassTimeout < 50) && (activeAxis == YAW)) + { + snprintf(&text[textIndex],80,"\023\t(%i, %i)", minMaxCompassDX[ROLL][0], minMaxCompassDX[ROLL][1]); + } + start.x = axis[axisIndex].coord.x; + start.y = axis[axisIndex].coord.y - 30; + stop.x = axis[axisIndex].coord.x; + stop.y = axis[axisIndex].coord.y +30; + break; + } + if(settingsGetPointer()->FlipDisplay) + { + start.x = 800 - start.x; + stop.x = 800 - stop.x; + start.y = 480 - start.y; + stop.y = 480 - stop.y; + } + if(activeAxis == axisIndex) /* only check one axis at a time. reason: yaw will be unstable at the beginning of calibration */ + { + for(offset = -6; offset <= 6; offset++) /* it is hard to hit every single angle and the resolution is not needed */ + { + if(( (index + offset) >= 0) && (index + offset < 360)) + { + axis[axisIndex].check[index + offset] = 1; /* => check surrounding angles as well */ + } + } + } + if(axisIndex == activeAxis) + { + color = CLUT_InfoCompass; + getElipsePoint(axis[axisIndex].eclipse.x,axis[axisIndex].eclipse.y,cursorAngle, &drawX, &drawY); + center.x = axis[axisIndex].coord.x + drawX; + center.y = axis[axisIndex].coord.y + drawY; + + t_Info_draw_circle(center, 4, CLUT_Font020); + cursorAngle += 15; + if(cursorAngle >= 360) + { + cursorAngle = 0; + } + } + else + { + color = CLUT_Font021; + } + tInfo_write_content_simple( 200, 600, 480 - axis[axisIndex].coord.y - 35 , &FontT42, text, color); + tInfo_draw_colorline(start, stop, CLUT_Font020); + for(angle = 0; angle < 360; angle = angle + 3) + { + if(axis[axisIndex].check[angle]) + { + color = CLUT_NiceGreen; + } + else + { + color = CLUT_WarningRed; + } + getElipsePoint(axis[axisIndex].eclipse.x,axis[axisIndex].eclipse.y,angle, &drawX, &drawY); + tInfo_drawPixel(axis[axisIndex].coord.x + drawX, axis[axisIndex].coord.y + drawY,color); + if((axisIndex == PITCH) && (angle == 180)) /* pitch only from -90 to +90 */ + { + break; + } + } + + } + for(int i = 0; i<3;i ++) { // do not accept zero @@ -100,18 +257,33 @@ snprintf(text,80,"Time left: %u s",(tInfoCompassTimeout+9)/10); tInfo_write_content_simple( 20,800, 25, &FontT42, text, CLUT_InfoCompass); - for(int i = 0; i<3;i ++) + + if(time_elapsed_ms(checkTick, HAL_GetTick() > 1000)) { - snprintf(text,80,"%c: %i" "\t(%i, %i)", - 'X'+i, - compassValues[i], - minMaxCompassDX[i][0], - minMaxCompassDX[i][1]); - tInfo_write_content_simple( 20,800, 96 + (i*96), &FontT48, text, CLUT_InfoCompass); + index = 0; + for(angle = 0; angle < 360; angle++) + { + if(axis[activeAxis].check[angle]) + { + index++; + } + } + if(index > 350) + { + if(activeAxis < 2) + { + activeAxis++; + } + else + { + if(tInfoCompassTimeout > 50) + { + tInfoCompassTimeout = 50; /* reduce exit time to five seconds */ + } + } + } + + + checkTick = HAL_GetTick(); } - - snprintf(text,80,"roll %.1f" "\tpitch %.1f", - stateUsed->lifeData.compass_roll, - stateUsed->lifeData.compass_pitch); - tInfo_write_content_simple( 20,800, 96 * 4, &FontT42, text, CLUT_InfoCompass); }
