introduce homescreen

pull/25/head
Pavol Rusnak 9 years ago
parent d35b741f08
commit b5221ce2e9

@ -463,7 +463,15 @@ void fsm_msgApplySettings(ApplySettings *msg)
return;
}
}
if (!msg->has_label && !msg->has_language && !msg->has_use_passphrase) {
if (msg->has_homescreen) {
layoutDialogSwipe(DIALOG_ICON_QUESTION, "Cancel", "Confirm", NULL, "Do you really want to", "change the home", "screen ?", NULL, NULL, NULL);
if (!protectButton(ButtonRequestType_ButtonRequest_ProtectCall, false)) {
fsm_sendFailure(FailureType_Failure_ActionCancelled, "Apply settings cancelled");
layoutHome();
return;
}
}
if (!msg->has_label && !msg->has_language && !msg->has_use_passphrase && !msg->has_homescreen) {
fsm_sendFailure(FailureType_Failure_SyntaxError, "No setting provided");
return;
}
@ -480,6 +488,9 @@ void fsm_msgApplySettings(ApplySettings *msg)
if (msg->has_use_passphrase) {
storage_setPassphraseProtection(msg->use_passphrase);
}
if (msg->has_homescreen) {
storage_setHomescreen(msg->homescreen.bytes, msg->homescreen.size);
}
storage_commit();
fsm_sendSuccess("Settings applied");
layoutHome();

@ -57,11 +57,20 @@ void layoutHome(void)
oledSwipeLeft();
}
const char *label = storage_getLabel();
if (label && strlen(label) > 0) {
oledDrawBitmap(44, 4, &bmp_logo48);
oledDrawStringCenter(OLED_HEIGHT - 8, label);
const uint8_t *homescreen = storage_getHomescreen();
if (homescreen) {
BITMAP b;
b.width = 128;
b.height = 64;
b.data = homescreen;
oledDrawBitmap(0, 0, &b);
} else {
oledDrawBitmap(40, 0, &bmp_logo64);
if (label && strlen(label) > 0) {
oledDrawBitmap(44, 4, &bmp_logo48);
oledDrawStringCenter(OLED_HEIGHT - 8, label);
} else {
oledDrawBitmap(40, 0, &bmp_logo64);
}
}
oledRefresh();
}

@ -8,6 +8,7 @@ Features.bootloader_hash max_size:32
ApplySettings.language max_size:17
ApplySettings.label max_size:33
ApplySettings.homescreen max_size:1024
Ping.message max_size:256

@ -42,10 +42,11 @@ const pb_field_t ClearSession_fields[1] = {
PB_LAST_FIELD
};
const pb_field_t ApplySettings_fields[4] = {
const pb_field_t ApplySettings_fields[5] = {
PB_FIELD2( 1, STRING , OPTIONAL, STATIC , FIRST, ApplySettings, language, language, 0),
PB_FIELD2( 2, STRING , OPTIONAL, STATIC , OTHER, ApplySettings, label, language, 0),
PB_FIELD2( 3, BOOL , OPTIONAL, STATIC , OTHER, ApplySettings, use_passphrase, label, 0),
PB_FIELD2( 4, BYTES , OPTIONAL, STATIC , OTHER, ApplySettings, homescreen, use_passphrase, 0),
PB_LAST_FIELD
};

@ -114,6 +114,11 @@ typedef struct _Address {
char address[36];
} Address;
typedef struct {
size_t size;
uint8_t bytes[1024];
} ApplySettings_homescreen_t;
typedef struct _ApplySettings {
bool has_language;
char language[17];
@ -121,6 +126,8 @@ typedef struct _ApplySettings {
char label[33];
bool has_use_passphrase;
bool use_passphrase;
bool has_homescreen;
ApplySettings_homescreen_t homescreen;
} ApplySettings;
typedef struct _ButtonRequest {
@ -584,7 +591,7 @@ extern const char SimpleSignTx_coin_name_default[17];
#define Initialize_init_default {0}
#define Features_init_default {false, "", false, 0, false, 0, false, 0, false, 0, false, "", false, 0, false, 0, false, "", false, "", 0, {CoinType_init_default, CoinType_init_default, CoinType_init_default, CoinType_init_default, CoinType_init_default}, false, 0, false, {0, {0}}, false, {0, {0}}, false, 0}
#define ClearSession_init_default {0}
#define ApplySettings_init_default {false, "", false, "", false, 0}
#define ApplySettings_init_default {false, "", false, "", false, 0, false, {0, {0}}}
#define ChangePin_init_default {false, 0}
#define Ping_init_default {false, "", false, 0, false, 0, false, 0}
#define Success_init_default {false, ""}
@ -635,7 +642,7 @@ extern const char SimpleSignTx_coin_name_default[17];
#define Initialize_init_zero {0}
#define Features_init_zero {false, "", false, 0, false, 0, false, 0, false, 0, false, "", false, 0, false, 0, false, "", false, "", 0, {CoinType_init_zero, CoinType_init_zero, CoinType_init_zero, CoinType_init_zero, CoinType_init_zero}, false, 0, false, {0, {0}}, false, {0, {0}}, false, 0}
#define ClearSession_init_zero {0}
#define ApplySettings_init_zero {false, "", false, "", false, 0}
#define ApplySettings_init_zero {false, "", false, "", false, 0, false, {0, {0}}}
#define ChangePin_init_zero {false, 0}
#define Ping_init_zero {false, "", false, 0, false, 0, false, 0}
#define Success_init_zero {false, ""}
@ -689,6 +696,7 @@ extern const char SimpleSignTx_coin_name_default[17];
#define ApplySettings_language_tag 1
#define ApplySettings_label_tag 2
#define ApplySettings_use_passphrase_tag 3
#define ApplySettings_homescreen_tag 4
#define ButtonRequest_code_tag 1
#define ButtonRequest_data_tag 2
#define ChangePin_remove_tag 1
@ -811,7 +819,7 @@ extern const char SimpleSignTx_coin_name_default[17];
extern const pb_field_t Initialize_fields[1];
extern const pb_field_t Features_fields[16];
extern const pb_field_t ClearSession_fields[1];
extern const pb_field_t ApplySettings_fields[4];
extern const pb_field_t ApplySettings_fields[5];
extern const pb_field_t ChangePin_fields[2];
extern const pb_field_t Ping_fields[5];
extern const pb_field_t Success_fields[2];
@ -864,7 +872,7 @@ extern const pb_field_t DebugLinkLog_fields[4];
#define Initialize_size 0
#define Features_size (230 + 5*CoinType_size)
#define ClearSession_size 0
#define ApplySettings_size 56
#define ApplySettings_size 1083
#define ChangePin_size 2
#define Ping_size 265
#define Success_size 259

@ -2,3 +2,4 @@ Storage.mnemonic max_size:241
Storage.pin max_size:10
Storage.language max_size:17
Storage.label max_size:33
Storage.homescreen max_size:1024

@ -5,7 +5,7 @@
const pb_field_t Storage_fields[10] = {
const pb_field_t Storage_fields[11] = {
PB_FIELD2( 1, UINT32 , REQUIRED, STATIC , FIRST, Storage, version, version, 0),
PB_FIELD2( 2, MESSAGE , OPTIONAL, STATIC , OTHER, Storage, node, version, &HDNodeType_fields),
PB_FIELD2( 3, STRING , OPTIONAL, STATIC , OTHER, Storage, mnemonic, node, 0),
@ -15,6 +15,7 @@ const pb_field_t Storage_fields[10] = {
PB_FIELD2( 7, STRING , OPTIONAL, STATIC , OTHER, Storage, language, pin, 0),
PB_FIELD2( 8, STRING , OPTIONAL, STATIC , OTHER, Storage, label, language, 0),
PB_FIELD2( 9, BOOL , OPTIONAL, STATIC , OTHER, Storage, imported, label, 0),
PB_FIELD2( 10, BYTES , OPTIONAL, STATIC , OTHER, Storage, homescreen, imported, 0),
PB_LAST_FIELD
};
@ -32,14 +33,7 @@ STATIC_ASSERT((pb_membersize(Storage, node) < 65536), YOU_MUST_DEFINE_PB_FIELD_3
#endif
#if !defined(PB_FIELD_16BIT) && !defined(PB_FIELD_32BIT)
/* If you get an error here, it means that you need to define PB_FIELD_16BIT
* compile-time option. You can do that in pb.h or on compiler command line.
*
* The reason you need to do this is that some of your messages contain tag
* numbers or field sizes that are larger than what can fit in the default
* 8 bit descriptors.
*/
STATIC_ASSERT((pb_membersize(Storage, node) < 256), YOU_MUST_DEFINE_PB_FIELD_16BIT_FOR_MESSAGES_Storage)
#error Field descriptor for Storage.homescreen is too large. Define PB_FIELD_16BIT to fix this.
#endif

@ -12,6 +12,11 @@ extern "C" {
/* Enum definitions */
/* Struct definitions */
typedef struct {
size_t size;
uint8_t bytes[1024];
} Storage_homescreen_t;
typedef struct _Storage {
uint32_t version;
bool has_node;
@ -30,13 +35,15 @@ typedef struct _Storage {
char label[33];
bool has_imported;
bool imported;
bool has_homescreen;
Storage_homescreen_t homescreen;
} Storage;
/* Default values for struct fields */
/* Initializer values for message structs */
#define Storage_init_default {0, false, HDNodeType_init_default, false, "", false, 0, false, 0, false, "", false, "", false, "", false, 0}
#define Storage_init_zero {0, false, HDNodeType_init_zero, false, "", false, 0, false, 0, false, "", false, "", false, "", false, 0}
#define Storage_init_default {0, false, HDNodeType_init_default, false, "", false, 0, false, 0, false, "", false, "", false, "", false, 0, false, {0, {0}}}
#define Storage_init_zero {0, false, HDNodeType_init_zero, false, "", false, 0, false, 0, false, "", false, "", false, "", false, 0, false, {0, {0}}}
/* Field tags (for use in manual encoding/decoding) */
#define Storage_version_tag 1
@ -48,12 +55,13 @@ typedef struct _Storage {
#define Storage_language_tag 7
#define Storage_label_tag 8
#define Storage_imported_tag 9
#define Storage_homescreen_tag 10
/* Struct field encoding specification for nanopb */
extern const pb_field_t Storage_fields[10];
extern const pb_field_t Storage_fields[11];
/* Maximum encoded size of messages (where known) */
#define Storage_size (332 + HDNodeType_size)
#define Storage_size (1359 + HDNodeType_size)
#ifdef __cplusplus
} /* extern "C" */

@ -220,6 +220,19 @@ void storage_setPassphraseProtection(bool passphrase_protection)
storage.passphrase_protection = passphrase_protection;
}
void storage_setHomescreen(const uint8_t *data, uint32_t size)
{
if (data && size == 1024) {
storage.has_homescreen = true;
memcpy(storage.homescreen.bytes, data, size);
storage.homescreen.size = size;
} else {
storage.has_homescreen = false;
memset(storage.homescreen.bytes, 0, sizeof(storage.homescreen.bytes));
storage.homescreen.size = 0;
}
}
void get_root_node_callback(uint32_t iter, uint32_t total)
{
layoutProgress("Waking up", 1000 * iter / total);
@ -285,6 +298,11 @@ const char *storage_getLanguage(void)
return storage.has_language ? storage.language : 0;
}
const uint8_t *storage_getHomescreen(void)
{
return (storage.has_homescreen && storage.homescreen.size == 1024) ? storage.homescreen.bytes : 0;
}
bool storage_isPinCorrect(const char *pin)
{
return strcmp(storage.pin, pin) == 0;

@ -43,6 +43,9 @@ void storage_setLanguage(const char *lang);
void storage_setPassphraseProtection(bool passphrase_protection);
const uint8_t *storage_getHomescreen(void);
void storage_setHomescreen(const uint8_t *data, uint32_t size);
void session_cachePassphrase(const char *passphrase);
bool session_isPassphraseCached(void);

@ -1 +1 @@
Subproject commit f5d880c96c72c298e0fb412bcb1abba6a4ddac02
Subproject commit 201b66a559567031f74621615884946c8bf1e837
Loading…
Cancel
Save