Skip to content

Commit

Permalink
add zoom capability
Browse files Browse the repository at this point in the history
  • Loading branch information
iltis42 committed Apr 23, 2024
1 parent e4b5095 commit 5e44d4a
Show file tree
Hide file tree
Showing 9 changed files with 57 additions and 23 deletions.
29 changes: 24 additions & 5 deletions main/SetupMenu.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -154,8 +154,15 @@ void SetupMenu::display( int mode ){
}

void SetupMenu::up(int count){
if( (selected != this) || !_menu_active )
if( selected != this ){
return;
}
if( !_menu_active ){
ESP_LOGI(FNAME,"zoom up %s", _title );
if( zoom < 5.0 )
zoom = zoom * 1.3;
return;
}
ESP_LOGI(FNAME,"down %d %d", highlight, _childs.size() );
if( focus )
return;
Expand All @@ -172,8 +179,14 @@ void SetupMenu::up(int count){
}

void SetupMenu::down(int count){
if( (selected != this) || !_menu_active )
if( selected != this)
return;
if( !_menu_active ){
if( zoom > 0.5 )
zoom = zoom * 0.7;
ESP_LOGI(FNAME,"zoom down %f", zoom );
return;
}
ESP_LOGI(FNAME,"SetupMenu::up %d %d", highlight, _childs.size() );
if( focus )
return;
Expand Down Expand Up @@ -284,21 +297,27 @@ void SetupMenu::options_menu_create_units( MenuEntry *top ){

void SetupMenu::options_menu_create_settings( MenuEntry *top ){
SetupMenuValFloat * vol = new SetupMenuValFloat( PROGMEM"Buzzer Volume", "%", 0.0, 100, 10, vol_adj, false, &audio_volume );
vol->setHelp(PROGMEM"Buzzer volume maximum level", 110 );
vol->setHelp(PROGMEM"Buzzer volume maximum level", 160 );
top->addEntry( vol );

SetupMenuSelect * mod = new SetupMenuSelect( PROGMEM"Display Mode", RST_NONE, 0, true, &display_mode );
mod->addEntry( PROGMEM"Normal");
mod->addEntry( PROGMEM"Simple");
top->addEntry( mod );
mod->setHelp( "Normal mode for multiple targets, Simple mode only one", hpos );
mod->setHelp( "Normal mode for multiple targets, Simple mode only one", 160 );

SetupMenuSelect * log = new SetupMenuSelect( PROGMEM"Distance Mode", RST_NONE, 0, true, &log_scale );
log->addEntry( PROGMEM"Linear");
log->addEntry( PROGMEM"Logarithmic");
top->addEntry( log );
log->setHelp(PROGMEM"Select distance either linear or logarithmic what zooms far distant targets on the screen", 160 );
}

void SetupMenu::setup_create_root(MenuEntry *top ){
ESP_LOGI(FNAME,"setup_create_root()");
SetupMenu * set = new SetupMenu( PROGMEM"Settings" );
top->addEntry( set );
set->setHelp( PROGMEM"Setup volume and mode", 125);
set->setHelp( PROGMEM"Setup volume and other modes", 160);
set->addCreator(options_menu_create_settings);

SetupMenu * un = new SetupMenu( PROGMEM"Units" );
Expand Down
1 change: 1 addition & 0 deletions main/SetupNG.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ SetupNG<int> serial1_tx_enable( "SER1_TX_ENA", 1 );
SetupNG<int> software_update( "SOFTWARE_UPDATE", 0 );
SetupNG<int> log_level( "LOG_LEVEL", 3 );
SetupNG<int> factory_reset( "FACTORY_RES" , 0 );
SetupNG<int> log_scale( "LOG_SCALE", 0 );

SetupNG<int> alt_unit( "ALT_UNIT", ALT_UNIT_METER );
SetupNG<int> ias_unit( "IAS_UNIT", SPEED_UNIT_KMH );
Expand Down
1 change: 1 addition & 0 deletions main/SetupNG.h
Original file line number Diff line number Diff line change
Expand Up @@ -319,6 +319,7 @@ extern SetupNG<int> serial1_tx_enable;
extern SetupNG<int> software_update;
extern SetupNG<int> log_level;
extern SetupNG<int> factory_reset;
extern SetupNG<int> log_scale;

extern uint8_t g_col_background;
extern uint8_t g_col_highlight;
Expand Down
16 changes: 8 additions & 8 deletions main/Target.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ int Target::old_dist = -10000;
unsigned int Target::old_alt = 100000;
unsigned int Target::old_id = 0;
int Target::old_var = -10000.0;
int Target::blink = 0;


Target::Target() {
Expand Down Expand Up @@ -204,17 +205,17 @@ void Target::checkClose(){
}
}


// Transform to heading from ground track
void Target::recalc(){
age = 0; // reset age
rel_target_heading = Vector::angleDiffDeg( (float)pflaa.track, Flarm::getGndCourse() );
rel_target_dir = Vector::angleDiffDeg( R2D(atan2( pflaa.relEast, pflaa.relNorth )), Flarm::getGndCourse() );
dist = sqrt( pflaa.relNorth*pflaa.relNorth + pflaa.relEast*pflaa.relEast )/1000.0; // distance in km float
float relV=float(pflaa.relVertical/1000.0);
prox=sqrt( relV*relV + dist*dist );
float logs = log( 2+prox );
float pix = fmax( logs*SCALE, 30.0 );
prox=sqrt( relV*relV + dist*dist ); // proximity 3D
float logs = dist;
if( log_scale.get() )
logs = log( 2+dist );
float pix = fmax( zoom*logs*SCALE, 20.0 );
// ESP_LOGI(FNAME,"prox: %f, log:%f, pix:%f", prox, logs, pix );
x=(DISPLAY_W/2)+pix*sin(D2R(rel_target_dir));
y=(DISPLAY_H/2)-pix*cos(D2R(rel_target_dir));
Expand Down Expand Up @@ -257,8 +258,6 @@ void Target::checkAlarm(){
}
}

int blink = 0;

void Target::draw(){
checkAlarm();
int size = std::min( 30.0, std::min( 80.0, 10.0+10.0/dist ) );
Expand Down Expand Up @@ -291,18 +290,19 @@ void Target::draw(){
}
}


void Target::update( nmea_pflaa_s a_pflaa ){
pflaa = a_pflaa;
// ESP_LOGI(FNAME,"Target (ID %06X) update()", pflaa.ID );
recalc();
age=0;
}

void Target::ageTarget(){
if( age < 1000 )
age++;
if( _buzzedHoldDown )
_buzzedHoldDown--;
recalc();
}

void Target::dumpInfo(){
Expand Down
3 changes: 2 additions & 1 deletion main/Target.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
#define MAIN_TARGET_H_


#define SCALE 30 // 1km
#define SCALE 30 // 1km @ zoom = 1

class Target {
public:
Expand Down Expand Up @@ -62,6 +62,7 @@ class Target {
static unsigned int old_alt;
static unsigned int old_id;
static int old_var;
static int blink;
};

#endif /* MAIN_TARGET_H_ */
25 changes: 17 additions & 8 deletions main/TargetManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ int TargetManager::_tick = 0;
int TargetManager::holddown = 0;
TaskHandle_t TargetManager::pid = 0;
unsigned int TargetManager::min_id = 0;
float TargetManager::old_radius=0.0;


#define TASK_PERIOD 100
Expand Down Expand Up @@ -64,10 +65,10 @@ TargetManager::~TargetManager() {
// TODO Auto-generated destructor stub
}

void TargetManager::drawN( int x, int y, bool erase, float north ){
void TargetManager::drawN( int x, int y, bool erase, float north, float dist ){
// ESP_LOGI(FNAME,"drawAirplane x:%d y:%d small:%d", x, y, smallSize );
egl->setFontPosCenter();
egl->setPrintPos( x-SCALE*sin(D2R(north))-5, y-SCALE*cos(D2R(north))+6 );
egl->setPrintPos( x-dist*sin(D2R(north))-5, y-dist*cos(D2R(north))+6 );
egl->setFont(ucg_font_ncenR14_hr);
if(erase)
egl->setColor(COLOR_BLACK);
Expand All @@ -83,13 +84,21 @@ void TargetManager::drawAirplane( int x, int y, float north ){
egl->drawTetragon( x-15,y-1, x-15,y+1, x+15,y+1, x+15,y-1 ); // wings
egl->drawTetragon( x-1,y+10, x-1,y-6, x+1,y-6, x+1,y+10 ); // fuselage
egl->drawTetragon( x-4,y+10, x-4,y+9, x+4,y+9, x+4,y+10 ); // elevator
egl->setColor(COLOR_GREEN);
egl->drawCircle( x,y, 25 );
if( north != oldN ){
if( oldN != -1.0 )
drawN( x,y, true, oldN );
drawN( x,y, false, north );
float logs = 1;
if( log_scale.get() )
logs = log( 2+1 );
float new_radius = zoom*logs*SCALE;

if( old_radius ){
egl->setColor(COLOR_BLACK);
egl->drawCircle( x,y, old_radius );
}
egl->setColor(COLOR_GREEN);
egl->drawCircle( x,y, new_radius );
if( oldN != -1.0 )
drawN( x,y, true, oldN, old_radius );
drawN( x,y, false, north, new_radius );
old_radius = new_radius;
}

void TargetManager::printAlarm( const char*alarm, int x, int y, int inactive ){
Expand Down
3 changes: 2 additions & 1 deletion main/TargetManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ class TargetManager {
static std::map< unsigned int, Target> targets;
static std::map< unsigned int, Target>::iterator id_iter;
static float oldN;
static void drawN( int x, int y, bool erase, float north );
static void drawN( int x, int y, bool erase, float north, float azoom );
static void printAlarm( const char*alarm, int x, int y, int inactive );
static void nextTarget(int timer);
static void taskTargetMgr(void *pvParameters);
Expand All @@ -35,6 +35,7 @@ class TargetManager {
static int holddown;
static TaskHandle_t pid;
static unsigned int min_id;
static float old_radius;
};

#endif /* MAIN_TARGETMANAGER_H_ */
1 change: 1 addition & 0 deletions main/flarmview.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ bool inch2dot4=false;
Switch swUp;
Switch swDown;
Switch swMode;
float zoom=1.0;

extern "C" void app_main(void)
{
Expand Down
1 change: 1 addition & 0 deletions main/flarmview.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@ extern bool inch2dot4;
extern Switch swUp;
extern Switch swDown;
extern Switch swMode;
extern float zoom;

0 comments on commit 5e44d4a

Please sign in to comment.