Skip to content

Commit

Permalink
Allow Scripts to perform an SD card format
Browse files Browse the repository at this point in the history
  • Loading branch information
magicrub committed Mar 19, 2024
1 parent 16b7838 commit 8cb1ec5
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 0 deletions.
6 changes: 6 additions & 0 deletions libraries/AP_Filesystem/AP_Filesystem.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -311,6 +311,12 @@ AP_Filesystem_Backend::FormatStatus AP_Filesystem::get_format_status(void) const
#endif
}

// get_singleton for scripting
AP_Filesystem *AP_Filesystem::get_singleton(void)
{
return &fs;
}

namespace AP
{
AP_Filesystem &FS()
Expand Down
3 changes: 3 additions & 0 deletions libraries/AP_Filesystem/AP_Filesystem.h
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,9 @@ class AP_Filesystem {
load a full file. Use delete to free the data
*/
FileData *load_file(const char *filename);

// get_singleton for scripting
static AP_Filesystem *get_singleton(void);

private:
struct Backend {
Expand Down
2 changes: 2 additions & 0 deletions libraries/AP_HAL_ChibiOS/hwdef/CubeOrangePlus/hwdef.dat
Original file line number Diff line number Diff line change
Expand Up @@ -97,3 +97,5 @@ CHECK_IMU2_PRESENT $CHECK_ICM42688_EXT || $CHECK_ICM45686_EXT
BOARD_VALIDATE $CHECK_IMU0_PRESENT $CHECK_IMU1_PRESENT $CHECK_IMU2_PRESENT $CHECK_BARO0_PRESENT $CHECK_BARO1_PRESENT

define HAL_SPI_SCK_SAVE_RESTORE TRUE

ROMFS scripts/zeroize.lua scripts/zeroize.lua
14 changes: 14 additions & 0 deletions libraries/AP_Scripting/docs/docs.lua
Original file line number Diff line number Diff line change
Expand Up @@ -2718,3 +2718,17 @@ function dirlist(directoryname) end
--desc
--@param filename
function remove(filename) end


-- desc
---@class fs
fs = {}

-- Format the SD card. This is a async operation, use get_format_status to get the status of the format
---@return boolean
function fs:format() end

-- Get the current status of a format. 0=NOT_STARTED, 1=PENDING, 2=IN_PROGRESS, 3=SUCCESS, 4=FAILURE
---@return number
function fs:get_format_status() end

7 changes: 7 additions & 0 deletions libraries/AP_Scripting/generator/description/bindings.desc
Original file line number Diff line number Diff line change
Expand Up @@ -710,3 +710,10 @@ userdata uint32_t manual tofloat uint32_t_tofloat 0

global manual dirlist lua_dirlist 1
global manual remove lua_removefile 1

include AP_Filesystem/AP_Filesystem.h
include AP_Filesystem/AP_Filesystem_config.h
singleton AP_Filesystem rename fs
singleton AP_Filesystem method format boolean
singleton AP_Filesystem method get_format_status uint8_t'skip_check

0 comments on commit 8cb1ec5

Please sign in to comment.