@@ -7,9 +7,24 @@ struct MassStorage {
7
7
};
8
8
9
9
typedef struct {
10
- FuriString * file_name ;
10
+ FuriString * file_name , * status_string ;
11
+ uint32_t read_speed , write_speed ;
12
+ uint32_t bytes_read , bytes_written ;
13
+ uint32_t update_time ;
11
14
} MassStorageModel ;
12
15
16
+ static void append_suffixed_byte_count (FuriString * string , uint32_t count ) {
17
+ if (count < 1024 ) {
18
+ furi_string_cat_printf (string , "%luB" , count );
19
+ } else if (count < 1024 * 1024 ) {
20
+ furi_string_cat_printf (string , "%luK" , count / 1024 );
21
+ } else if (count < 1024 * 1024 * 1024 ) {
22
+ furi_string_cat_printf (string , "%.3fM" , (double )count / (1024 * 1024 ));
23
+ } else {
24
+ furi_string_cat_printf (string , "%.3fG" , (double )count / (1024 * 1024 * 1024 ));
25
+ }
26
+ }
27
+
13
28
static void mass_storage_draw_callback (Canvas * canvas , void * _model ) {
14
29
MassStorageModel * model = _model ;
15
30
@@ -19,10 +34,28 @@ static void mass_storage_draw_callback(Canvas* canvas, void* _model) {
19
34
canvas_draw_str_aligned (
20
35
canvas , canvas_width (canvas ) / 2 , 0 , AlignCenter , AlignTop , "USB Mass Storage" );
21
36
22
- elements_string_fit_width (canvas , model -> file_name , 87 - 2 );
23
37
canvas_set_font (canvas , FontSecondary );
24
- canvas_draw_str (canvas , 12 , 25 , "Disc image:" );
25
- canvas_draw_str (canvas , 12 , 40 , furi_string_get_cstr (model -> file_name ));
38
+ elements_string_fit_width (canvas , model -> file_name , 89 - 2 );
39
+ canvas_draw_str_aligned (
40
+ canvas , 50 , 23 , AlignCenter , AlignBottom , furi_string_get_cstr (model -> file_name ));
41
+
42
+ furi_string_set_str (model -> status_string , "R:" );
43
+ append_suffixed_byte_count (model -> status_string , model -> bytes_read );
44
+ if (model -> read_speed ) {
45
+ furi_string_cat_str (model -> status_string , "; " );
46
+ append_suffixed_byte_count (model -> status_string , model -> read_speed );
47
+ furi_string_cat_str (model -> status_string , "ps" );
48
+ }
49
+ canvas_draw_str (canvas , 12 , 34 , furi_string_get_cstr (model -> status_string ));
50
+
51
+ furi_string_set_str (model -> status_string , "W:" );
52
+ append_suffixed_byte_count (model -> status_string , model -> bytes_written );
53
+ if (model -> write_speed ) {
54
+ furi_string_cat_str (model -> status_string , "; " );
55
+ append_suffixed_byte_count (model -> status_string , model -> write_speed );
56
+ furi_string_cat_str (model -> status_string , "ps" );
57
+ }
58
+ canvas_draw_str (canvas , 12 , 44 , furi_string_get_cstr (model -> status_string ));
26
59
}
27
60
28
61
MassStorage * mass_storage_alloc () {
@@ -33,7 +66,10 @@ MassStorage* mass_storage_alloc() {
33
66
with_view_model (
34
67
mass_storage -> view ,
35
68
MassStorageModel * model ,
36
- { model -> file_name = furi_string_alloc (); },
69
+ {
70
+ model -> file_name = furi_string_alloc ();
71
+ model -> status_string = furi_string_alloc ();
72
+ },
37
73
false);
38
74
view_set_context (mass_storage -> view , mass_storage );
39
75
view_set_draw_callback (mass_storage -> view , mass_storage_draw_callback );
@@ -46,7 +82,10 @@ void mass_storage_free(MassStorage* mass_storage) {
46
82
with_view_model (
47
83
mass_storage -> view ,
48
84
MassStorageModel * model ,
49
- { furi_string_free (model -> file_name ); },
85
+ {
86
+ furi_string_free (model -> file_name );
87
+ furi_string_free (model -> status_string );
88
+ },
50
89
false);
51
90
view_free (mass_storage -> view );
52
91
free (mass_storage );
@@ -65,3 +104,19 @@ void mass_storage_set_file_name(MassStorage* mass_storage, FuriString* name) {
65
104
{ furi_string_set (model -> file_name , name ); },
66
105
true);
67
106
}
107
+
108
+ void mass_storage_set_stats (MassStorage * mass_storage , uint32_t read , uint32_t written ) {
109
+ with_view_model (
110
+ mass_storage -> view ,
111
+ MassStorageModel * model ,
112
+ {
113
+ uint32_t now = furi_get_tick ();
114
+ model -> read_speed = (read - model -> bytes_read ) * 1000 / (now - model -> update_time );
115
+ model -> write_speed =
116
+ (written - model -> bytes_written ) * 1000 / (now - model -> update_time );
117
+ model -> bytes_read = read ;
118
+ model -> bytes_written = written ;
119
+ model -> update_time = now ;
120
+ },
121
+ true);
122
+ }
0 commit comments