Skip to content

Commit

Permalink
do not start to record if sdcard free space < 103MB
Browse files Browse the repository at this point in the history
  • Loading branch information
ligenxxxx committed Jun 21, 2024
1 parent 84fdd30 commit 6c90d7d
Show file tree
Hide file tree
Showing 7 changed files with 37 additions and 16 deletions.
3 changes: 2 additions & 1 deletion src/core/dvr.c
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
#include "core/settings.h"
#include "driver/hardware.h"
#include "ui/page_common.h"
#include "util/sdcard.h"
#include "util/system.h"

bool dvr_is_recording = false;
Expand Down Expand Up @@ -165,7 +166,7 @@ void dvr_cmd(osd_dvr_cmd_t cmd) {
}

if (start_rec) {
if (!dvr_is_recording && g_sdcard_size >= 103) {
if (!dvr_is_recording && !sdcard_is_full()) {
dvr_update_record_conf();
dvr_is_recording = true;
usleep(10 * 1000);
Expand Down
10 changes: 4 additions & 6 deletions src/core/thread.c
Original file line number Diff line number Diff line change
Expand Up @@ -43,11 +43,7 @@ static void detect_sdcard(void) {
g_sdcard_enable = sdcard_mounted();

if ((g_sdcard_enable && !sdcard_enable_last) || g_sdcard_det_req) {
struct statfs info;
if (statfs("/mnt/extsd", &info) == 0)
g_sdcard_size = (info.f_bsize * info.f_bavail) >> 20; // in MB
else
g_sdcard_size = 0;
sdcard_update_free_size();
g_sdcard_det_req = 0;
}

Expand Down Expand Up @@ -135,7 +131,9 @@ static void check_hdzero_signal(int vtmg_change) {
if (cnt >= SIGNAL_ACCQ_DURATION_THR) {
cnt = 0;
LOGI("Signal accquired");
dvr_cmd(DVR_START);
sdcard_update_free_size();
if (!sdcard_is_full())
dvr_cmd(DVR_START);
}
} else
cnt = 0;
Expand Down
2 changes: 1 addition & 1 deletion src/ui/page_common.c
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,7 @@ void create_slider_item(slider_group_t *slider_group, lv_obj_t *parent, const ch
lv_obj_remove_style_all(slider_group->slider);
lv_obj_add_style(slider_group->slider, &style_silder_main, LV_PART_MAIN);
lv_obj_set_style_bg_color(slider_group->slider, COLOR_DISABLED, LV_PART_MAIN | STATE_DISABLED);

lv_obj_add_style(slider_group->slider, &style_silder_indicator, LV_PART_INDICATOR);
lv_obj_set_style_bg_color(slider_group->slider, COLOR_DISABLED, LV_PART_INDICATOR | STATE_DISABLED);
lv_obj_add_style(slider_group->slider, &style_silder_pressed_color, LV_PART_INDICATOR | LV_STATE_PRESSED);
Expand Down
5 changes: 2 additions & 3 deletions src/ui/page_common.h
Original file line number Diff line number Diff line change
Expand Up @@ -77,8 +77,8 @@ extern "C" {
#define MAX_PANELS 9

#define FLAG_SELECTABLE LV_OBJ_FLAG_USER_1
#define STATE_DISABLED LV_STATE_USER_1
#define COLOR_DISABLED (lv_color_darken(lv_color_white(), 127))
#define STATE_DISABLED LV_STATE_USER_1
#define COLOR_DISABLED (lv_color_darken(lv_color_white(), 127))

typedef enum {
SOURCE_HDZERO = 0,
Expand Down Expand Up @@ -132,7 +132,6 @@ typedef uint8_t lv_menu_builder_variant_t;

extern bool g_sdcard_enable;
extern bool g_sdcard_det_req;
extern int g_sdcard_size;
extern bool g_autoscan_exit;
extern bool g_scanning;
extern bool g_latency_locked;
Expand Down
7 changes: 3 additions & 4 deletions src/ui/ui_statusbar.c
Original file line number Diff line number Diff line change
Expand Up @@ -209,16 +209,15 @@ void statubar_update(void) {
} else {
if (g_sdcard_enable) {
int cnt = get_videofile_cnt();
float gb = g_sdcard_size / 1024.0;
bool bFull = g_sdcard_size < 103;
float gb = sdcard_free_size() / 1024.0;
lv_img_set_src(img_sdc, &img_sdcard);
if (cnt != 0) {
if (bFull)
if (sdcard_is_full())
sprintf(buf, "%d clip(s), SD Card full", cnt);
else
sprintf(buf, "%d clip(s), %.2fGB available", cnt, gb);
} else {
if (bFull)
if (sdcard_is_full())
sprintf(buf, "#FF0000 SD Card full#");
else
sprintf(buf, "%.2fGB available", gb);
Expand Down
22 changes: 22 additions & 0 deletions src/util/sdcard.c
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
#include "sdcard.h"

#include <sys/stat.h>
#include <sys/vfs.h>
#include <unistd.h>

static int g_sdcard_free_size = 0;

bool sdcard_mounted() {
struct stat mountpoint;
struct stat mountpoint_parent;
Expand All @@ -20,3 +23,22 @@ bool sdcard_mounted() {
bool sdcard_inserted() {
return access(SD_BLOCK_DEVICE, F_OK) == 0;
}

void sdcard_update_free_size() {
struct statfs info;
if (statfs("/mnt/extsd", &info) == 0)
g_sdcard_free_size = (info.f_bsize * info.f_bavail) >> 20; // in MB
else
g_sdcard_free_size = 0;
}

bool sdcard_is_full() {
return g_sdcard_free_size < 103;
}

/*
return in MB
*/
int sdcard_free_size() {
return g_sdcard_free_size;
}
4 changes: 3 additions & 1 deletion src/util/sdcard.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,10 @@ extern "C" {
#define SD_BLOCK_DEVICE "/dev/mmcblk0"

bool sdcard_mounted();

bool sdcard_inserted();
void sdcard_update_free_size();
int sdcard_free_size();
bool sdcard_is_full();

#ifdef __cplusplus
}
Expand Down

0 comments on commit 6c90d7d

Please sign in to comment.