legacy: style

poc/dualbuttonime
Tomas Susanka 5 years ago
parent 8931ac1ef1
commit 3054a56288

@ -828,20 +828,17 @@ bool session_getState(const uint8_t *salt, uint8_t *state,
bool session_isUnlocked(void) { return sectrue == storage_is_unlocked(); } bool session_isUnlocked(void) { return sectrue == storage_is_unlocked(); }
bool session_isUseOnDeviceTextInputCached(void) bool session_isUseOnDeviceTextInputCached(void) {
{ return sectrue == sessionUseOnDeviceTextInputCached;
return sectrue == sessionUseOnDeviceTextInputCached;
} }
bool session_isUseOnDeviceTextInput(void) bool session_isUseOnDeviceTextInput(void) {
{ return sectrue == sessionUseOnDeviceTextInput;
return sectrue == sessionUseOnDeviceTextInput;
} }
void session_setUseOnDeviceTextInput(bool use) void session_setUseOnDeviceTextInput(bool use) {
{ sessionUseOnDeviceTextInputCached = sectrue;
sessionUseOnDeviceTextInputCached = sectrue; sessionUseOnDeviceTextInput = use ? sectrue : secfalse;
sessionUseOnDeviceTextInput = use ? sectrue : secfalse;
} }
bool config_isInitialized(void) { bool config_isInitialized(void) {

@ -243,109 +243,117 @@ void layoutProgressSwipe(const char *desc, int permil) {
layoutProgress(desc, permil); layoutProgress(desc, permil);
} }
void layoutScrollInput(const char *text, int text_width, int num_total, int num_screen, int current_index, const char entries[], int horizontal_padding, int num_group, const int groups[], int num_skip_in_groups, bool draw_caret) void layoutScrollInput(const char *text, int text_width, int num_total,
{ int num_screen, int current_index, const char entries[],
layoutLast = layoutScrollInput; int horizontal_padding, int num_group,
const int groups[], int num_skip_in_groups,
oledClear(); bool draw_caret) {
layoutLast = layoutScrollInput;
if (num_screen % 2 > 0)
++num_screen; oledClear();
if (num_total <= 0 || num_screen <= 0 || current_index < 0 || current_index >= num_total || groups[num_group - 1] > num_total) if (num_screen % 2 > 0) ++num_screen;
return;
if (num_total <= 0 || num_screen <= 0 || current_index < 0 ||
const int CenterX = OLED_WIDTH / 2; current_index >= num_total || groups[num_group - 1] > num_total)
const int Y = 2; return;
int width = OLED_WIDTH - horizontal_padding * 2; const int CenterX = OLED_WIDTH / 2;
int gap = width / (num_screen - 1); const int Y = 2;
int t = (num_screen - 1) / 2;
char letter[2]; int width = OLED_WIDTH - horizontal_padding * 2;
letter[1] = 0; int gap = width / (num_screen - 1);
for (int i = 0; i < num_screen && i < num_total; ++i) int t = (num_screen - 1) / 2;
{ char letter[2];
int x = CenterX - gap * (t - i); letter[1] = 0;
int n = (current_index + i - t + num_total) % num_total; for (int i = 0; i < num_screen && i < num_total; ++i) {
letter[0] = entries[n]; int x = CenterX - gap * (t - i);
oledDrawStringCenter(x, Y, letter, 1); int n = (current_index + i - t + num_total) % num_total;
} letter[0] = entries[n];
oledDrawStringCenter(x, Y, letter, 1);
int halfgap = gap / 2; }
oledInvert(CenterX - halfgap, Y - 2, CenterX + halfgap - 1, Y + FONT_HEIGHT + 1);
int halfgap = gap / 2;
const int LineY = Y + FONT_HEIGHT * 2 - 2; oledInvert(CenterX - halfgap, Y - 2, CenterX + halfgap - 1,
Y + FONT_HEIGHT + 1);
width--;
const int LineY = Y + FONT_HEIGHT * 2 - 2;
oledPartialHLine(horizontal_padding, OLED_WIDTH - horizontal_padding, LineY);
for (int i = 0; i < num_group; ++i) width--;
oledPartialVLine(horizontal_padding + width * groups[i] / num_total, LineY - 1, LineY);
oledPartialHLine(horizontal_padding, OLED_WIDTH - horizontal_padding, LineY);
int x = horizontal_padding + width * current_index / num_total; for (int i = 0; i < num_group; ++i)
oledPartialHLine(x, x + 1, LineY - 1); oledPartialVLine(horizontal_padding + width * groups[i] / num_total,
oledPartialHLine(x - 1, x + 2, LineY - 2); LineY - 1, LineY);
oledPartialHLine(x - 2, x + 3, LineY - 3);
int x = horizontal_padding + width * current_index / num_total;
char groupinfo[] = "?-?"; oledPartialHLine(x, x + 1, LineY - 1);
int group; oledPartialHLine(x - 1, x + 2, LineY - 2);
for (group = 0; group < num_group - 1; ++group) oledPartialHLine(x - 2, x + 3, LineY - 3);
{
if (current_index >= groups[group] && current_index < groups[group + 1]) char groupinfo[] = "?-?";
break; int group;
} for (group = 0; group < num_group - 1; ++group) {
groupinfo[0] = entries[groups[group]]; if (current_index >= groups[group] && current_index < groups[group + 1])
groupinfo[2] = entries[groups[group + 1] - num_skip_in_groups - 1]; break;
oledDrawStringCenter(x, LineY + 2, groupinfo, 1); }
groupinfo[0] = entries[groups[group]];
oledHLine(OLED_HEIGHT / 2 - 5); groupinfo[2] = entries[groups[group + 1] - num_skip_in_groups - 1];
oledDrawStringCenter(x, LineY + 2, groupinfo, 1);
if (text)
oledDrawStringCenterMultiline(OLED_HEIGHT - FONT_HEIGHT * 2 - 1, text, 1, text_width); oledHLine(OLED_HEIGHT / 2 - 5);
if (draw_caret) if (text)
oledDrawCaret(); oledDrawStringCenterMultiline(OLED_HEIGHT - FONT_HEIGHT * 2 - 1, text, 1,
text_width);
oledRefresh();
if (draw_caret) oledDrawCaret();
oledRefresh();
} }
void layoutCheckPassphrase(const char *passphrase, int text_width, bool enable_edit, bool enable_done_yes) void layoutCheckPassphrase(const char *passphrase, int text_width,
{ bool enable_edit, bool enable_done_yes) {
layoutLast = layoutCheckPassphrase; layoutLast = layoutCheckPassphrase;
layoutSwipe(); layoutSwipe();
oledClear(); oledClear();
if (enable_edit && enable_done_yes) if (enable_edit && enable_done_yes)
oledDrawString(0, 0 * 9, "Confirm passphrase:", 0); oledDrawString(0, 0 * 9, "Confirm passphrase:", 0);
else if (enable_edit) else if (enable_edit)
oledDrawString(0, 0 * 9, "Passphrases mismatched:", 0); oledDrawString(0, 0 * 9, "Passphrases mismatched:", 0);
else else
oledDrawString(0, 0 * 9, "Passphrase confirmed:", 0); oledDrawString(0, 0 * 9, "Passphrase confirmed:", 0);
oledDrawStringCenterMultiline(OLED_HEIGHT / 2 - 2, passphrase, 1, text_width); oledDrawStringCenterMultiline(OLED_HEIGHT / 2 - 2, passphrase, 1, text_width);
if (enable_edit) if (enable_edit) {
{ const char *btnNo = "Edit";
const char *btnNo = "Edit"; oledDrawString(1, OLED_HEIGHT - 8, "\x15", 0);
oledDrawString(1, OLED_HEIGHT - 8, "\x15", 0); oledDrawString(fontCharWidth(0, '\x15') + 3, OLED_HEIGHT - 8, btnNo, 0);
oledDrawString(fontCharWidth(0, '\x15') + 3, OLED_HEIGHT - 8, btnNo, 0); oledInvert(0, OLED_HEIGHT - 9,
oledInvert(0, OLED_HEIGHT - 9, fontCharWidth(0, '\x15') + oledStringWidth(btnNo, 0) + 2, OLED_HEIGHT - 1); fontCharWidth(0, '\x15') + oledStringWidth(btnNo, 0) + 2,
} OLED_HEIGHT - 1);
}
if (enable_done_yes)
{ if (enable_done_yes) {
const char *DONE = "Done"; const char *DONE = "Done";
const char *NEXT = "Next"; const char *NEXT = "Next";
const char *btnYes = enable_edit ? DONE : NEXT; const char *btnYes = enable_edit ? DONE : NEXT;
oledDrawString(OLED_WIDTH - fontCharWidth(0, '\x06') - 1, OLED_HEIGHT - 8, "\x06", 0); oledDrawString(OLED_WIDTH - fontCharWidth(0, '\x06') - 1, OLED_HEIGHT - 8,
oledDrawString(OLED_WIDTH - oledStringWidth(btnYes, 0) - fontCharWidth(0, '\x06') - 3, OLED_HEIGHT - 8, btnYes, 0); "\x06", 0);
oledInvert(OLED_WIDTH - oledStringWidth(btnYes, 0) - fontCharWidth(0, '\x06') - 4, OLED_HEIGHT - 9, OLED_WIDTH - 1, OLED_HEIGHT - 1); oledDrawString(
} OLED_WIDTH - oledStringWidth(btnYes, 0) - fontCharWidth(0, '\x06') - 3,
OLED_HEIGHT - 8, btnYes, 0);
oledHLine(OLED_HEIGHT - 13); oledInvert(
OLED_WIDTH - oledStringWidth(btnYes, 0) - fontCharWidth(0, '\x06') - 4,
oledRefresh(); OLED_HEIGHT - 9, OLED_WIDTH - 1, OLED_HEIGHT - 1);
}
oledHLine(OLED_HEIGHT - 13);
oledRefresh();
} }
void layoutScreensaver(void) { void layoutScreensaver(void) {

@ -44,8 +44,13 @@ void layoutDialogSwipe(const BITMAP *icon, const char *btnNo,
const char *line5, const char *line6); const char *line5, const char *line6);
void layoutProgressSwipe(const char *desc, int permil); void layoutProgressSwipe(const char *desc, int permil);
void layoutScrollInput(const char *text, int text_width, int num_total, int num_screen, int current_index, const char entries[], int horizontal_padding, int num_group, const int groups[], int num_skip_in_groups, bool draw_caret); void layoutScrollInput(const char *text, int text_width, int num_total,
void layoutCheckPassphrase(const char *passphrase, int text_width, bool enable_edit, bool enable_done); int num_screen, int current_index, const char entries[],
int horizontal_padding, int num_group,
const int groups[], int num_skip_in_groups,
bool draw_caret);
void layoutCheckPassphrase(const char *passphrase, int text_width,
bool enable_edit, bool enable_done);
void layoutScreensaver(void); void layoutScreensaver(void);
void layoutHome(void); void layoutHome(void);

@ -30,21 +30,22 @@
#include "messages.pb.h" #include "messages.pb.h"
#include "oled.h" #include "oled.h"
#include "pinmatrix.h" #include "pinmatrix.h"
#include "rng.h"
#include "usb.h" #include "usb.h"
#include "util.h" #include "util.h"
#include "rng.h"
#define MAX_WRONG_PINS 15 #define MAX_WRONG_PINS 15
#define BACKSPACE '\x08' #define BACKSPACE '\x08'
#define SPACE '\x09' #define SPACE '\x09'
#define DONE '\x06' #define DONE '\x06'
#define INPUT_DONE -1 #define INPUT_DONE -1
#define NUM_PASSPHRASE_LINES 3 #define NUM_PASSPHRASE_LINES 3
#define CHAR_AND_SPACE_WIDTH (5 + 1) #define CHAR_AND_SPACE_WIDTH (5 + 1)
#define PASSPHRASE_WIDTH (MAX_PASSPHRASE_LEN / NUM_PASSPHRASE_LINES * CHAR_AND_SPACE_WIDTH) #define PASSPHRASE_WIDTH \
(MAX_PASSPHRASE_LEN / NUM_PASSPHRASE_LINES * CHAR_AND_SPACE_WIDTH)
#define LAST_PASSPHRASE_INDEX (MAX_PASSPHRASE_LEN - 1) #define LAST_PASSPHRASE_INDEX (MAX_PASSPHRASE_LEN - 1)
@ -54,125 +55,100 @@
bool protectAbortedByCancel = false; bool protectAbortedByCancel = false;
bool protectAbortedByInitialize = false; bool protectAbortedByInitialize = false;
void buttonCheckRepeat(bool *yes, bool *no, bool *confirm) void buttonCheckRepeat(bool *yes, bool *no, bool *confirm) {
{ *yes = false;
*yes = false; *no = false;
*no = false; *confirm = false;
*confirm = false;
const int Threshold0 = 20;
const int Threshold0 = 20; const int Thresholds[] = {Threshold0, 80, 20, 18, 16, 14, 12, 10, 8, 6, 4};
const int Thresholds[] = { Threshold0, 80, 20, 18, 16, 14, 12, 10, 8, 6, 4 }; const int MaxThresholdLevel = sizeof(Thresholds) / sizeof(Thresholds[0]) - 1;
const int MaxThresholdLevel = sizeof(Thresholds)/sizeof(Thresholds[0]) - 1;
static int yesthreshold = Threshold0;
static int yesthreshold = Threshold0; static int nothreshold = Threshold0;
static int nothreshold = Threshold0;
static int yeslevel = 0;
static int yeslevel = 0; static int nolevel = 0;
static int nolevel = 0;
static bool both = false;
static bool both = false;
usbSleep(5);
usbSleep(5); buttonUpdate();
buttonUpdate();
if (both) {
if (both) if (!button.YesDown && !button.NoDown) {
{ both = false;
if (!button.YesDown && !button.NoDown) yeslevel = 0;
{ nolevel = 0;
both = false; yesthreshold = Thresholds[0];
yeslevel = 0; nothreshold = Thresholds[0];
nolevel = 0; }
yesthreshold = Thresholds[0]; } else if ((button.YesDown && button.NoDown) ||
nothreshold = Thresholds[0]; (button.YesUp && button.NoDown) ||
} (button.YesDown && button.NoUp) || (button.YesUp && button.NoUp)) {
} if (!yeslevel && !nolevel) {
else if ((button.YesDown && button.NoDown) both = true;
|| (button.YesUp && button.NoDown) *confirm = true;
|| (button.YesDown && button.NoUp) }
|| (button.YesUp && button.NoUp)) } else {
{ if (button.YesUp) {
if (!yeslevel && !nolevel) if (!yeslevel) *yes = true;
{ yeslevel = 0;
both = true; yesthreshold = Thresholds[0];
*confirm = true; } else if (button.YesDown >= yesthreshold) {
} if (yeslevel < MaxThresholdLevel) yeslevel++;
} yesthreshold += Thresholds[yeslevel];
else *yes = true;
{ }
if (button.YesUp) if (button.NoUp) {
{ if (!nolevel) *no = true;
if (!yeslevel) nolevel = 0;
*yes = true; nothreshold = Thresholds[0];
yeslevel = 0; } else if (button.NoDown >= nothreshold) {
yesthreshold = Thresholds[0]; if (nolevel < MaxThresholdLevel) nolevel++;
} nothreshold += Thresholds[nolevel];
else if (button.YesDown >= yesthreshold) *no = true;
{ }
if (yeslevel < MaxThresholdLevel) }
yeslevel++;
yesthreshold += Thresholds[yeslevel];
*yes = true;
}
if (button.NoUp)
{
if (!nolevel)
*no = true;
nolevel = 0;
nothreshold = Thresholds[0];
}
else if (button.NoDown >= nothreshold)
{
if (nolevel < MaxThresholdLevel)
nolevel++;
nothreshold += Thresholds[nolevel];
*no = true;
}
}
} }
void buttonWaitForYesUp(void) void buttonWaitForYesUp(void) {
{ buttonUpdate();
buttonUpdate();
for (;;) {
for(;;) usbSleep(5);
{ buttonUpdate();
usbSleep(5); if (button.YesUp) break;
buttonUpdate(); }
if (button.YesUp)
break;
}
} }
void buttonWaitForIdle(void) void buttonWaitForIdle(void) {
{ buttonUpdate();
buttonUpdate();
for (;;) {
for(;;) usbSleep(5);
{ buttonUpdate();
usbSleep(5); if (!button.YesDown && !button.YesUp && !button.NoDown && !button.NoUp)
buttonUpdate(); break;
if (!button.YesDown && !button.YesUp && !button.NoDown && !button.NoUp) }
break;
}
} }
void requestOnDeviceTextInput(void) void requestOnDeviceTextInput(void) {
{ layoutDialog(&bmp_icon_question, _("Cancel"), _("Confirm"), NULL,
layoutDialog(&bmp_icon_question, _("Cancel"), _("Confirm"), NULL, _("Do you like to use"), _("on-device text input?"), NULL, NULL, NULL, NULL); _("Do you like to use"), _("on-device text input?"), NULL, NULL,
NULL, NULL);
buttonUpdate(); buttonUpdate();
for(;;) for (;;) {
{ usbSleep(5);
usbSleep(5); buttonUpdate();
buttonUpdate(); if (button.YesUp || button.NoUp) break;
if (button.YesUp || button.NoUp) }
break;
}
layoutSwipe(); layoutSwipe();
session_setUseOnDeviceTextInput(button.YesUp); session_setUseOnDeviceTextInput(button.YesUp);
} }
bool protectButton(ButtonRequestType type, bool confirm_only) { bool protectButton(ButtonRequestType type, bool confirm_only) {
@ -450,209 +426,197 @@ bool protectPassphraseComputer(void) {
return result; return result;
} }
int inputPassphraseScroll(char *passphrase, int *passphrasecharindex, const char entries[], int entryindex, int numtotal, int numscreen, int padding, const int groups[], int numgroup, int skip, int *caret) int inputPassphraseScroll(char *passphrase, int *passphrasecharindex,
{ const char entries[], int entryindex, int numtotal,
for (; ; *caret = (*caret + 1) % CARET_CYCLE) int numscreen, int padding, const int groups[],
{ int numgroup, int skip, int *caret) {
bool yes, no, confirm; for (;; *caret = (*caret + 1) % CARET_CYCLE) {
buttonCheckRepeat(&yes, &no, &confirm); bool yes, no, confirm;
buttonCheckRepeat(&yes, &no, &confirm);
if (confirm)
{ if (confirm) {
buttonWaitForIdle(); buttonWaitForIdle();
if (entries[entryindex] == BACKSPACE) if (entries[entryindex] == BACKSPACE) {
{ if (*passphrasecharindex > 0) {
if (*passphrasecharindex > 0) --(*passphrasecharindex);
{ passphrase[*passphrasecharindex] = 0;
--(*passphrasecharindex); }
passphrase[*passphrasecharindex] = 0; } else if (entries[entryindex] == DONE) {
} return INPUT_DONE;
} } else {
else if (entries[entryindex] == DONE) if (*passphrasecharindex < LAST_PASSPHRASE_INDEX) {
{ passphrase[*passphrasecharindex] = entries[entryindex];
return INPUT_DONE; ++(*passphrasecharindex);
} }
else return entryindex;
{ }
if (*passphrasecharindex < LAST_PASSPHRASE_INDEX)
{ entryindex = random32() % numtotal;
passphrase[*passphrasecharindex] = entries[entryindex]; } else {
++(*passphrasecharindex); if (yes) entryindex = (entryindex + 1) % numtotal;
} if (no) entryindex = (entryindex - 1 + numtotal) % numtotal;
return entryindex; }
}
layoutScrollInput(passphrase, PASSPHRASE_WIDTH, numtotal, numscreen,
entryindex = random32() % numtotal; entryindex, entries, padding, numgroup, groups, skip,
} *caret < CARET_SHOW);
else }
{
if (yes)
entryindex = (entryindex + 1) % numtotal;
if (no)
entryindex = (entryindex - 1 + numtotal) % numtotal;
}
layoutScrollInput(passphrase, PASSPHRASE_WIDTH, numtotal, numscreen, entryindex, entries, padding, numgroup, groups, skip, *caret < CARET_SHOW);
}
} }
int findCharIndex(const char entries[], char needle, int numtotal, int startindex, bool forward) int findCharIndex(const char entries[], char needle, int numtotal,
{ int startindex, bool forward) {
int index = startindex; int index = startindex;
int step = forward ? 1 : -1; int step = forward ? 1 : -1;
while (index >= 0 && index < numtotal) while (index >= 0 && index < numtotal) {
{ if (entries[index] == needle) return index;
if (entries[index] == needle) index += step;
return index; }
index += step; return startindex;
}
return startindex;
} }
void inputPassphrase(char *passphrase) void inputPassphrase(char *passphrase) {
{ const char Entries[] = {
const char Entries[] = { 'a', 'b', 'c', 'd', 'e', 'f', 'g',
'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', BACKSPACE, DONE, 'h', 'i', BACKSPACE, DONE, 'j', 'k', 'l',
'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', BACKSPACE, DONE, 'm', 'n', 'o', 'p', 'q', 'r', BACKSPACE,
's', 't', 'u', 'v', 'w', 'x', 'y', 'z', SPACE, BACKSPACE, DONE, DONE, 's', 't', 'u', 'v', 'w', 'x',
'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', BACKSPACE, DONE, 'y', 'z', SPACE, BACKSPACE, DONE, 'A', 'B',
'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', BACKSPACE, DONE, 'C', 'D', 'E', 'F', 'G', 'H', 'I',
'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z', SPACE, BACKSPACE, DONE, BACKSPACE, DONE, 'J', 'K', 'L', 'M', 'N',
'1', '2', '3', '4', '5', '6', '7', '8', '9', '0', BACKSPACE, DONE, 'O', 'P', 'Q', 'R', BACKSPACE, DONE, 'S',
'!', '@', '#', '$', '\x25', '^', '&', '*', '(', ')', BACKSPACE, DONE, 'T', 'U', 'V', 'W', 'X', 'Y', 'Z',
'`', '-', '=', '[', ']', '\\', ';', '\'', ',', '.', '/', BACKSPACE, DONE, SPACE, BACKSPACE, DONE, '1', '2', '3', '4',
'~', '_', '+', '{', '}', '|', ':', '\'', '<', '>', '?', BACKSPACE, DONE '5', '6', '7', '8', '9', '0', BACKSPACE,
}; DONE, '!', '@', '#', '$', '\x25', '^',
const int EntriesGroups[] = { 0, 11, 22, 33, 44, 55, 66, 78, 90, 103, 116 }; '&', '*', '(', ')', BACKSPACE, DONE, '`',
'-', '=', '[', ']', '\\', ';', '\'',
int numentries = sizeof(Entries) / sizeof(Entries[0]); ',', '.', '/', BACKSPACE, DONE, '~', '_',
int numentriesgroups = sizeof(EntriesGroups) / sizeof(EntriesGroups[0]); '+', '{', '}', '|', ':', '\'', '<',
'>', '?', BACKSPACE, DONE};
usbSleep(5); const int EntriesGroups[] = {0, 11, 22, 33, 44, 55, 66, 78, 90, 103, 116};
buttonUpdate();
int numentries = sizeof(Entries) / sizeof(Entries[0]);
int passphrasecharindex = strlen(passphrase); int numentriesgroups = sizeof(EntriesGroups) / sizeof(EntriesGroups[0]);
int caret = 0;
usbSleep(5);
for (;;) buttonUpdate();
{
int entryindex = random32() % numentries; int passphrasecharindex = strlen(passphrase);
if (passphrasecharindex >= LAST_PASSPHRASE_INDEX) int caret = 0;
entryindex = findCharIndex(Entries, DONE, numentries, entryindex, entryindex < numentries / 2);
entryindex = inputPassphraseScroll(passphrase, &passphrasecharindex, Entries, entryindex, numentries, 9, 9, EntriesGroups, numentriesgroups, 2, &caret); for (;;) {
if (entryindex == INPUT_DONE) int entryindex = random32() % numentries;
return; if (passphrasecharindex >= LAST_PASSPHRASE_INDEX)
} entryindex = findCharIndex(Entries, DONE, numentries, entryindex,
entryindex < numentries / 2);
entryindex = inputPassphraseScroll(
passphrase, &passphrasecharindex, Entries, entryindex, numentries, 9, 9,
EntriesGroups, numentriesgroups, 2, &caret);
if (entryindex == INPUT_DONE) return;
}
} }
bool checkPassphrase(const char *passphrase, bool enable_edit, bool enable_done) bool checkPassphrase(const char *passphrase, bool enable_edit,
{ bool enable_done) {
layoutCheckPassphrase(passphrase, PASSPHRASE_WIDTH, enable_edit, enable_done); layoutCheckPassphrase(passphrase, PASSPHRASE_WIDTH, enable_edit, enable_done);
buttonUpdate(); buttonUpdate();
for(;;) for (;;) {
{ usbSleep(5);
usbSleep(5); buttonUpdate();
buttonUpdate(); if (enable_done && button.YesUp) return true;
if (enable_done && button.YesUp) if (enable_edit && button.NoUp) return false;
return true; }
if (enable_edit && button.NoUp)
return false;
}
} }
bool protectPassphraseDevice(void) bool protectPassphraseDevice(void) {
{ static char CONFIDENTIAL passphrase[MAX_PASSPHRASE_LEN];
static char CONFIDENTIAL passphrase[MAX_PASSPHRASE_LEN];
memzero(passphrase, sizeof(passphrase));
buttonUpdate();
memzero(passphrase, sizeof(passphrase)); layoutDialog(NULL, NULL, _("Next"), NULL, _("You are about to enter"),
buttonUpdate(); _("the passphrase."), _("Select how many times"),
_("you'd like to do it."), NULL, NULL);
buttonWaitForYesUp();
layoutSwipe();
layoutDialog(NULL, NULL, _("Next"), NULL, _("You are about to enter"), _("the passphrase."), _("Select how many times"), _("you'd like to do it."), NULL, NULL); layoutDialog(NULL, _("Twice"), _("Once"), NULL,
buttonWaitForYesUp(); _("If you are creating a new"), _("wallet, it is advised"),
layoutSwipe(); _("that you select Twice."), NULL, NULL, NULL);
for (;;) {
usbSleep(5);
buttonUpdate();
if (button.YesUp || button.NoUp) break;
}
layoutSwipe();
layoutDialog(NULL, _("Twice"), _("Once"), NULL, _("If you are creating a new"), _("wallet, it is advised"), _("that you select Twice."), NULL, NULL, NULL); bool twice = button.NoUp;
for(;;)
{
usbSleep(5);
buttonUpdate();
if (button.YesUp || button.NoUp)
break;
}
layoutSwipe();
bool twice = button.NoUp; layoutDialog(NULL, NULL, _("Next"), NULL, _("Enter the passphrase"),
_("on the next screen."), _("- Single button: scroll."),
_("- Hold: auto-scroll."), _("- Both buttons: confirm."), NULL);
buttonWaitForYesUp();
layoutSwipe();
layoutDialog(NULL, NULL, _("Next"), NULL, _("Enter the passphrase"), _("on the next screen."), _("- Single button: scroll."), _("- Hold: auto-scroll."), _("- Both buttons: confirm."), NULL); for (;;) {
buttonWaitForYesUp(); inputPassphrase(passphrase);
layoutSwipe();
for (;;) if (checkPassphrase(passphrase, true, true)) break;
{
inputPassphrase(passphrase);
if (checkPassphrase(passphrase, true, true)) oledSwipeRight();
break; }
oledSwipeRight(); if (twice) {
} static char CONFIDENTIAL passphrase2[MAX_PASSPHRASE_LEN];
if (twice) memzero(passphrase2, sizeof(passphrase2));
{
static char CONFIDENTIAL passphrase2[MAX_PASSPHRASE_LEN];
memzero(passphrase2, sizeof(passphrase2)); layoutSwipe();
layoutDialog(NULL, NULL, _("Next"), NULL, _("Re-enter the passphrase."),
NULL, NULL, NULL, NULL, NULL);
buttonWaitForYesUp();
layoutSwipe();
layoutSwipe(); for (;;) {
layoutDialog(NULL, NULL, _("Next"), NULL, _("Re-enter the passphrase."), NULL, NULL, NULL, NULL, NULL); inputPassphrase(passphrase2);
buttonWaitForYesUp();
layoutSwipe();
for (;;) if (strcmp(passphrase, passphrase2) == 0) break;
{
inputPassphrase(passphrase2);
if (strcmp(passphrase, passphrase2) == 0) checkPassphrase(passphrase2, true, false);
break; oledSwipeRight();
}
checkPassphrase(passphrase2, true, false); memzero(passphrase2, sizeof(passphrase2));
oledSwipeRight(); }
}
memzero(passphrase2, sizeof(passphrase2)); checkPassphrase(passphrase, false, true);
}
checkPassphrase(passphrase, false, true); for (int i = 0; i < MAX_PASSPHRASE_LEN && passphrase[i]; ++i)
if (passphrase[i] == SPACE) passphrase[i] = ' ';
for (int i = 0; i < MAX_PASSPHRASE_LEN && passphrase[i]; ++i) session_cachePassphrase(passphrase);
if (passphrase[i] == SPACE) memzero(passphrase, sizeof(passphrase));
passphrase[i] = ' ';
session_cachePassphrase(passphrase);
memzero(passphrase, sizeof(passphrase));
layoutHome(); layoutHome();
return true; return true;
} }
bool protectPassphrase(void) bool protectPassphrase(void) {
{ bool passphrase_protection = false;
bool passphrase_protection = false; config_getPassphraseProtection(&passphrase_protection);
config_getPassphraseProtection(&passphrase_protection); if (!passphrase_protection || session_isPassphraseCached()) {
if (!passphrase_protection || session_isPassphraseCached()) { return true;
return true; }
}
bool result;
bool result; if (!session_isUseOnDeviceTextInputCached()) requestOnDeviceTextInput();
if (!session_isUseOnDeviceTextInputCached()) if (session_isUseOnDeviceTextInput())
requestOnDeviceTextInput(); result = protectPassphraseDevice();
if (session_isUseOnDeviceTextInput()) else
result = protectPassphraseDevice(); result = protectPassphraseComputer();
else return result;
result = protectPassphraseComputer();
return result;
} }

@ -16,6 +16,5 @@ int fontCharWidth(uint8_t font, uint8_t c) {
} }
const uint8_t *fontCharData(uint8_t font, uint8_t c) { const uint8_t *fontCharData(uint8_t font, uint8_t c) {
return (c >= 0x80) ? (const uint8_t *)"" return (c >= 0x80) ? (const uint8_t *)"" : font_data[font % FONTS][c] + 1;
: font_data[font % FONTS][c] + 1;
} }

@ -244,7 +244,8 @@ void oledSetBuffer(uint8_t *buf) {
memcpy(_oledbuffer, buf, sizeof(_oledbuffer)); memcpy(_oledbuffer, buf, sizeof(_oledbuffer));
} }
void oledDrawCharUpdateCaret(int x, int y, char c, uint8_t font, int zoom, bool update_caret) { void oledDrawCharUpdateCaret(int x, int y, char c, uint8_t font, int zoom,
bool update_caret) {
if (x >= OLED_WIDTH || y >= OLED_HEIGHT || y <= -FONT_HEIGHT) { if (x >= OLED_WIDTH || y >= OLED_HEIGHT || y <= -FONT_HEIGHT) {
return; return;
} }
@ -270,8 +271,7 @@ void oledDrawCharUpdateCaret(int x, int y, char c, uint8_t font, int zoom, bool
} }
} }
if (update_caret) if (update_caret) {
{
caret_x = x + (char_width + 1) * zoom; caret_x = x + (char_width + 1) * zoom;
caret_y = y; caret_y = y;
caret_zoom = zoom; caret_zoom = zoom;
@ -283,7 +283,7 @@ void oledDrawChar(int x, int y, char c, uint8_t font) {
} }
void oledDrawCaret(void) { void oledDrawCaret(void) {
oledDrawCharUpdateCaret(caret_x, caret_y, '\x03', 1, caret_zoom, false); oledDrawCharUpdateCaret(caret_x, caret_y, '\x03', 1, caret_zoom, false);
} }
static uint8_t convert_char(const char a) { static uint8_t convert_char(const char a) {
@ -355,91 +355,80 @@ void oledDrawStringRight(int x, int y, const char *text, uint8_t font) {
oledDrawString(x, y, text, font); oledDrawString(x, y, text, font);
} }
void oledDrawPartialStringSize(int x, int y, const char* text, uint8_t font, int size, int num) void oledDrawPartialStringSize(int x, int y, const char *text, uint8_t font,
{ int size, int num) {
if (!text) return; if (!text) return;
int l = 0; int l = 0;
for (; *text && num; text++, num--) { for (; *text && num; text++, num--) {
uint8_t c = convert_char(*text); uint8_t c = convert_char(*text);
if (c) { if (c) {
oledDrawCharUpdateCaret(x + l, y, c, font, size, true); oledDrawCharUpdateCaret(x + l, y, c, font, size, true);
l += (fontCharWidth(font, c) + 1) * size; l += (fontCharWidth(font, c) + 1) * size;
} }
} }
} }
void oledDrawPartialString(int x, int y, const char* text, uint8_t font, int num) void oledDrawPartialString(int x, int y, const char *text, uint8_t font,
{ int num) {
oledDrawPartialStringSize(x, y, text, font, 1, num); oledDrawPartialStringSize(x, y, text, font, 1, num);
} }
void oledDrawStringCenterMultiline(int y, const char* text, uint8_t font, int maxwidth) void oledDrawStringCenterMultiline(int y, const char *text, uint8_t font,
{ int maxwidth) {
const int CenterX = OLED_WIDTH / 2; const int CenterX = OLED_WIDTH / 2;
const int Height = FONT_HEIGHT + 1; const int Height = FONT_HEIGHT + 1;
if (!text || !*text) if (!text || !*text) {
{ caret_x = CenterX;
caret_x = CenterX; caret_y = y - Height / 2;
caret_y = y - Height / 2; caret_zoom = 1;
caret_zoom = 1; return;
return; }
}
if (maxwidth <= 0 || maxwidth > OLED_WIDTH) maxwidth = OLED_WIDTH;
if (maxwidth <= 0 || maxwidth > OLED_WIDTH)
maxwidth = OLED_WIDTH; const char *end = text + strlen(text);
const char* end = text + strlen(text); int lines = 0;
int chars[8];
int lines = 0; const char *str;
int chars[8]; for (str = text; str < end;) {
const char* str; int lo = 1;
for (str = text; str < end;) int hi = strlen(str);
{ int len = lo;
int lo = 1; for (;;) {
int hi = strlen(str); if (lo > hi) break;
int len = lo; int mid = (lo + hi) / 2;
for (;;) int width = oledPartialStringWidth(str, font, mid);
{ if (width < maxwidth) {
if (lo > hi) len = mid;
break; lo = mid + 1;
int mid = (lo + hi) / 2; } else if (width > maxwidth) {
int width = oledPartialStringWidth(str, font, mid); if (mid == len + 1)
if (width < maxwidth) break;
{ else
len = mid; hi = mid - 1;
lo = mid + 1; } else {
} len = mid;
else if (width > maxwidth) break;
{ }
if (mid == len + 1) }
break; str += len;
else chars[lines] = len;
hi = mid - 1; lines++;
} if (lines >= 8) break;
else }
{
len = mid; y -= Height * lines / 2;
break;
} str = text;
} for (int i = 0; i < lines; i++) {
str += len; int len = chars[i];
chars[lines] = len; oledDrawPartialString(CenterX - oledPartialStringWidth(str, font, len) / 2,
lines++; y, str, font, len);
if (lines >= 8) str += len;
break; y += Height;
} }
y -= Height * lines / 2;
str = text;
for (int i = 0; i < lines; i++)
{
int len = chars[i];
oledDrawPartialString(CenterX - oledPartialStringWidth(str, font, len) / 2, y, str, font, len);
str += len;
y += Height;
}
} }
void oledDrawBitmap(int x, int y, const BITMAP *bmp) { void oledDrawBitmap(int x, int y, const BITMAP *bmp) {
@ -484,29 +473,25 @@ void oledBox(int x1, int y1, int x2, int y2, bool set) {
} }
} }
void oledPartialHLine(int x1, int x2, int y) void oledPartialHLine(int x1, int x2, int y) {
{ if (y < 0 || y >= OLED_HEIGHT || x1 >= x2 || x1 >= OLED_WIDTH || x2 <= 0) {
if (y < 0 || y >= OLED_HEIGHT || x1 >= x2 || x1 >= OLED_WIDTH || x2 <= 0) { return;
return; }
} for (int x = x1; x < x2; x++) {
for (int x = x1; x < x2; x++) { oledDrawPixel(x, y);
oledDrawPixel(x, y); }
}
} }
void oledPartialVLine(int x, int y1, int y2) void oledPartialVLine(int x, int y1, int y2) {
{ if (x < 0 || x >= OLED_WIDTH || y1 >= y2 || y1 >= OLED_HEIGHT || y2 <= 0) {
if (x < 0 || x >= OLED_WIDTH || y1 >= y2 || y1 >= OLED_HEIGHT || y2 <= 0) { return;
return; }
} for (int y = y1; y < y2; y++) {
for (int y = y1; y < y2; y++) { oledDrawPixel(x, y);
oledDrawPixel(x, y); }
}
} }
void oledHLine(int y) { void oledHLine(int y) { oledPartialHLine(0, OLED_WIDTH, y); }
oledPartialHLine(0, OLED_WIDTH, y);
}
/* /*
* Draw a rectangle frame. * Draw a rectangle frame.

@ -48,7 +48,8 @@ void oledDrawCaret(void);
int oledStringWidth(const char *text, uint8_t font); int oledStringWidth(const char *text, uint8_t font);
void oledDrawString(int x, int y, const char *text, uint8_t font); void oledDrawString(int x, int y, const char *text, uint8_t font);
void oledDrawStringCenter(int x, int y, const char *text, uint8_t font); void oledDrawStringCenter(int x, int y, const char *text, uint8_t font);
void oledDrawStringCenterMultiline(int y, const char* text, uint8_t font, int width); void oledDrawStringCenterMultiline(int y, const char *text, uint8_t font,
int width);
void oledDrawStringRight(int x, int y, const char *text, uint8_t font); void oledDrawStringRight(int x, int y, const char *text, uint8_t font);
void oledDrawBitmap(int x, int y, const BITMAP *bmp); void oledDrawBitmap(int x, int y, const BITMAP *bmp);
void oledInvert(int x1, int y1, int x2, int y2); void oledInvert(int x1, int y1, int x2, int y2);

Loading…
Cancel
Save