mirror of
https://github.com/betaflight/betaflight.git
synced 2025-07-20 06:45:16 +03:00
Touch-ups, tidy, bandwidth mgmt on serial canvas
This commit is contained in:
parent
c3c13cf454
commit
38660aa8a6
10 changed files with 524 additions and 507 deletions
|
@ -67,9 +67,7 @@
|
|||
#include "io/flashfs.h"
|
||||
#include "io/transponder_ir.h"
|
||||
#include "io/asyncfatfs/asyncfatfs.h"
|
||||
//#include "io/osd.h"
|
||||
#include "io/serial_4way.h"
|
||||
//#include "io/vtx.h"
|
||||
|
||||
#include "msp/msp.h"
|
||||
#include "msp/msp_protocol.h"
|
||||
|
|
|
@ -17,45 +17,48 @@
|
|||
#include "msp/msp_protocol.h"
|
||||
#include "msp/msp_serial.h"
|
||||
|
||||
void canvasOutput(uint8_t cmd, uint8_t *buf, int len)
|
||||
{
|
||||
mspSerialPush(cmd, buf, len);
|
||||
delayMicroseconds(len * 150); // XXX Kludge!!!
|
||||
}
|
||||
|
||||
void canvasGetSize(uint8_t *pRows, uint8_t *pCols)
|
||||
void canvasGetDevParam(uint8_t *pRows, uint8_t *pCols, uint16_t *pBuftime, uint16_t *pBufsize)
|
||||
{
|
||||
*pRows = 13;
|
||||
*pCols = 30;
|
||||
*pBuftime = 23; // = 256/(115200/10)
|
||||
*pBufsize = 192; // 256 * 3/4 (Be conservative)
|
||||
}
|
||||
|
||||
void canvasBegin(void)
|
||||
int canvasOutput(uint8_t cmd, uint8_t *buf, int len)
|
||||
{
|
||||
mspSerialPush(cmd, buf, len);
|
||||
|
||||
return 6 + len;
|
||||
}
|
||||
|
||||
int canvasBegin(void)
|
||||
{
|
||||
uint8_t subcmd[] = { 0 };
|
||||
|
||||
canvasOutput(MSP_CANVAS, subcmd, sizeof(subcmd));
|
||||
return canvasOutput(MSP_CANVAS, subcmd, sizeof(subcmd));
|
||||
}
|
||||
|
||||
void canvasHeartBeat(void)
|
||||
int canvasHeartBeat(void)
|
||||
{
|
||||
canvasBegin();
|
||||
return canvasBegin();
|
||||
}
|
||||
|
||||
void canvasEnd(void)
|
||||
int canvasEnd(void)
|
||||
{
|
||||
uint8_t subcmd[] = { 1 };
|
||||
|
||||
canvasOutput(MSP_CANVAS, subcmd, sizeof(subcmd));
|
||||
return canvasOutput(MSP_CANVAS, subcmd, sizeof(subcmd));
|
||||
}
|
||||
|
||||
void canvasClear(void)
|
||||
int canvasClear(void)
|
||||
{
|
||||
uint8_t subcmd[] = { 2 };
|
||||
|
||||
canvasOutput(MSP_CANVAS, subcmd, sizeof(subcmd));
|
||||
return canvasOutput(MSP_CANVAS, subcmd, sizeof(subcmd));
|
||||
}
|
||||
|
||||
void canvasWrite(uint8_t col, uint8_t row, char *string)
|
||||
int canvasWrite(uint8_t col, uint8_t row, char *string)
|
||||
{
|
||||
int len;
|
||||
char buf[30 + 4];
|
||||
|
@ -69,11 +72,11 @@ void canvasWrite(uint8_t col, uint8_t row, char *string)
|
|||
buf[3] = 0;
|
||||
memcpy((char *)&buf[4], string, len);
|
||||
|
||||
canvasOutput(MSP_CANVAS, (uint8_t *)buf, len + 4);
|
||||
return canvasOutput(MSP_CANVAS, (uint8_t *)buf, len + 4);
|
||||
}
|
||||
|
||||
screenFnVTable_t canvasVTable = {
|
||||
canvasGetSize,
|
||||
canvasGetDevParam,
|
||||
canvasBegin,
|
||||
canvasEnd,
|
||||
canvasClear,
|
||||
|
|
File diff suppressed because it is too large
Load diff
|
@ -11,3 +11,7 @@ void cmsScreenResync(void);
|
|||
|
||||
void cmsChangeScreen(void * ptr);
|
||||
void cmsExitMenu(void * ptr);
|
||||
|
||||
#define STARTUP_HELP_TEXT1 "MENU: THR MID"
|
||||
#define STARTUP_HELP_TEXT2 "+ YAW LEFT"
|
||||
#define STARTUP_HELP_TEXT3 "+ PITCH UP"
|
||||
|
|
|
@ -23,7 +23,6 @@ typedef enum
|
|||
OME_FLOAT, //only up to 255 value and cant be 2.55 or 25.5, just for PID's
|
||||
//wlasciwosci elementow
|
||||
OME_VISIBLE,
|
||||
OME_POS,
|
||||
OME_TAB,
|
||||
OME_END,
|
||||
} OSD_MenuElement;
|
||||
|
@ -34,9 +33,21 @@ typedef struct
|
|||
OSD_MenuElement type;
|
||||
OSDMenuFuncPtr func;
|
||||
void *data;
|
||||
bool changed;
|
||||
uint8_t flags;
|
||||
} OSD_Entry;
|
||||
|
||||
// Bits in flags
|
||||
#define PRINT_VALUE 0x01 // Value has been changed, need to redraw
|
||||
#define PRINT_LABEL 0x02 // Text label should be printed
|
||||
|
||||
#define IS_PRINTVALUE(p) ((p)->flags & PRINT_VALUE)
|
||||
#define SET_PRINTVALUE(p) { (p)->flags |= PRINT_VALUE; }
|
||||
#define CLR_PRINTVALUE(p) { (p)->flags &= ~PRINT_VALUE; }
|
||||
|
||||
#define IS_PRINTLABEL(p) ((p)->flags & PRINT_LABEL)
|
||||
#define SET_PRINTLABEL(p) { (p)->flags |= PRINT_LABEL; }
|
||||
#define CLR_PRINTLABEL(p) { (p)->flags &= ~PRINT_LABEL; }
|
||||
|
||||
typedef struct
|
||||
{
|
||||
uint8_t *val;
|
||||
|
@ -86,11 +97,11 @@ typedef struct
|
|||
} OSD_TAB_t;
|
||||
|
||||
typedef struct screenFnVTable_s {
|
||||
void (*getsize)(uint8_t *, uint8_t *);
|
||||
void (*begin)(void);
|
||||
void (*end)(void);
|
||||
void (*clear)(void);
|
||||
void (*write)(uint8_t, uint8_t, char *);
|
||||
void (*heartbeat)(void);
|
||||
void (*getDevParam)(uint8_t *, uint8_t *, uint16_t *, uint16_t *);
|
||||
int (*begin)(void);
|
||||
int (*end)(void);
|
||||
int (*clear)(void);
|
||||
int (*write)(uint8_t, uint8_t, char *);
|
||||
int (*heartbeat)(void);
|
||||
void (*resync)(void);
|
||||
} screenFnVTable_t;
|
||||
|
|
|
@ -62,8 +62,6 @@
|
|||
#include "io/gimbal.h"
|
||||
#include "io/serial.h"
|
||||
#include "io/gps.h"
|
||||
//#include "io/osd.h"
|
||||
//#include "io/vtx.h"
|
||||
|
||||
#include "flight/failsafe.h"
|
||||
#include "flight/mixer.h"
|
||||
|
|
|
@ -53,9 +53,6 @@
|
|||
#include "config/config_master.h"
|
||||
#include "config/feature.h"
|
||||
|
||||
// Short hands
|
||||
#define OSD_cfg masterConfig.osdProfile
|
||||
|
||||
#ifdef USE_HARDWARE_REVISION_DETECTION
|
||||
#include "hardware_revision.h"
|
||||
#endif
|
||||
|
@ -80,17 +77,8 @@ extern serialPort_t *debugSerialPort;
|
|||
#define IS_LO(X) (rcData[X] < 1250)
|
||||
#define IS_MID(X) (rcData[X] > 1250 && rcData[X] < 1750)
|
||||
|
||||
//#define VISIBLE_FLAG 0x0800 // defined in osd.h
|
||||
#define BLINK_FLAG 0x0400
|
||||
bool blinkState = true;
|
||||
|
||||
#define OSD_POS(x,y) (x | (y << 5))
|
||||
#define OSD_X(x) (x & 0x001F)
|
||||
#define OSD_Y(x) ((x >> 5) & 0x001F)
|
||||
//#define VISIBLE(x) (x & VISIBLE_FLAG) // defined in osd.h
|
||||
#define BLINK(x) ((x & BLINK_FLAG) && blinkState)
|
||||
#define BLINK_OFF(x) (x & ~BLINK_FLAG)
|
||||
|
||||
//extern uint8_t RSSI; // TODO: not used?
|
||||
|
||||
static uint16_t flyTime = 0;
|
||||
|
@ -158,11 +146,11 @@ void osdDrawElements(void)
|
|||
|
||||
void osdDrawSingleElement(uint8_t item)
|
||||
{
|
||||
if (!VISIBLE(OSD_cfg.item_pos[item]) || BLINK(OSD_cfg.item_pos[item]))
|
||||
if (!VISIBLE(masterConfig.osdProfile.item_pos[item]) || BLINK(masterConfig.osdProfile.item_pos[item]))
|
||||
return;
|
||||
|
||||
uint8_t elemPosX = OSD_X(OSD_cfg.item_pos[item]);
|
||||
uint8_t elemPosY = OSD_Y(OSD_cfg.item_pos[item]);
|
||||
uint8_t elemPosX = OSD_X(masterConfig.osdProfile.item_pos[item]);
|
||||
uint8_t elemPosY = OSD_Y(masterConfig.osdProfile.item_pos[item]);
|
||||
char buff[32];
|
||||
|
||||
switch(item) {
|
||||
|
@ -396,7 +384,7 @@ void osdInit(void)
|
|||
|
||||
armState = ARMING_FLAG(ARMED);
|
||||
|
||||
max7456Init(OSD_cfg.video_system);
|
||||
max7456Init(masterConfig.osdProfile.video_system);
|
||||
|
||||
max7456ClearScreen();
|
||||
|
||||
|
@ -413,9 +401,9 @@ void osdInit(void)
|
|||
|
||||
sprintf(string_buffer, "BF VERSION: %s", FC_VERSION_STRING);
|
||||
max7456Write(5, 6, string_buffer);
|
||||
max7456Write(7, 7, "MENU: THRT MID");
|
||||
max7456Write(13, 8, "YAW RIGHT");
|
||||
max7456Write(13, 9, "PITCH UP");
|
||||
max7456Write(7, 7, STARTUP_HELP_TEXT1);
|
||||
max7456Write(12, 8, STARTUP_HELP_TEXT2);
|
||||
max7456Write(12, 9, STARTUP_HELP_TEXT3);
|
||||
|
||||
cmsScreenResync(); // Was max7456RefreshAll(); may be okay.
|
||||
|
||||
|
@ -427,7 +415,7 @@ void osdInit(void)
|
|||
*/
|
||||
char osdGetAltitudeSymbol()
|
||||
{
|
||||
switch (OSD_cfg.units) {
|
||||
switch (masterConfig.osdProfile.units) {
|
||||
case OSD_UNIT_IMPERIAL:
|
||||
return 0xF;
|
||||
default:
|
||||
|
@ -441,7 +429,7 @@ char osdGetAltitudeSymbol()
|
|||
*/
|
||||
int32_t osdGetAltitude(int32_t alt)
|
||||
{
|
||||
switch (OSD_cfg.units) {
|
||||
switch (masterConfig.osdProfile.units) {
|
||||
case OSD_UNIT_IMPERIAL:
|
||||
return (alt * 328) / 100; // Convert to feet / 100
|
||||
default:
|
||||
|
@ -454,44 +442,44 @@ void osdUpdateAlarms(void)
|
|||
int32_t alt = osdGetAltitude(BaroAlt) / 100;
|
||||
statRssi = rssi * 100 / 1024;
|
||||
|
||||
if (statRssi < OSD_cfg.rssi_alarm)
|
||||
OSD_cfg.item_pos[OSD_RSSI_VALUE] |= BLINK_FLAG;
|
||||
if (statRssi < masterConfig.osdProfile.rssi_alarm)
|
||||
masterConfig.osdProfile.item_pos[OSD_RSSI_VALUE] |= BLINK_FLAG;
|
||||
else
|
||||
OSD_cfg.item_pos[OSD_RSSI_VALUE] &= ~BLINK_FLAG;
|
||||
masterConfig.osdProfile.item_pos[OSD_RSSI_VALUE] &= ~BLINK_FLAG;
|
||||
|
||||
if (vbat <= (batteryWarningVoltage - 1))
|
||||
OSD_cfg.item_pos[OSD_MAIN_BATT_VOLTAGE] |= BLINK_FLAG;
|
||||
masterConfig.osdProfile.item_pos[OSD_MAIN_BATT_VOLTAGE] |= BLINK_FLAG;
|
||||
else
|
||||
OSD_cfg.item_pos[OSD_MAIN_BATT_VOLTAGE] &= ~BLINK_FLAG;
|
||||
masterConfig.osdProfile.item_pos[OSD_MAIN_BATT_VOLTAGE] &= ~BLINK_FLAG;
|
||||
|
||||
if (STATE(GPS_FIX) == 0)
|
||||
OSD_cfg.item_pos[OSD_GPS_SATS] |= BLINK_FLAG;
|
||||
masterConfig.osdProfile.item_pos[OSD_GPS_SATS] |= BLINK_FLAG;
|
||||
else
|
||||
OSD_cfg.item_pos[OSD_GPS_SATS] &= ~BLINK_FLAG;
|
||||
masterConfig.osdProfile.item_pos[OSD_GPS_SATS] &= ~BLINK_FLAG;
|
||||
|
||||
if (flyTime / 60 >= OSD_cfg.time_alarm && ARMING_FLAG(ARMED))
|
||||
OSD_cfg.item_pos[OSD_FLYTIME] |= BLINK_FLAG;
|
||||
if (flyTime / 60 >= masterConfig.osdProfile.time_alarm && ARMING_FLAG(ARMED))
|
||||
masterConfig.osdProfile.item_pos[OSD_FLYTIME] |= BLINK_FLAG;
|
||||
else
|
||||
OSD_cfg.item_pos[OSD_FLYTIME] &= ~BLINK_FLAG;
|
||||
masterConfig.osdProfile.item_pos[OSD_FLYTIME] &= ~BLINK_FLAG;
|
||||
|
||||
if (mAhDrawn >= OSD_cfg.cap_alarm)
|
||||
OSD_cfg.item_pos[OSD_MAH_DRAWN] |= BLINK_FLAG;
|
||||
if (mAhDrawn >= masterConfig.osdProfile.cap_alarm)
|
||||
masterConfig.osdProfile.item_pos[OSD_MAH_DRAWN] |= BLINK_FLAG;
|
||||
else
|
||||
OSD_cfg.item_pos[OSD_MAH_DRAWN] &= ~BLINK_FLAG;
|
||||
masterConfig.osdProfile.item_pos[OSD_MAH_DRAWN] &= ~BLINK_FLAG;
|
||||
|
||||
if (alt >= OSD_cfg.alt_alarm)
|
||||
OSD_cfg.item_pos[OSD_ALTITUDE] |= BLINK_FLAG;
|
||||
if (alt >= masterConfig.osdProfile.alt_alarm)
|
||||
masterConfig.osdProfile.item_pos[OSD_ALTITUDE] |= BLINK_FLAG;
|
||||
else
|
||||
OSD_cfg.item_pos[OSD_ALTITUDE] &= ~BLINK_FLAG;
|
||||
masterConfig.osdProfile.item_pos[OSD_ALTITUDE] &= ~BLINK_FLAG;
|
||||
}
|
||||
|
||||
void osdResetAlarms(void)
|
||||
{
|
||||
OSD_cfg.item_pos[OSD_RSSI_VALUE] &= ~BLINK_FLAG;
|
||||
OSD_cfg.item_pos[OSD_MAIN_BATT_VOLTAGE] &= ~BLINK_FLAG;
|
||||
OSD_cfg.item_pos[OSD_GPS_SATS] &= ~BLINK_FLAG;
|
||||
OSD_cfg.item_pos[OSD_FLYTIME] &= ~BLINK_FLAG;
|
||||
OSD_cfg.item_pos[OSD_MAH_DRAWN] &= ~BLINK_FLAG;
|
||||
masterConfig.osdProfile.item_pos[OSD_RSSI_VALUE] &= ~BLINK_FLAG;
|
||||
masterConfig.osdProfile.item_pos[OSD_MAIN_BATT_VOLTAGE] &= ~BLINK_FLAG;
|
||||
masterConfig.osdProfile.item_pos[OSD_GPS_SATS] &= ~BLINK_FLAG;
|
||||
masterConfig.osdProfile.item_pos[OSD_FLYTIME] &= ~BLINK_FLAG;
|
||||
masterConfig.osdProfile.item_pos[OSD_MAH_DRAWN] &= ~BLINK_FLAG;
|
||||
}
|
||||
|
||||
void osdResetStats(void)
|
||||
|
@ -654,20 +642,42 @@ void osdUpdate(uint32_t currentTime)
|
|||
// OSD specific CMS functions
|
||||
//
|
||||
|
||||
void osdGetSize(uint8_t *pRows, uint8_t *pCols)
|
||||
void osdGetDevParam(uint8_t *pRows, uint8_t *pCols, uint16_t *pBuftime, uint16_t *pBufsize)
|
||||
{
|
||||
*pRows = max7456GetRowsCount();
|
||||
*pCols = 30;
|
||||
*pBuftime = 1; // Very fast
|
||||
*pBufsize = 50000; // Very large
|
||||
}
|
||||
|
||||
void osdMenuBegin(void) {
|
||||
int osdMenuBegin(void)
|
||||
{
|
||||
osdResetAlarms();
|
||||
osdInMenu = true;
|
||||
refreshTimeout = 0;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
void osdMenuEnd(void) {
|
||||
int osdMenuEnd(void)
|
||||
{
|
||||
osdInMenu = false;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int osdClearScreen(void)
|
||||
{
|
||||
max7456ClearScreen();
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int osdWrite(uint8_t x, uint8_t y, char *s)
|
||||
{
|
||||
max7456Write(x, y, s);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
#ifdef EDIT_ELEMENT_SUPPORT
|
||||
|
@ -688,20 +698,20 @@ void osdEditElement(void *ptr)
|
|||
|
||||
void osdDrawElementPositioningHelp(void)
|
||||
{
|
||||
max7456Write(OSD_X(OSD_cfg.item_pos[OSD_ARTIFICIAL_HORIZON]), OSD_Y(OSD_cfg.item_pos[OSD_ARTIFICIAL_HORIZON]), "--- HELP --- ");
|
||||
max7456Write(OSD_X(OSD_cfg.item_pos[OSD_ARTIFICIAL_HORIZON]), OSD_Y(OSD_cfg.item_pos[OSD_ARTIFICIAL_HORIZON]) + 1, "USE ROLL/PITCH");
|
||||
max7456Write(OSD_X(OSD_cfg.item_pos[OSD_ARTIFICIAL_HORIZON]), OSD_Y(OSD_cfg.item_pos[OSD_ARTIFICIAL_HORIZON]) + 2, "TO MOVE ELEM. ");
|
||||
max7456Write(OSD_X(OSD_cfg.item_pos[OSD_ARTIFICIAL_HORIZON]), OSD_Y(OSD_cfg.item_pos[OSD_ARTIFICIAL_HORIZON]) + 3, " ");
|
||||
max7456Write(OSD_X(OSD_cfg.item_pos[OSD_ARTIFICIAL_HORIZON]), OSD_Y(OSD_cfg.item_pos[OSD_ARTIFICIAL_HORIZON]) + 4, "YAW - EXIT ");
|
||||
max7456Write(OSD_X(masterConfig.osdProfile.item_pos[OSD_ARTIFICIAL_HORIZON]), OSD_Y(masterConfig.osdProfile.item_pos[OSD_ARTIFICIAL_HORIZON]), "--- HELP --- ");
|
||||
max7456Write(OSD_X(masterConfig.osdProfile.item_pos[OSD_ARTIFICIAL_HORIZON]), OSD_Y(masterConfig.osdProfile.item_pos[OSD_ARTIFICIAL_HORIZON]) + 1, "USE ROLL/PITCH");
|
||||
max7456Write(OSD_X(masterConfig.osdProfile.item_pos[OSD_ARTIFICIAL_HORIZON]), OSD_Y(masterConfig.osdProfile.item_pos[OSD_ARTIFICIAL_HORIZON]) + 2, "TO MOVE ELEM. ");
|
||||
max7456Write(OSD_X(masterConfig.osdProfile.item_pos[OSD_ARTIFICIAL_HORIZON]), OSD_Y(masterConfig.osdProfile.item_pos[OSD_ARTIFICIAL_HORIZON]) + 3, " ");
|
||||
max7456Write(OSD_X(masterConfig.osdProfile.item_pos[OSD_ARTIFICIAL_HORIZON]), OSD_Y(masterConfig.osdProfile.item_pos[OSD_ARTIFICIAL_HORIZON]) + 4, "YAW - EXIT ");
|
||||
}
|
||||
#endif
|
||||
|
||||
screenFnVTable_t osdVTable = {
|
||||
osdGetSize,
|
||||
osdGetDevParam,
|
||||
osdMenuBegin,
|
||||
osdMenuEnd,
|
||||
max7456ClearScreen,
|
||||
max7456Write,
|
||||
osdClearScreen,
|
||||
osdWrite,
|
||||
NULL,
|
||||
max7456RefreshAll,
|
||||
};
|
||||
|
|
|
@ -17,8 +17,6 @@
|
|||
|
||||
#pragma once
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
typedef enum {
|
||||
OSD_RSSI_VALUE,
|
||||
OSD_MAIN_BATT_VOLTAGE,
|
||||
|
@ -70,5 +68,13 @@ void osdInit(void);
|
|||
void resetOsdConfig(osd_profile_t *osdProfile);
|
||||
screenFnVTable_t *osdCmsInit(void);
|
||||
|
||||
// Character coordinate and attributes
|
||||
|
||||
#define OSD_POS(x,y) (x | (y << 5))
|
||||
#define OSD_X(x) (x & 0x001F)
|
||||
#define OSD_Y(x) ((x >> 5) & 0x001F)
|
||||
#define VISIBLE_FLAG 0x0800
|
||||
#define BLINK_FLAG 0x0400
|
||||
#define VISIBLE(x) (x & VISIBLE_FLAG)
|
||||
#define BLINK(x) ((x & BLINK_FLAG) && blinkState)
|
||||
#define BLINK_OFF(x) (x & ~BLINK_FLAG)
|
||||
|
|
|
@ -65,8 +65,6 @@
|
|||
#include "io/gps.h"
|
||||
#include "io/ledstrip.h"
|
||||
#include "io/beeper.h"
|
||||
//#include "io/osd.h"
|
||||
//#include "io/vtx.h"
|
||||
|
||||
#include "rx/rx.h"
|
||||
|
||||
|
|
|
@ -36,9 +36,6 @@
|
|||
#include "io/gps.h"
|
||||
#include "io/gimbal.h"
|
||||
#include "io/serial.h"
|
||||
//#include "io/ledstrip.h"
|
||||
//#include "io/osd.h"
|
||||
//#include "io/vtx.h"
|
||||
|
||||
#include "sensors/boardalignment.h"
|
||||
#include "sensors/sensors.h"
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue