Skip to content

Commit

Permalink
Merge pull request #184 from fishybow/patch-3
Browse files Browse the repository at this point in the history
Update settings.c: Update settings.c: Default battery mode now depend…
  • Loading branch information
solosky authored Dec 29, 2023
2 parents cf1c4a2 + 4a52f5a commit 25574a1
Show file tree
Hide file tree
Showing 2 changed files with 191 additions and 4 deletions.
184 changes: 182 additions & 2 deletions docs/en/05+1-ble_protocol.md
Original file line number Diff line number Diff line change
Expand Up @@ -248,7 +248,7 @@ TODO Supplement the error code in detail. .
| cmd | uint8 | 1 | fixed 0x12 |
| status | uint8 | 1 | Status code, see status code description |
| chunk | uint16 | 2 | 0 |
| file id | uint8 | 1 | File ID, used for subsequent read and write requests |
| file id | uint8 | 1 | file id, used for subsequent read and write requests |

## 0x13: Close file

Expand All @@ -257,4 +257,184 @@ TODO Supplement the error code in detail. .
| Field name | Type | Length (bytes) | Description |
| ---- | ----- |---- | ---- |
| cmd | uint8 | 1 | 0x13 |
| sta
| status | uint8 | 1 | 0 |
| chunk | uint16 | 2 | 0 |
| file id | uint8 | 1 | file id |


2. Service response

| Field name | Type | Length (bytes) | Description |
| ---- | ----- |---- | ---- |
| cmd | uint8 | 1 | 0x13 |
| status | uint8 | 1 | Status code, see status code description |
| chunk | uint16 | 2 | 0 |
| file id | uint8 | 1 | file id, used for subsequent read and write requests |


## 0x14: Read file

1. The client sends a request

Only support sequential reading.

| Field name | Type | Length (bytes) | Description |
| ---- | ----- |---- | ---- |
| cmd | uint8 | 1 | 0x14 |
| status | uint8 | 1 | 0 |
| chunk | uint16 | 2 | 0 |
| file id | uint8 | 1| file id |


2. The server responds to the request

| Field name | Type | Length (bytes) | Description |
| ---- | ----- |---- | ---- |
| cmd | uint8 | 1 | 0x14 |
| status | uint8 | 1 |Status code, see status code description |
| chunk | uint16 | 2 | Enable chunk transfer |
| data | byte | N | File data |


## 0x15 Write to file

1. The client sends a request

| Field name | Type | Length (bytes) | Description |
| ---- | ----- |---- | ---- |
| cmd | uint8 | 1 | 0x15 |
| status | uint8 | 1 | 0 |
| chunk | uint16 | 2 | Enable chunk transfer |
| file id | uint8 | 1 | file id |
| data | byte | N | File data, max length = MTU - 4 |



2. The server responds to the request

| Field name | Type | Length (bytes) | Description |
| ---- | ----- |---- | ---- |
| cmd | uint8 | 1 | 0x15 |
| status | uint8 | 1 |Status code, see status code description |
| chunk | uint16 | 2 | Same as Request |


## 0x16:Read folder

1. The client sends a request

| Field name | Type | Length (bytes) | Description |
| ---- | ----- |---- | ---- |
| cmd | uint8 | 1 | 0x16 |
| status | uint8 | 1 | 0 |
| chunk | uint16 | 2 | 0 |
| path length | uint16 | 2 | Path length under bytes |
| path | byte | N | Path string bytes |


2. The server responds to the request

| Field name | Type | Length (bytes) | Description |
| ---- | ----- |---- | ---- |
| cmd | uint8 | 1 | 0x16 |
| status | uint8 | 1 |Status code, see status code description |
| chunk | uint16 | 2 | Enable chunk transfer |
| file N name length| uint16 | 2 | File name bytes length|
| file N name | byte | N| File name bytes |
| file N size | uint32 | 4 |File size |
| file N type | uint8 | 1 | File Type: 0 => File, 1 => Folder |
| file N meta length | uint8 | 1 | File meta data length, 64 max|
| file N meta | byte | N | File meta data |

## 0x17 Create folder

1. The client sends a request

| Field name | Type | Length (bytes) | Description |
| ---- | ----- |---- | ---- |
| cmd | uint8 | 1 | 0x17 |
| status | uint8 | 1 | 0 |
| chunk | uint16 | 2 | 0 |
| path length | uint16 | 2 | Path length under bytes |
| path | byte | N | Path string bytes |


2. The server responds to the request

| Field name | Type | Length (bytes) | Description |
| ---- | ----- |---- | ---- |
| cmd | uint8 | 1 | 0x17 |
| status | uint8 | 1 |Status code, see status code description |
| chunk | uint16 | 2 | 0 |



## 0x18 Delete file or folder

1. The client sends a request

| Field name | Type | Length (bytes) | Description |
| ---- | ----- |---- | ---- |
| cmd | uint8 | 1 | 0x18 |
| status | uint8 | 1 | 0 |
| chunk | uint16 | 2 | 0 |
| path length | uint16 | 2 | Path length under bytes |
| path | byte | N | Path string bytes |


2. The server responds to the request

| Field name | Type | Length (bytes) | Description |
| ---- | ----- |---- | ---- |
| cmd | uint8 | 1 | 0x18 |
| status | uint8 | 1 |Status code, see status code description |
| chunk | uint16 | 2 | 0 |


## 0x19 Rename file or folder

1. The client sends a request

| Field name | Type | Length (bytes) | Description |
| ---- | ----- |---- | ---- |
| cmd | uint8 | 1 | 0x18 |
| status | uint8 | 1 | 0 |
| chunk | uint16 | 2 | Enable chunk transfer |
| old path length | uint16 | 2 | Path length under bytes |
| old path | byte | N | Path string bytes |
| new path length | uint16 | 2 | Path length under bytes |
| new path | byte | N | Path string bytes |

If data length is larger than MTU, use chunk transfer.


2. The server responds to the request

| Field name | Type | Length (bytes) | Description |
| ---- | ----- |---- | ---- |
| cmd | uint8 | 1 | 0x18 |
| status | uint8 | 1 |Status code, see status code description |
| chunk | uint16 | 2 | 0 |


## 0x1A Update file meta

1. The client sends a request

| Field name | Type | Length (bytes) | Description |
| ---- | ----- |---- | ---- |
| cmd | uint8 | 1 | 0x1a |
| status | uint8 | 1 | 0 |
| chunk | uint16 | 2 | 0 |
| path length | uint16 | 2 | Path length under bytes |
| path | byte | N | Path string bytes |
| meta data | byte | N | File Meta Data |

2. The server responds to the request

| Field name | Type | Length (bytes) | Description |
| ---- | ----- |---- | ---- |
| cmd | uint8 | 1 | 0x1a |
| status | uint8 | 1 |Status code, see status code description |
| chunk | uint16 | 2 | 0 |

11 changes: 9 additions & 2 deletions fw/application/src/mod/settings.c
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,20 @@

#define SETTINGS_FILE_NAME "/settings.bin"

#ifdef OLED_SCREEN
// Though OLED doesn't necessarily imply rechargeable battery, it's usually the case.
#define DEFAULT_BAT_MODE 1
#else // !OLED_SCREEN
#define DEFAULT_BAT_MODE 0
#endif // OLED_SCREEN

const settings_data_t def_settings_data = {.backlight = 0,
.oled_contrast = 40,
.auto_gen_amiibo = 0,
.auto_gen_amiibolink = 0,
.sleep_timeout_sec = 30,
.skip_driver_select = 0,
.bat_mode = 0,
.bat_mode = DEFAULT_BAT_MODE,
.amiibo_link_ver = BLE_AMIIBOLINK_VER_V1,
.language = LANGUAGE_EN_US,
.hibernate_enabled = false,
Expand Down Expand Up @@ -132,4 +139,4 @@ int32_t settings_reset() {
memcpy(&m_settings_data, &def_settings_data, sizeof(settings_data_t));
vfs_driver_t *p_driver = vfs_get_default_driver();
return p_driver->remove_file(SETTINGS_FILE_NAME);
}
}

0 comments on commit 25574a1

Please sign in to comment.