introduce homescreen

This commit is contained in:
Pavol Rusnak 2015-02-04 21:27:07 +01:00
parent d35b741f08
commit b5221ce2e9
11 changed files with 78 additions and 24 deletions

View File

@ -463,7 +463,15 @@ void fsm_msgApplySettings(ApplySettings *msg)
return; 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"); fsm_sendFailure(FailureType_Failure_SyntaxError, "No setting provided");
return; return;
} }
@ -480,6 +488,9 @@ void fsm_msgApplySettings(ApplySettings *msg)
if (msg->has_use_passphrase) { if (msg->has_use_passphrase) {
storage_setPassphraseProtection(msg->use_passphrase); storage_setPassphraseProtection(msg->use_passphrase);
} }
if (msg->has_homescreen) {
storage_setHomescreen(msg->homescreen.bytes, msg->homescreen.size);
}
storage_commit(); storage_commit();
fsm_sendSuccess("Settings applied"); fsm_sendSuccess("Settings applied");
layoutHome(); layoutHome();

View File

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

View File

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

View File

@ -42,10 +42,11 @@ const pb_field_t ClearSession_fields[1] = {
PB_LAST_FIELD 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( 1, STRING , OPTIONAL, STATIC , FIRST, ApplySettings, language, language, 0),
PB_FIELD2( 2, STRING , OPTIONAL, STATIC , OTHER, ApplySettings, label, 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( 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 PB_LAST_FIELD
}; };

View File

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

View File

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

View File

@ -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( 1, UINT32 , REQUIRED, STATIC , FIRST, Storage, version, version, 0),
PB_FIELD2( 2, MESSAGE , OPTIONAL, STATIC , OTHER, Storage, node, version, &HDNodeType_fields), PB_FIELD2( 2, MESSAGE , OPTIONAL, STATIC , OTHER, Storage, node, version, &HDNodeType_fields),
PB_FIELD2( 3, STRING , OPTIONAL, STATIC , OTHER, Storage, mnemonic, node, 0), 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( 7, STRING , OPTIONAL, STATIC , OTHER, Storage, language, pin, 0),
PB_FIELD2( 8, STRING , OPTIONAL, STATIC , OTHER, Storage, label, language, 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( 9, BOOL , OPTIONAL, STATIC , OTHER, Storage, imported, label, 0),
PB_FIELD2( 10, BYTES , OPTIONAL, STATIC , OTHER, Storage, homescreen, imported, 0),
PB_LAST_FIELD PB_LAST_FIELD
}; };
@ -32,14 +33,7 @@ STATIC_ASSERT((pb_membersize(Storage, node) < 65536), YOU_MUST_DEFINE_PB_FIELD_3
#endif #endif
#if !defined(PB_FIELD_16BIT) && !defined(PB_FIELD_32BIT) #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 #error Field descriptor for Storage.homescreen is too large. Define PB_FIELD_16BIT to fix this.
* 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)
#endif #endif

View File

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

View File

@ -220,6 +220,19 @@ void storage_setPassphraseProtection(bool passphrase_protection)
storage.passphrase_protection = 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) void get_root_node_callback(uint32_t iter, uint32_t total)
{ {
layoutProgress("Waking up", 1000 * iter / total); layoutProgress("Waking up", 1000 * iter / total);
@ -285,6 +298,11 @@ const char *storage_getLanguage(void)
return storage.has_language ? storage.language : 0; 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) bool storage_isPinCorrect(const char *pin)
{ {
return strcmp(storage.pin, pin) == 0; return strcmp(storage.pin, pin) == 0;

View File

@ -43,6 +43,9 @@ void storage_setLanguage(const char *lang);
void storage_setPassphraseProtection(bool passphrase_protection); 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); void session_cachePassphrase(const char *passphrase);
bool session_isPassphraseCached(void); bool session_isPassphraseCached(void);

@ -1 +1 @@
Subproject commit f5d880c96c72c298e0fb412bcb1abba6a4ddac02 Subproject commit 201b66a559567031f74621615884946c8bf1e837