mirror of
https://github.com/Next-Flip/Momentum-Firmware.git
synced 2026-07-12 23:48:10 -07:00
name changer?
This commit is contained in:
@@ -86,30 +86,77 @@ typedef struct {
|
||||
char name[FURI_HAL_VERSION_ARRAY_NAME_LENGTH]; /** \0 terminated name */
|
||||
char device_name[FURI_HAL_VERSION_DEVICE_NAME_LENGTH]; /** device name for special needs */
|
||||
uint8_t ble_mac[6];
|
||||
const char* cname;
|
||||
char cname2[FURI_HAL_VERSION_ARRAY_NAME_LENGTH];
|
||||
} FuriHalVersion;
|
||||
|
||||
static FuriHalVersion furi_hal_version = {0};
|
||||
|
||||
static void furi_hal_version_set_name(const char* name) {
|
||||
if(name != NULL) {
|
||||
strlcpy(furi_hal_version.name, name, FURI_HAL_VERSION_ARRAY_NAME_LENGTH);
|
||||
void furi_hal_version_set_custom_name(const char* name) {
|
||||
if((name != NULL) && ((strlen(name) >= 1) && (strlen(name) <= 8))) {
|
||||
strlcpy(furi_hal_version.cname2, name, FURI_HAL_VERSION_ARRAY_NAME_LENGTH);
|
||||
|
||||
snprintf(
|
||||
furi_hal_version.device_name,
|
||||
FURI_HAL_VERSION_DEVICE_NAME_LENGTH,
|
||||
"xFlipper %s",
|
||||
furi_hal_version.name);
|
||||
furi_hal_version.cname2);
|
||||
|
||||
furi_hal_version.device_name[0] = AD_TYPE_COMPLETE_LOCAL_NAME;
|
||||
} else {
|
||||
snprintf(furi_hal_version.device_name, FURI_HAL_VERSION_DEVICE_NAME_LENGTH, "xFlipper");
|
||||
strcpy(furi_hal_version.cname2, "");
|
||||
}
|
||||
}
|
||||
|
||||
static void furi_hal_version_set_name(const char* name) {
|
||||
char tmpCname[FURI_HAL_VERSION_ARRAY_NAME_LENGTH];
|
||||
|
||||
strlcpy(tmpCname, furi_hal_version_get_name_ptr(), FURI_HAL_VERSION_ARRAY_NAME_LENGTH);
|
||||
|
||||
if(!((strlen(tmpCname) >= 1) && (strlen(tmpCname) <= 8))) {
|
||||
strcpy(tmpCname, "");
|
||||
}
|
||||
|
||||
if(name != NULL) {
|
||||
if(strcmp(tmpCname, "") != 0) {
|
||||
strlcpy(furi_hal_version.name, tmpCname, FURI_HAL_VERSION_ARRAY_NAME_LENGTH);
|
||||
|
||||
snprintf(
|
||||
furi_hal_version.device_name,
|
||||
FURI_HAL_VERSION_DEVICE_NAME_LENGTH,
|
||||
"xFlipper %s",
|
||||
furi_hal_version.name);
|
||||
} else {
|
||||
strlcpy(furi_hal_version.name, name, FURI_HAL_VERSION_ARRAY_NAME_LENGTH);
|
||||
|
||||
snprintf(
|
||||
furi_hal_version.device_name,
|
||||
FURI_HAL_VERSION_DEVICE_NAME_LENGTH,
|
||||
"xFlipper %s",
|
||||
furi_hal_version.name);
|
||||
}
|
||||
} else {
|
||||
if(strcmp(tmpCname, "") != 0) {
|
||||
strlcpy(furi_hal_version.name, tmpCname, FURI_HAL_VERSION_ARRAY_NAME_LENGTH);
|
||||
|
||||
snprintf(
|
||||
furi_hal_version.device_name,
|
||||
FURI_HAL_VERSION_DEVICE_NAME_LENGTH,
|
||||
"xFlipper %s",
|
||||
furi_hal_version.name);
|
||||
} else {
|
||||
snprintf(
|
||||
furi_hal_version.device_name,
|
||||
FURI_HAL_VERSION_DEVICE_NAME_LENGTH,
|
||||
"xFlipper Dev");
|
||||
}
|
||||
}
|
||||
|
||||
furi_hal_version.device_name[0] = AD_TYPE_COMPLETE_LOCAL_NAME;
|
||||
|
||||
// BLE Mac address
|
||||
uint32_t udn = LL_FLASH_GetUDN();
|
||||
if(version_get_custom_name(NULL) != NULL) {
|
||||
udn = *((uint32_t*)version_get_custom_name(NULL));
|
||||
}
|
||||
|
||||
udn = *((uint32_t*)name);
|
||||
uint32_t company_id = LL_FLASH_GetSTCompanyID();
|
||||
uint32_t device_id = LL_FLASH_GetDeviceID();
|
||||
furi_hal_version.ble_mac[0] = (uint8_t)(udn & 0x000000FF);
|
||||
@@ -133,8 +180,10 @@ static void furi_hal_version_load_otp_v0() {
|
||||
furi_hal_version.board_body = otp->board_body;
|
||||
furi_hal_version.board_connect = otp->board_connect;
|
||||
|
||||
if(version_get_custom_name(NULL) != NULL) {
|
||||
furi_hal_version_set_name(version_get_custom_name(NULL));
|
||||
furi_hal_version.cname = furi_hal_version_get_name_ptr();
|
||||
if(furi_hal_version.cname != NULL && strlen(furi_hal_version.cname) >= 1 &&
|
||||
strlen(furi_hal_version.cname) <= 8) {
|
||||
furi_hal_version_set_name(furi_hal_version.cname);
|
||||
} else {
|
||||
furi_hal_version_set_name(otp->name);
|
||||
}
|
||||
@@ -151,8 +200,10 @@ static void furi_hal_version_load_otp_v1() {
|
||||
furi_hal_version.board_color = otp->board_color;
|
||||
furi_hal_version.board_region = otp->board_region;
|
||||
|
||||
if(version_get_custom_name(NULL) != NULL) {
|
||||
furi_hal_version_set_name(version_get_custom_name(NULL));
|
||||
furi_hal_version.cname = furi_hal_version_get_name_ptr();
|
||||
if(furi_hal_version.cname != NULL && strlen(furi_hal_version.cname) >= 1 &&
|
||||
strlen(furi_hal_version.cname) <= 8) {
|
||||
furi_hal_version_set_name(furi_hal_version.cname);
|
||||
} else {
|
||||
furi_hal_version_set_name(otp->name);
|
||||
}
|
||||
@@ -175,8 +226,10 @@ static void furi_hal_version_load_otp_v2() {
|
||||
if(otp->board_color != 0xFF) {
|
||||
furi_hal_version.board_color = otp->board_color;
|
||||
furi_hal_version.board_region = otp->board_region;
|
||||
if(version_get_custom_name(NULL) != NULL) {
|
||||
furi_hal_version_set_name(version_get_custom_name(NULL));
|
||||
furi_hal_version.cname = furi_hal_version_get_name_ptr();
|
||||
if(furi_hal_version.cname != NULL && strlen(furi_hal_version.cname) >= 1 &&
|
||||
strlen(furi_hal_version.cname) <= 8) {
|
||||
furi_hal_version_set_name(furi_hal_version.cname);
|
||||
} else {
|
||||
furi_hal_version_set_name(otp->name);
|
||||
}
|
||||
@@ -265,6 +318,7 @@ uint8_t furi_hal_version_get_hw_connect() {
|
||||
}
|
||||
|
||||
FuriHalVersionRegion furi_hal_version_get_hw_region() {
|
||||
// return furi_hal_version.board_region;
|
||||
return FuriHalVersionRegionUnknown;
|
||||
}
|
||||
|
||||
@@ -293,6 +347,20 @@ uint32_t furi_hal_version_get_hw_timestamp() {
|
||||
}
|
||||
|
||||
const char* furi_hal_version_get_name_ptr() {
|
||||
if((strcmp(furi_hal_version.cname2, "") != 0) &&
|
||||
((strlen(furi_hal_version.cname2) >= 1) && (strlen(furi_hal_version.cname2) <= 8))) {
|
||||
return furi_hal_version.cname2;
|
||||
}
|
||||
|
||||
furi_hal_version.cname = version_get_custom_name(NULL);
|
||||
|
||||
if((furi_hal_version.cname != NULL) &&
|
||||
((strlen(furi_hal_version.cname) >= 1) && (strlen(furi_hal_version.cname) <= 8))) {
|
||||
strlcpy(
|
||||
furi_hal_version.cname2, furi_hal_version.cname, FURI_HAL_VERSION_ARRAY_NAME_LENGTH);
|
||||
return furi_hal_version.cname2;
|
||||
}
|
||||
|
||||
return *furi_hal_version.name == 0x00 ? NULL : furi_hal_version.name;
|
||||
}
|
||||
|
||||
@@ -317,8 +385,10 @@ size_t furi_hal_version_uid_size() {
|
||||
}
|
||||
|
||||
const uint8_t* furi_hal_version_uid() {
|
||||
if(version_get_custom_name(NULL) != NULL) {
|
||||
return (const uint8_t*)&(*((uint32_t*)version_get_custom_name(NULL)));
|
||||
furi_hal_version.cname = furi_hal_version_get_name_ptr();
|
||||
if(furi_hal_version.cname != NULL && strlen(furi_hal_version.cname) >= 1 &&
|
||||
strlen(furi_hal_version.cname) <= 8) {
|
||||
return (const uint8_t*)&(*((uint32_t*)furi_hal_version_get_name_ptr()));
|
||||
}
|
||||
return (const uint8_t*)UID64_BASE;
|
||||
}
|
||||
|
||||
@@ -51,6 +51,14 @@ typedef enum {
|
||||
FuriHalVersionDisplayMgg = 0x02,
|
||||
} FuriHalVersionDisplay;
|
||||
|
||||
/** Set Flipper Name
|
||||
*/
|
||||
//void furi_hal_version_set_name(const char* name);
|
||||
|
||||
/** Set Custom Name
|
||||
*/
|
||||
void furi_hal_version_set_custom_name(const char* name);
|
||||
|
||||
/** Init flipper version
|
||||
*/
|
||||
void furi_hal_version_init();
|
||||
|
||||
Reference in New Issue
Block a user