Skip to content

Commit

Permalink
minor fix format_float, CF/SD alternate display
Browse files Browse the repository at this point in the history
  • Loading branch information
arnaud-sintes committed Oct 19, 2023
1 parent e29a02c commit 550ecd7
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 12 deletions.
37 changes: 26 additions & 11 deletions src/lens.c
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@
#include "focus.h"
#include "lvinfo.h"
#include "powersave.h"
#include "util.h"

// for movie logging
static char* mvr_logfile_buffer = 0;
Expand Down Expand Up @@ -2928,27 +2929,41 @@ static LVINFO_UPDATE_FUNC(fps_update)
}
}

struct card_t
{
char * type;
double free_space_gb;
};

static LVINFO_UPDATE_FUNC(free_space_update)
{
LVINFO_BUFFER(8);
LVINFO_BUFFER(11);
// "XX:999.1GB"

if (RECORDING)
{
/* leave space for the recording indicators */
return;
}

int free_space_32k = get_free_space_32k(get_shooting_card());

int fsg = free_space_32k >> 15;
int fsgr = free_space_32k - (fsg << 15);
int fsgf = (fsgr * 10) >> 15;
// feed CF & SD cards info:
struct card_t cards[ 2 ];
int card_count = 0;
for( int i = 0; i < 2; i++ ) {
struct card_info * p_card_info = get_card( i );
if( p_card_info->cluster_size == 0 ) {
continue;
}
cards[ card_count ].type = p_card_info->type;
cards[ card_count ].free_space_gb = ( double ) get_free_space_32k( p_card_info ) *
32000 / ( double ) ( 1024 * 1024 * 1024 );
card_count++;
}

snprintf(buffer, sizeof(buffer),
"%d.%dGB",
fsg,
fsgf
);
// alternate display between cards every two seconds max.:
struct card_t p_card = cards[ ( get_seconds_clock() >> 1 ) % card_count ];
char space_buffer[ 16 ];
snprintf( buffer, sizeof( buffer ), "%s:%sGB", p_card.type, format_float_ex( p_card.free_space_gb, 1, space_buffer, 15 ) );
}

static LVINFO_UPDATE_FUNC(mode_update)
Expand Down
25 changes: 25 additions & 0 deletions src/lvinfo.c
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ static GUARDED_BY(lvinfo_sem) int layout_dirty = 0;

static GUARDED_BY(lvinfo_sem) int default_font = FONT_MED_LARGE | FONT_ALIGN_CENTER; /* used in normal situations */
static GUARDED_BY(lvinfo_sem) int small_font = FONT_MED | FONT_ALIGN_CENTER; /* used if the layout gets really tight */
static GUARDED_BY(lvinfo_sem) int fixed_font = FONT_MONO_20 | FONT_ALIGN_CENTER; /* used for fixed displays */

/* fixme: false thread safety warning
* when called from INIT_FUNC's, the semaphore may not be initialized yet
Expand Down Expand Up @@ -61,6 +62,13 @@ void lvinfo_update_items(struct lvinfo_item * items[], int count, int override_f
items[i]->hidden = 0;

if (override_font) items[i]->fontspec = override_font;

// specific case for cards free space to avoid horizontal spacing
// flickering due to potential SD/CF report alternance:
if( strcmp(items[i]->name, "Free space") == 0 ) {
items[i]->fontspec = fixed_font;
}

int fnt = items[i]->fontspec;
items[i]->color_fg = FONT_FG(fnt);
items[i]->color_bg = FONT_BG(fnt);
Expand Down Expand Up @@ -587,9 +595,26 @@ void lvinfo_display(int top, int bottom)
give_semaphore(lvinfo_sem);
}


void lvinfo_regular_update()
{
// ensures the top bar is refreshed at least every seconds
for(;;) {
// bypass if menus or recording
if( !gui_menu_shown() && !RECORDING ) {
BMP_LOCK( if (lv) update_lens_display(1,0); );
}
msleep(1000);
}
}


static void lvinfo_init()
{
lvinfo_sem = create_named_semaphore("lvinfo_sem", 1);

// regular update task:
task_create("lvinfo_regular_update", 0x18, 0x1000, lvinfo_regular_update, 0 );
}

INIT_FUNC("lvinfo", lvinfo_init);
Expand Down
2 changes: 1 addition & 1 deletion src/util.c
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ int bin_search(int lo, int hi, CritFunc crit)

char * format_float_ex( const double _value, const int _digits, char * _buffer, const size_t _buffer_len )
{
ASSERT( _digits > 1 && _digits < 9 );
ASSERT( _digits > 0 && _digits < 9 );
static const unsigned factors[ 8 ] = { 10, 100, 1000, 10000, 100000, 1000000, 10000000, 100000000 };
static const char * const signs[ 2 ] = { "", "-" };
const unsigned factor = factors[ _digits - 1 ];
Expand Down

0 comments on commit 550ecd7

Please sign in to comment.