debug apps: made runnable as .faps; sdk: resolved additional APIs in use by faps (#2333)
* sdk: resolve additional APIs in use by faps * debug tools: fixed battery_test, bt_debug, display_test, rpc_debug Co-authored-by: hedger <hedger@nanode.su> Co-authored-by: hedger <hedger@users.noreply.github.com> Co-authored-by: あく <alleteam@gmail.com>
This commit is contained in:
		
							parent
							
								
									126a9efd09
								
							
						
					
					
						commit
						24a23e5dc7
					
				| @ -11,4 +11,5 @@ App( | |||||||
|     stack_size=1 * 1024, |     stack_size=1 * 1024, | ||||||
|     order=130, |     order=130, | ||||||
|     fap_category="Debug", |     fap_category="Debug", | ||||||
|  |     fap_libs=["assets"], | ||||||
| ) | ) | ||||||
|  | |||||||
							
								
								
									
										148
									
								
								applications/debug/battery_test_app/views/battery_info.c
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										148
									
								
								applications/debug/battery_test_app/views/battery_info.c
									
									
									
									
									
										Normal file
									
								
							| @ -0,0 +1,148 @@ | |||||||
|  | #include "battery_info.h" | ||||||
|  | #include <furi.h> | ||||||
|  | #include <gui/elements.h> | ||||||
|  | #include <assets_icons.h> | ||||||
|  | 
 | ||||||
|  | #define LOW_CHARGE_THRESHOLD 10 | ||||||
|  | #define HIGH_DRAIN_CURRENT_THRESHOLD 100 | ||||||
|  | 
 | ||||||
|  | struct BatteryInfo { | ||||||
|  |     View* view; | ||||||
|  | }; | ||||||
|  | 
 | ||||||
|  | static void draw_stat(Canvas* canvas, int x, int y, const Icon* icon, char* val) { | ||||||
|  |     canvas_draw_frame(canvas, x - 7, y + 7, 30, 13); | ||||||
|  |     canvas_draw_icon(canvas, x, y, icon); | ||||||
|  |     canvas_set_color(canvas, ColorWhite); | ||||||
|  |     canvas_draw_box(canvas, x - 4, y + 16, 24, 6); | ||||||
|  |     canvas_set_color(canvas, ColorBlack); | ||||||
|  |     canvas_draw_str_aligned(canvas, x + 8, y + 22, AlignCenter, AlignBottom, val); | ||||||
|  | }; | ||||||
|  | 
 | ||||||
|  | static void draw_battery(Canvas* canvas, BatteryInfoModel* data, int x, int y) { | ||||||
|  |     char emote[20] = {}; | ||||||
|  |     char header[20] = {}; | ||||||
|  |     char value[20] = {}; | ||||||
|  | 
 | ||||||
|  |     int32_t drain_current = data->gauge_current * (-1000); | ||||||
|  |     uint32_t charge_current = data->gauge_current * 1000; | ||||||
|  | 
 | ||||||
|  |     // Draw battery
 | ||||||
|  |     canvas_draw_icon(canvas, x, y, &I_BatteryBody_52x28); | ||||||
|  |     if(charge_current > 0) { | ||||||
|  |         canvas_draw_icon(canvas, x + 16, y + 7, &I_FaceCharging_29x14); | ||||||
|  |     } else if(drain_current > HIGH_DRAIN_CURRENT_THRESHOLD) { | ||||||
|  |         canvas_draw_icon(canvas, x + 16, y + 7, &I_FaceConfused_29x14); | ||||||
|  |     } else if(data->charge < LOW_CHARGE_THRESHOLD) { | ||||||
|  |         canvas_draw_icon(canvas, x + 16, y + 7, &I_FaceNopower_29x14); | ||||||
|  |     } else { | ||||||
|  |         canvas_draw_icon(canvas, x + 16, y + 7, &I_FaceNormal_29x14); | ||||||
|  |     } | ||||||
|  | 
 | ||||||
|  |     // Draw bubble
 | ||||||
|  |     elements_bubble(canvas, 53, 0, 71, 39); | ||||||
|  | 
 | ||||||
|  |     // Set text
 | ||||||
|  |     if(charge_current > 0) { | ||||||
|  |         snprintf(emote, sizeof(emote), "%s", "Yummy!"); | ||||||
|  |         snprintf(header, sizeof(header), "%s", "Charging at"); | ||||||
|  |         snprintf( | ||||||
|  |             value, | ||||||
|  |             sizeof(value), | ||||||
|  |             "%lu.%luV   %lumA", | ||||||
|  |             (uint32_t)(data->vbus_voltage), | ||||||
|  |             (uint32_t)(data->vbus_voltage * 10) % 10, | ||||||
|  |             charge_current); | ||||||
|  |     } else if(drain_current > 0) { | ||||||
|  |         snprintf( | ||||||
|  |             emote, | ||||||
|  |             sizeof(emote), | ||||||
|  |             "%s", | ||||||
|  |             drain_current > HIGH_DRAIN_CURRENT_THRESHOLD ? "Oh no!" : "Om-nom-nom!"); | ||||||
|  |         snprintf(header, sizeof(header), "%s", "Consumption is"); | ||||||
|  |         snprintf( | ||||||
|  |             value, | ||||||
|  |             sizeof(value), | ||||||
|  |             "%ld %s", | ||||||
|  |             drain_current, | ||||||
|  |             drain_current > HIGH_DRAIN_CURRENT_THRESHOLD ? "mA!" : "mA"); | ||||||
|  |     } else if(drain_current != 0) { | ||||||
|  |         snprintf(header, 20, "..."); | ||||||
|  |     } else if(data->charging_voltage < 4.2) { | ||||||
|  |         // Non-default battery charging limit, mention it
 | ||||||
|  |         snprintf(emote, sizeof(emote), "Charged!"); | ||||||
|  |         snprintf(header, sizeof(header), "Limited to"); | ||||||
|  |         snprintf( | ||||||
|  |             value, | ||||||
|  |             sizeof(value), | ||||||
|  |             "%lu.%luV", | ||||||
|  |             (uint32_t)(data->charging_voltage), | ||||||
|  |             (uint32_t)(data->charging_voltage * 10) % 10); | ||||||
|  |     } else { | ||||||
|  |         snprintf(header, sizeof(header), "Charged!"); | ||||||
|  |     } | ||||||
|  | 
 | ||||||
|  |     canvas_draw_str_aligned(canvas, 92, y + 3, AlignCenter, AlignCenter, emote); | ||||||
|  |     canvas_draw_str_aligned(canvas, 92, y + 15, AlignCenter, AlignCenter, header); | ||||||
|  |     canvas_draw_str_aligned(canvas, 92, y + 27, AlignCenter, AlignCenter, value); | ||||||
|  | }; | ||||||
|  | 
 | ||||||
|  | static void battery_info_draw_callback(Canvas* canvas, void* context) { | ||||||
|  |     furi_assert(context); | ||||||
|  |     BatteryInfoModel* model = context; | ||||||
|  | 
 | ||||||
|  |     canvas_clear(canvas); | ||||||
|  |     canvas_set_color(canvas, ColorBlack); | ||||||
|  |     draw_battery(canvas, model, 0, 5); | ||||||
|  | 
 | ||||||
|  |     char batt_level[10]; | ||||||
|  |     char temperature[10]; | ||||||
|  |     char voltage[10]; | ||||||
|  |     char health[10]; | ||||||
|  | 
 | ||||||
|  |     snprintf(batt_level, sizeof(batt_level), "%lu%%", (uint32_t)model->charge); | ||||||
|  |     snprintf(temperature, sizeof(temperature), "%lu C", (uint32_t)model->gauge_temperature); | ||||||
|  |     snprintf( | ||||||
|  |         voltage, | ||||||
|  |         sizeof(voltage), | ||||||
|  |         "%lu.%01lu V", | ||||||
|  |         (uint32_t)model->gauge_voltage, | ||||||
|  |         (uint32_t)(model->gauge_voltage * 10) % 10UL); | ||||||
|  |     snprintf(health, sizeof(health), "%d%%", model->health); | ||||||
|  | 
 | ||||||
|  |     draw_stat(canvas, 8, 42, &I_Battery_16x16, batt_level); | ||||||
|  |     draw_stat(canvas, 40, 42, &I_Temperature_16x16, temperature); | ||||||
|  |     draw_stat(canvas, 72, 42, &I_Voltage_16x16, voltage); | ||||||
|  |     draw_stat(canvas, 104, 42, &I_Health_16x16, health); | ||||||
|  | } | ||||||
|  | 
 | ||||||
|  | BatteryInfo* battery_info_alloc() { | ||||||
|  |     BatteryInfo* battery_info = malloc(sizeof(BatteryInfo)); | ||||||
|  |     battery_info->view = view_alloc(); | ||||||
|  |     view_set_context(battery_info->view, battery_info); | ||||||
|  |     view_allocate_model(battery_info->view, ViewModelTypeLocking, sizeof(BatteryInfoModel)); | ||||||
|  |     view_set_draw_callback(battery_info->view, battery_info_draw_callback); | ||||||
|  | 
 | ||||||
|  |     return battery_info; | ||||||
|  | } | ||||||
|  | 
 | ||||||
|  | void battery_info_free(BatteryInfo* battery_info) { | ||||||
|  |     furi_assert(battery_info); | ||||||
|  |     view_free(battery_info->view); | ||||||
|  |     free(battery_info); | ||||||
|  | } | ||||||
|  | 
 | ||||||
|  | View* battery_info_get_view(BatteryInfo* battery_info) { | ||||||
|  |     furi_assert(battery_info); | ||||||
|  |     return battery_info->view; | ||||||
|  | } | ||||||
|  | 
 | ||||||
|  | void battery_info_set_data(BatteryInfo* battery_info, BatteryInfoModel* data) { | ||||||
|  |     furi_assert(battery_info); | ||||||
|  |     furi_assert(data); | ||||||
|  |     with_view_model( | ||||||
|  |         battery_info->view, | ||||||
|  |         BatteryInfoModel * model, | ||||||
|  |         { memcpy(model, data, sizeof(BatteryInfoModel)); }, | ||||||
|  |         true); | ||||||
|  | } | ||||||
							
								
								
									
										23
									
								
								applications/debug/battery_test_app/views/battery_info.h
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										23
									
								
								applications/debug/battery_test_app/views/battery_info.h
									
									
									
									
									
										Normal file
									
								
							| @ -0,0 +1,23 @@ | |||||||
|  | #pragma once | ||||||
|  | 
 | ||||||
|  | #include <gui/view.h> | ||||||
|  | 
 | ||||||
|  | typedef struct BatteryInfo BatteryInfo; | ||||||
|  | 
 | ||||||
|  | typedef struct { | ||||||
|  |     float vbus_voltage; | ||||||
|  |     float gauge_voltage; | ||||||
|  |     float gauge_current; | ||||||
|  |     float gauge_temperature; | ||||||
|  |     float charging_voltage; | ||||||
|  |     uint8_t charge; | ||||||
|  |     uint8_t health; | ||||||
|  | } BatteryInfoModel; | ||||||
|  | 
 | ||||||
|  | BatteryInfo* battery_info_alloc(); | ||||||
|  | 
 | ||||||
|  | void battery_info_free(BatteryInfo* battery_info); | ||||||
|  | 
 | ||||||
|  | View* battery_info_get_view(BatteryInfo* battery_info); | ||||||
|  | 
 | ||||||
|  | void battery_info_set_data(BatteryInfo* battery_info, BatteryInfoModel* data); | ||||||
| @ -31,9 +31,6 @@ uint32_t bt_debug_start_view(void* context) { | |||||||
| BtDebugApp* bt_debug_app_alloc() { | BtDebugApp* bt_debug_app_alloc() { | ||||||
|     BtDebugApp* app = malloc(sizeof(BtDebugApp)); |     BtDebugApp* app = malloc(sizeof(BtDebugApp)); | ||||||
| 
 | 
 | ||||||
|     // Load settings
 |  | ||||||
|     bt_settings_load(&app->settings); |  | ||||||
| 
 |  | ||||||
|     // Gui
 |     // Gui
 | ||||||
|     app->gui = furi_record_open(RECORD_GUI); |     app->gui = furi_record_open(RECORD_GUI); | ||||||
| 
 | 
 | ||||||
| @ -105,13 +102,15 @@ int32_t bt_debug_app(void* p) { | |||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|     BtDebugApp* app = bt_debug_app_alloc(); |     BtDebugApp* app = bt_debug_app_alloc(); | ||||||
|  |     // Was bt active?
 | ||||||
|  |     const bool was_active = furi_hal_bt_is_active(); | ||||||
|     // Stop advertising
 |     // Stop advertising
 | ||||||
|     furi_hal_bt_stop_advertising(); |     furi_hal_bt_stop_advertising(); | ||||||
| 
 | 
 | ||||||
|     view_dispatcher_run(app->view_dispatcher); |     view_dispatcher_run(app->view_dispatcher); | ||||||
| 
 | 
 | ||||||
|     // Restart advertising
 |     // Restart advertising
 | ||||||
|     if(app->settings.enabled) { |     if(was_active) { | ||||||
|         furi_hal_bt_start_advertising(); |         furi_hal_bt_start_advertising(); | ||||||
|     } |     } | ||||||
|     bt_debug_app_free(app); |     bt_debug_app_free(app); | ||||||
|  | |||||||
| @ -4,15 +4,14 @@ | |||||||
| #include <gui/gui.h> | #include <gui/gui.h> | ||||||
| #include <gui/view.h> | #include <gui/view.h> | ||||||
| #include <gui/view_dispatcher.h> | #include <gui/view_dispatcher.h> | ||||||
|  | #include <gui/modules/submenu.h> | ||||||
|  | 
 | ||||||
| #include <dialogs/dialogs.h> | #include <dialogs/dialogs.h> | ||||||
| 
 | 
 | ||||||
| #include <gui/modules/submenu.h> |  | ||||||
| #include "views/bt_carrier_test.h" | #include "views/bt_carrier_test.h" | ||||||
| #include "views/bt_packet_test.h" | #include "views/bt_packet_test.h" | ||||||
| #include <bt/bt_settings.h> |  | ||||||
| 
 | 
 | ||||||
| typedef struct { | typedef struct { | ||||||
|     BtSettings settings; |  | ||||||
|     Gui* gui; |     Gui* gui; | ||||||
|     ViewDispatcher* view_dispatcher; |     ViewDispatcher* view_dispatcher; | ||||||
|     Submenu* submenu; |     Submenu* submenu; | ||||||
|  | |||||||
| @ -5,6 +5,7 @@ App( | |||||||
|     entry_point="display_test_app", |     entry_point="display_test_app", | ||||||
|     cdefines=["APP_DISPLAY_TEST"], |     cdefines=["APP_DISPLAY_TEST"], | ||||||
|     requires=["gui"], |     requires=["gui"], | ||||||
|  |     fap_libs=["misc"], | ||||||
|     stack_size=1 * 1024, |     stack_size=1 * 1024, | ||||||
|     order=120, |     order=120, | ||||||
|     fap_category="Debug", |     fap_category="Debug", | ||||||
|  | |||||||
| @ -91,7 +91,6 @@ static void display_test_reload_config(DisplayTest* instance) { | |||||||
|         instance->config_contrast, |         instance->config_contrast, | ||||||
|         instance->config_regulation_ratio, |         instance->config_regulation_ratio, | ||||||
|         instance->config_bias); |         instance->config_bias); | ||||||
|     gui_update(instance->gui); |  | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| static void display_config_set_bias(VariableItem* item) { | static void display_config_set_bias(VariableItem* item) { | ||||||
|  | |||||||
| @ -44,7 +44,11 @@ bool rpc_debug_app_scene_input_error_code_on_event(void* context, SceneManagerEv | |||||||
| 
 | 
 | ||||||
|     if(event.type == SceneManagerEventTypeCustom) { |     if(event.type == SceneManagerEventTypeCustom) { | ||||||
|         if(event.event == RpcDebugAppCustomEventInputErrorCode) { |         if(event.event == RpcDebugAppCustomEventInputErrorCode) { | ||||||
|             rpc_system_app_set_error_code(app->rpc, (uint32_t)atol(app->text_store)); |             char* end; | ||||||
|  |             int error_code = strtol(app->text_store, &end, 10); | ||||||
|  |             if(!*end) { | ||||||
|  |                 rpc_system_app_set_error_code(app->rpc, error_code); | ||||||
|  |             } | ||||||
|             scene_manager_previous_scene(app->scene_manager); |             scene_manager_previous_scene(app->scene_manager); | ||||||
|             consumed = true; |             consumed = true; | ||||||
|         } |         } | ||||||
|  | |||||||
| @ -5,6 +5,10 @@ | |||||||
| #include <stdint.h> | #include <stdint.h> | ||||||
| #include <stdbool.h> | #include <stdbool.h> | ||||||
| 
 | 
 | ||||||
|  | #ifdef __cplusplus | ||||||
|  | extern "C" { | ||||||
|  | #endif | ||||||
|  | 
 | ||||||
| typedef struct { | typedef struct { | ||||||
|     bool enabled; |     bool enabled; | ||||||
| } BtSettings; | } BtSettings; | ||||||
| @ -12,3 +16,7 @@ typedef struct { | |||||||
| bool bt_settings_load(BtSettings* bt_settings); | bool bt_settings_load(BtSettings* bt_settings); | ||||||
| 
 | 
 | ||||||
| bool bt_settings_save(BtSettings* bt_settings); | bool bt_settings_save(BtSettings* bt_settings); | ||||||
|  | 
 | ||||||
|  | #ifdef __cplusplus | ||||||
|  | } | ||||||
|  | #endif | ||||||
| @ -1,5 +1,5 @@ | |||||||
| entry,status,name,type,params | entry,status,name,type,params | ||||||
| Version,+,11.7,, | Version,+,11.8,, | ||||||
| Header,+,applications/services/bt/bt_service/bt.h,, | Header,+,applications/services/bt/bt_service/bt.h,, | ||||||
| Header,+,applications/services/cli/cli.h,, | Header,+,applications/services/cli/cli.h,, | ||||||
| Header,+,applications/services/cli/cli_vcp.h,, | Header,+,applications/services/cli/cli_vcp.h,, | ||||||
| @ -188,6 +188,7 @@ Header,+,lib/toolbox/stream/file_stream.h,, | |||||||
| Header,+,lib/toolbox/stream/stream.h,, | Header,+,lib/toolbox/stream/stream.h,, | ||||||
| Header,+,lib/toolbox/stream/string_stream.h,, | Header,+,lib/toolbox/stream/string_stream.h,, | ||||||
| Header,+,lib/toolbox/tar/tar_archive.h,, | Header,+,lib/toolbox/tar/tar_archive.h,, | ||||||
|  | Header,+,lib/toolbox/value_index.h,, | ||||||
| Header,+,lib/toolbox/version.h,, | Header,+,lib/toolbox/version.h,, | ||||||
| Function,-,LL_ADC_CommonDeInit,ErrorStatus,ADC_Common_TypeDef* | Function,-,LL_ADC_CommonDeInit,ErrorStatus,ADC_Common_TypeDef* | ||||||
| Function,-,LL_ADC_CommonInit,ErrorStatus,"ADC_Common_TypeDef*, LL_ADC_CommonInitTypeDef*" | Function,-,LL_ADC_CommonInit,ErrorStatus,"ADC_Common_TypeDef*, LL_ADC_CommonInitTypeDef*" | ||||||
| @ -2066,7 +2067,7 @@ Function,-,posix_memalign,int,"void**, size_t, size_t" | |||||||
| Function,-,pow,double,"double, double" | Function,-,pow,double,"double, double" | ||||||
| Function,-,pow10,double,double | Function,-,pow10,double,double | ||||||
| Function,-,pow10f,float,float | Function,-,pow10f,float,float | ||||||
| Function,-,power_enable_low_battery_level_notification,void,"Power*, _Bool" | Function,+,power_enable_low_battery_level_notification,void,"Power*, _Bool" | ||||||
| Function,+,power_get_info,void,"Power*, PowerInfo*" | Function,+,power_get_info,void,"Power*, PowerInfo*" | ||||||
| Function,+,power_get_pubsub,FuriPubSub*,Power* | Function,+,power_get_pubsub,FuriPubSub*,Power* | ||||||
| Function,+,power_is_battery_healthy,_Bool,Power* | Function,+,power_is_battery_healthy,_Bool,Power* | ||||||
| @ -2804,6 +2805,9 @@ Function,-,vTimerSetTimerNumber,void,"TimerHandle_t, UBaseType_t" | |||||||
| Function,+,validator_is_file_alloc_init,ValidatorIsFile*,"const char*, const char*, const char*" | Function,+,validator_is_file_alloc_init,ValidatorIsFile*,"const char*, const char*, const char*" | ||||||
| Function,+,validator_is_file_callback,_Bool,"const char*, FuriString*, void*" | Function,+,validator_is_file_callback,_Bool,"const char*, FuriString*, void*" | ||||||
| Function,+,validator_is_file_free,void,ValidatorIsFile* | Function,+,validator_is_file_free,void,ValidatorIsFile* | ||||||
|  | Function,+,value_index_bool,uint8_t,"const _Bool, const _Bool[], uint8_t" | ||||||
|  | Function,+,value_index_float,uint8_t,"const float, const float[], uint8_t" | ||||||
|  | Function,+,value_index_uint32,uint8_t,"const uint32_t, const uint32_t[], uint8_t" | ||||||
| Function,+,variable_item_get_context,void*,VariableItem* | Function,+,variable_item_get_context,void*,VariableItem* | ||||||
| Function,+,variable_item_get_current_value_index,uint8_t,VariableItem* | Function,+,variable_item_get_current_value_index,uint8_t,VariableItem* | ||||||
| Function,+,variable_item_list_add,VariableItem*,"VariableItemList*, const char*, uint8_t, VariableItemChangeCallback, void*" | Function,+,variable_item_list_add,VariableItem*,"VariableItemList*, const char*, uint8_t, VariableItemChangeCallback, void*" | ||||||
|  | |||||||
| 
 | 
| @ -20,6 +20,7 @@ env.Append( | |||||||
|         File("saved_struct.h"), |         File("saved_struct.h"), | ||||||
|         File("version.h"), |         File("version.h"), | ||||||
|         File("float_tools.h"), |         File("float_tools.h"), | ||||||
|  |         File("value_index.h"), | ||||||
|         File("tar/tar_archive.h"), |         File("tar/tar_archive.h"), | ||||||
|         File("stream/stream.h"), |         File("stream/stream.h"), | ||||||
|         File("stream/file_stream.h"), |         File("stream/file_stream.h"), | ||||||
|  | |||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user
	 Emily Trau
						Emily Trau