mirror of
https://github.com/trezor/trezor-firmware.git
synced 2025-07-01 20:32:35 +00:00
legacy: style
This commit is contained in:
parent
8931ac1ef1
commit
3054a56288
17
legacy/firmware/config.c
Executable file → Normal file
17
legacy/firmware/config.c
Executable file → Normal file
@ -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_isUseOnDeviceTextInputCached(void)
|
||||
{
|
||||
return sectrue == sessionUseOnDeviceTextInputCached;
|
||||
bool session_isUseOnDeviceTextInputCached(void) {
|
||||
return sectrue == sessionUseOnDeviceTextInputCached;
|
||||
}
|
||||
|
||||
bool session_isUseOnDeviceTextInput(void)
|
||||
{
|
||||
return sectrue == sessionUseOnDeviceTextInput;
|
||||
bool session_isUseOnDeviceTextInput(void) {
|
||||
return sectrue == sessionUseOnDeviceTextInput;
|
||||
}
|
||||
|
||||
void session_setUseOnDeviceTextInput(bool use)
|
||||
{
|
||||
sessionUseOnDeviceTextInputCached = sectrue;
|
||||
sessionUseOnDeviceTextInput = use ? sectrue : secfalse;
|
||||
void session_setUseOnDeviceTextInput(bool use) {
|
||||
sessionUseOnDeviceTextInputCached = sectrue;
|
||||
sessionUseOnDeviceTextInput = use ? sectrue : secfalse;
|
||||
}
|
||||
|
||||
bool config_isInitialized(void) {
|
||||
|
170
legacy/firmware/layout2.c
Executable file → Normal file
170
legacy/firmware/layout2.c
Executable file → Normal file
@ -243,109 +243,117 @@ void layoutProgressSwipe(const char *desc, int 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)
|
||||
{
|
||||
layoutLast = layoutScrollInput;
|
||||
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) {
|
||||
layoutLast = layoutScrollInput;
|
||||
|
||||
oledClear();
|
||||
oledClear();
|
||||
|
||||
if (num_screen % 2 > 0)
|
||||
++num_screen;
|
||||
if (num_screen % 2 > 0) ++num_screen;
|
||||
|
||||
if (num_total <= 0 || num_screen <= 0 || current_index < 0 || current_index >= num_total || groups[num_group - 1] > num_total)
|
||||
return;
|
||||
|
||||
const int CenterX = OLED_WIDTH / 2;
|
||||
const int Y = 2;
|
||||
if (num_total <= 0 || num_screen <= 0 || current_index < 0 ||
|
||||
current_index >= num_total || groups[num_group - 1] > num_total)
|
||||
return;
|
||||
|
||||
int width = OLED_WIDTH - horizontal_padding * 2;
|
||||
int gap = width / (num_screen - 1);
|
||||
int t = (num_screen - 1) / 2;
|
||||
char letter[2];
|
||||
letter[1] = 0;
|
||||
for (int i = 0; i < num_screen && i < num_total; ++i)
|
||||
{
|
||||
int x = CenterX - gap * (t - i);
|
||||
int n = (current_index + i - t + num_total) % num_total;
|
||||
letter[0] = entries[n];
|
||||
oledDrawStringCenter(x, Y, letter, 1);
|
||||
}
|
||||
const int CenterX = OLED_WIDTH / 2;
|
||||
const int Y = 2;
|
||||
|
||||
int halfgap = gap / 2;
|
||||
oledInvert(CenterX - halfgap, Y - 2, CenterX + halfgap - 1, Y + FONT_HEIGHT + 1);
|
||||
int width = OLED_WIDTH - horizontal_padding * 2;
|
||||
int gap = width / (num_screen - 1);
|
||||
int t = (num_screen - 1) / 2;
|
||||
char letter[2];
|
||||
letter[1] = 0;
|
||||
for (int i = 0; i < num_screen && i < num_total; ++i) {
|
||||
int x = CenterX - gap * (t - i);
|
||||
int n = (current_index + i - t + num_total) % num_total;
|
||||
letter[0] = entries[n];
|
||||
oledDrawStringCenter(x, Y, letter, 1);
|
||||
}
|
||||
|
||||
const int LineY = Y + FONT_HEIGHT * 2 - 2;
|
||||
int halfgap = gap / 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)
|
||||
oledPartialVLine(horizontal_padding + width * groups[i] / num_total, LineY - 1, LineY);
|
||||
|
||||
int x = horizontal_padding + width * current_index / num_total;
|
||||
oledPartialHLine(x, x + 1, LineY - 1);
|
||||
oledPartialHLine(x - 1, x + 2, LineY - 2);
|
||||
oledPartialHLine(x - 2, x + 3, LineY - 3);
|
||||
width--;
|
||||
|
||||
char groupinfo[] = "?-?";
|
||||
int group;
|
||||
for (group = 0; group < num_group - 1; ++group)
|
||||
{
|
||||
if (current_index >= groups[group] && current_index < groups[group + 1])
|
||||
break;
|
||||
}
|
||||
groupinfo[0] = entries[groups[group]];
|
||||
groupinfo[2] = entries[groups[group + 1] - num_skip_in_groups - 1];
|
||||
oledDrawStringCenter(x, LineY + 2, groupinfo, 1);
|
||||
oledPartialHLine(horizontal_padding, OLED_WIDTH - horizontal_padding, LineY);
|
||||
for (int i = 0; i < num_group; ++i)
|
||||
oledPartialVLine(horizontal_padding + width * groups[i] / num_total,
|
||||
LineY - 1, LineY);
|
||||
|
||||
oledHLine(OLED_HEIGHT / 2 - 5);
|
||||
int x = horizontal_padding + width * current_index / num_total;
|
||||
oledPartialHLine(x, x + 1, LineY - 1);
|
||||
oledPartialHLine(x - 1, x + 2, LineY - 2);
|
||||
oledPartialHLine(x - 2, x + 3, LineY - 3);
|
||||
|
||||
if (text)
|
||||
oledDrawStringCenterMultiline(OLED_HEIGHT - FONT_HEIGHT * 2 - 1, text, 1, text_width);
|
||||
char groupinfo[] = "?-?";
|
||||
int group;
|
||||
for (group = 0; group < num_group - 1; ++group) {
|
||||
if (current_index >= groups[group] && current_index < groups[group + 1])
|
||||
break;
|
||||
}
|
||||
groupinfo[0] = entries[groups[group]];
|
||||
groupinfo[2] = entries[groups[group + 1] - num_skip_in_groups - 1];
|
||||
oledDrawStringCenter(x, LineY + 2, groupinfo, 1);
|
||||
|
||||
if (draw_caret)
|
||||
oledDrawCaret();
|
||||
oledHLine(OLED_HEIGHT / 2 - 5);
|
||||
|
||||
oledRefresh();
|
||||
if (text)
|
||||
oledDrawStringCenterMultiline(OLED_HEIGHT - FONT_HEIGHT * 2 - 1, text, 1,
|
||||
text_width);
|
||||
|
||||
if (draw_caret) oledDrawCaret();
|
||||
|
||||
oledRefresh();
|
||||
}
|
||||
|
||||
void layoutCheckPassphrase(const char *passphrase, int text_width, bool enable_edit, bool enable_done_yes)
|
||||
{
|
||||
layoutLast = layoutCheckPassphrase;
|
||||
layoutSwipe();
|
||||
void layoutCheckPassphrase(const char *passphrase, int text_width,
|
||||
bool enable_edit, bool enable_done_yes) {
|
||||
layoutLast = layoutCheckPassphrase;
|
||||
layoutSwipe();
|
||||
|
||||
oledClear();
|
||||
oledClear();
|
||||
|
||||
if (enable_edit && enable_done_yes)
|
||||
oledDrawString(0, 0 * 9, "Confirm passphrase:", 0);
|
||||
else if (enable_edit)
|
||||
oledDrawString(0, 0 * 9, "Passphrases mismatched:", 0);
|
||||
else
|
||||
oledDrawString(0, 0 * 9, "Passphrase confirmed:", 0);
|
||||
if (enable_edit && enable_done_yes)
|
||||
oledDrawString(0, 0 * 9, "Confirm passphrase:", 0);
|
||||
else if (enable_edit)
|
||||
oledDrawString(0, 0 * 9, "Passphrases mismatched:", 0);
|
||||
else
|
||||
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)
|
||||
{
|
||||
const char *btnNo = "Edit";
|
||||
oledDrawString(1, OLED_HEIGHT - 8, "\x15", 0);
|
||||
oledDrawString(fontCharWidth(0, '\x15') + 3, OLED_HEIGHT - 8, btnNo, 0);
|
||||
oledInvert(0, OLED_HEIGHT - 9, fontCharWidth(0, '\x15') + oledStringWidth(btnNo, 0) + 2, OLED_HEIGHT - 1);
|
||||
}
|
||||
if (enable_edit) {
|
||||
const char *btnNo = "Edit";
|
||||
oledDrawString(1, OLED_HEIGHT - 8, "\x15", 0);
|
||||
oledDrawString(fontCharWidth(0, '\x15') + 3, OLED_HEIGHT - 8, btnNo, 0);
|
||||
oledInvert(0, OLED_HEIGHT - 9,
|
||||
fontCharWidth(0, '\x15') + oledStringWidth(btnNo, 0) + 2,
|
||||
OLED_HEIGHT - 1);
|
||||
}
|
||||
|
||||
if (enable_done_yes)
|
||||
{
|
||||
const char *DONE = "Done";
|
||||
const char *NEXT = "Next";
|
||||
const char *btnYes = enable_edit ? DONE : NEXT;
|
||||
oledDrawString(OLED_WIDTH - fontCharWidth(0, '\x06') - 1, OLED_HEIGHT - 8, "\x06", 0);
|
||||
oledDrawString(OLED_WIDTH - oledStringWidth(btnYes, 0) - fontCharWidth(0, '\x06') - 3, OLED_HEIGHT - 8, btnYes, 0);
|
||||
oledInvert(OLED_WIDTH - oledStringWidth(btnYes, 0) - fontCharWidth(0, '\x06') - 4, OLED_HEIGHT - 9, OLED_WIDTH - 1, OLED_HEIGHT - 1);
|
||||
}
|
||||
if (enable_done_yes) {
|
||||
const char *DONE = "Done";
|
||||
const char *NEXT = "Next";
|
||||
const char *btnYes = enable_edit ? DONE : NEXT;
|
||||
oledDrawString(OLED_WIDTH - fontCharWidth(0, '\x06') - 1, OLED_HEIGHT - 8,
|
||||
"\x06", 0);
|
||||
oledDrawString(
|
||||
OLED_WIDTH - oledStringWidth(btnYes, 0) - fontCharWidth(0, '\x06') - 3,
|
||||
OLED_HEIGHT - 8, btnYes, 0);
|
||||
oledInvert(
|
||||
OLED_WIDTH - oledStringWidth(btnYes, 0) - fontCharWidth(0, '\x06') - 4,
|
||||
OLED_HEIGHT - 9, OLED_WIDTH - 1, OLED_HEIGHT - 1);
|
||||
}
|
||||
|
||||
oledHLine(OLED_HEIGHT - 13);
|
||||
oledHLine(OLED_HEIGHT - 13);
|
||||
|
||||
oledRefresh();
|
||||
oledRefresh();
|
||||
}
|
||||
|
||||
void layoutScreensaver(void) {
|
||||
|
9
legacy/firmware/layout2.h
Executable file → Normal file
9
legacy/firmware/layout2.h
Executable file → Normal file
@ -44,8 +44,13 @@ void layoutDialogSwipe(const BITMAP *icon, const char *btnNo,
|
||||
const char *line5, const char *line6);
|
||||
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 layoutCheckPassphrase(const char *passphrase, int text_width, bool enable_edit, bool enable_done);
|
||||
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 layoutCheckPassphrase(const char *passphrase, int text_width,
|
||||
bool enable_edit, bool enable_done);
|
||||
|
||||
void layoutScreensaver(void);
|
||||
void layoutHome(void);
|
||||
|
510
legacy/firmware/protect.c
Executable file → Normal file
510
legacy/firmware/protect.c
Executable file → Normal file
@ -30,21 +30,22 @@
|
||||
#include "messages.pb.h"
|
||||
#include "oled.h"
|
||||
#include "pinmatrix.h"
|
||||
#include "rng.h"
|
||||
#include "usb.h"
|
||||
#include "util.h"
|
||||
#include "rng.h"
|
||||
|
||||
#define MAX_WRONG_PINS 15
|
||||
|
||||
#define BACKSPACE '\x08'
|
||||
#define SPACE '\x09'
|
||||
#define DONE '\x06'
|
||||
#define SPACE '\x09'
|
||||
#define DONE '\x06'
|
||||
|
||||
#define INPUT_DONE -1
|
||||
|
||||
#define NUM_PASSPHRASE_LINES 3
|
||||
#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)
|
||||
|
||||
@ -54,125 +55,100 @@
|
||||
bool protectAbortedByCancel = false;
|
||||
bool protectAbortedByInitialize = false;
|
||||
|
||||
void buttonCheckRepeat(bool *yes, bool *no, bool *confirm)
|
||||
{
|
||||
*yes = false;
|
||||
*no = false;
|
||||
*confirm = false;
|
||||
void buttonCheckRepeat(bool *yes, bool *no, bool *confirm) {
|
||||
*yes = false;
|
||||
*no = false;
|
||||
*confirm = false;
|
||||
|
||||
const int Threshold0 = 20;
|
||||
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 Threshold0 = 20;
|
||||
const int Thresholds[] = {Threshold0, 80, 20, 18, 16, 14, 12, 10, 8, 6, 4};
|
||||
const int MaxThresholdLevel = sizeof(Thresholds) / sizeof(Thresholds[0]) - 1;
|
||||
|
||||
static int yesthreshold = Threshold0;
|
||||
static int nothreshold = Threshold0;
|
||||
static int yesthreshold = Threshold0;
|
||||
static int nothreshold = Threshold0;
|
||||
|
||||
static int yeslevel = 0;
|
||||
static int nolevel = 0;
|
||||
static int yeslevel = 0;
|
||||
static int nolevel = 0;
|
||||
|
||||
static bool both = false;
|
||||
static bool both = false;
|
||||
|
||||
usbSleep(5);
|
||||
buttonUpdate();
|
||||
|
||||
if (both)
|
||||
{
|
||||
if (!button.YesDown && !button.NoDown)
|
||||
{
|
||||
both = false;
|
||||
yeslevel = 0;
|
||||
nolevel = 0;
|
||||
yesthreshold = Thresholds[0];
|
||||
nothreshold = Thresholds[0];
|
||||
}
|
||||
}
|
||||
else if ((button.YesDown && button.NoDown)
|
||||
|| (button.YesUp && button.NoDown)
|
||||
|| (button.YesDown && button.NoUp)
|
||||
|| (button.YesUp && button.NoUp))
|
||||
{
|
||||
if (!yeslevel && !nolevel)
|
||||
{
|
||||
both = true;
|
||||
*confirm = true;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (button.YesUp)
|
||||
{
|
||||
if (!yeslevel)
|
||||
*yes = true;
|
||||
yeslevel = 0;
|
||||
yesthreshold = Thresholds[0];
|
||||
}
|
||||
else if (button.YesDown >= yesthreshold)
|
||||
{
|
||||
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;
|
||||
}
|
||||
}
|
||||
usbSleep(5);
|
||||
buttonUpdate();
|
||||
|
||||
if (both) {
|
||||
if (!button.YesDown && !button.NoDown) {
|
||||
both = false;
|
||||
yeslevel = 0;
|
||||
nolevel = 0;
|
||||
yesthreshold = Thresholds[0];
|
||||
nothreshold = Thresholds[0];
|
||||
}
|
||||
} else if ((button.YesDown && button.NoDown) ||
|
||||
(button.YesUp && button.NoDown) ||
|
||||
(button.YesDown && button.NoUp) || (button.YesUp && button.NoUp)) {
|
||||
if (!yeslevel && !nolevel) {
|
||||
both = true;
|
||||
*confirm = true;
|
||||
}
|
||||
} else {
|
||||
if (button.YesUp) {
|
||||
if (!yeslevel) *yes = true;
|
||||
yeslevel = 0;
|
||||
yesthreshold = Thresholds[0];
|
||||
} else if (button.YesDown >= yesthreshold) {
|
||||
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)
|
||||
{
|
||||
buttonUpdate();
|
||||
void buttonWaitForYesUp(void) {
|
||||
buttonUpdate();
|
||||
|
||||
for(;;)
|
||||
{
|
||||
usbSleep(5);
|
||||
buttonUpdate();
|
||||
if (button.YesUp)
|
||||
break;
|
||||
}
|
||||
for (;;) {
|
||||
usbSleep(5);
|
||||
buttonUpdate();
|
||||
if (button.YesUp) break;
|
||||
}
|
||||
}
|
||||
|
||||
void buttonWaitForIdle(void)
|
||||
{
|
||||
buttonUpdate();
|
||||
void buttonWaitForIdle(void) {
|
||||
buttonUpdate();
|
||||
|
||||
for(;;)
|
||||
{
|
||||
usbSleep(5);
|
||||
buttonUpdate();
|
||||
if (!button.YesDown && !button.YesUp && !button.NoDown && !button.NoUp)
|
||||
break;
|
||||
}
|
||||
for (;;) {
|
||||
usbSleep(5);
|
||||
buttonUpdate();
|
||||
if (!button.YesDown && !button.YesUp && !button.NoDown && !button.NoUp)
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
void requestOnDeviceTextInput(void)
|
||||
{
|
||||
layoutDialog(&bmp_icon_question, _("Cancel"), _("Confirm"), NULL, _("Do you like to use"), _("on-device text input?"), NULL, NULL, NULL, NULL);
|
||||
void requestOnDeviceTextInput(void) {
|
||||
layoutDialog(&bmp_icon_question, _("Cancel"), _("Confirm"), NULL,
|
||||
_("Do you like to use"), _("on-device text input?"), NULL, NULL,
|
||||
NULL, NULL);
|
||||
|
||||
buttonUpdate();
|
||||
buttonUpdate();
|
||||
|
||||
for(;;)
|
||||
{
|
||||
usbSleep(5);
|
||||
buttonUpdate();
|
||||
if (button.YesUp || button.NoUp)
|
||||
break;
|
||||
}
|
||||
for (;;) {
|
||||
usbSleep(5);
|
||||
buttonUpdate();
|
||||
if (button.YesUp || button.NoUp) break;
|
||||
}
|
||||
|
||||
layoutSwipe();
|
||||
layoutSwipe();
|
||||
|
||||
session_setUseOnDeviceTextInput(button.YesUp);
|
||||
session_setUseOnDeviceTextInput(button.YesUp);
|
||||
}
|
||||
|
||||
bool protectButton(ButtonRequestType type, bool confirm_only) {
|
||||
@ -450,209 +426,197 @@ bool protectPassphraseComputer(void) {
|
||||
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)
|
||||
{
|
||||
for (; ; *caret = (*caret + 1) % CARET_CYCLE)
|
||||
{
|
||||
bool yes, no, confirm;
|
||||
buttonCheckRepeat(&yes, &no, &confirm);
|
||||
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) {
|
||||
for (;; *caret = (*caret + 1) % CARET_CYCLE) {
|
||||
bool yes, no, confirm;
|
||||
buttonCheckRepeat(&yes, &no, &confirm);
|
||||
|
||||
if (confirm)
|
||||
{
|
||||
buttonWaitForIdle();
|
||||
|
||||
if (entries[entryindex] == BACKSPACE)
|
||||
{
|
||||
if (*passphrasecharindex > 0)
|
||||
{
|
||||
--(*passphrasecharindex);
|
||||
passphrase[*passphrasecharindex] = 0;
|
||||
}
|
||||
}
|
||||
else if (entries[entryindex] == DONE)
|
||||
{
|
||||
return INPUT_DONE;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (*passphrasecharindex < LAST_PASSPHRASE_INDEX)
|
||||
{
|
||||
passphrase[*passphrasecharindex] = entries[entryindex];
|
||||
++(*passphrasecharindex);
|
||||
}
|
||||
return entryindex;
|
||||
}
|
||||
if (confirm) {
|
||||
buttonWaitForIdle();
|
||||
|
||||
entryindex = random32() % numtotal;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (yes)
|
||||
entryindex = (entryindex + 1) % numtotal;
|
||||
if (no)
|
||||
entryindex = (entryindex - 1 + numtotal) % numtotal;
|
||||
}
|
||||
if (entries[entryindex] == BACKSPACE) {
|
||||
if (*passphrasecharindex > 0) {
|
||||
--(*passphrasecharindex);
|
||||
passphrase[*passphrasecharindex] = 0;
|
||||
}
|
||||
} else if (entries[entryindex] == DONE) {
|
||||
return INPUT_DONE;
|
||||
} else {
|
||||
if (*passphrasecharindex < LAST_PASSPHRASE_INDEX) {
|
||||
passphrase[*passphrasecharindex] = entries[entryindex];
|
||||
++(*passphrasecharindex);
|
||||
}
|
||||
return entryindex;
|
||||
}
|
||||
|
||||
layoutScrollInput(passphrase, PASSPHRASE_WIDTH, numtotal, numscreen, entryindex, entries, padding, numgroup, groups, skip, *caret < CARET_SHOW);
|
||||
}
|
||||
entryindex = random32() % numtotal;
|
||||
} 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 index = startindex;
|
||||
int step = forward ? 1 : -1;
|
||||
while (index >= 0 && index < numtotal)
|
||||
{
|
||||
if (entries[index] == needle)
|
||||
return index;
|
||||
index += step;
|
||||
}
|
||||
return startindex;
|
||||
int findCharIndex(const char entries[], char needle, int numtotal,
|
||||
int startindex, bool forward) {
|
||||
int index = startindex;
|
||||
int step = forward ? 1 : -1;
|
||||
while (index >= 0 && index < numtotal) {
|
||||
if (entries[index] == needle) return index;
|
||||
index += step;
|
||||
}
|
||||
return startindex;
|
||||
}
|
||||
|
||||
void inputPassphrase(char *passphrase)
|
||||
{
|
||||
const char Entries[] = {
|
||||
'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', BACKSPACE, DONE,
|
||||
'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', BACKSPACE, DONE,
|
||||
's', 't', 'u', 'v', 'w', 'x', 'y', 'z', SPACE, BACKSPACE, DONE,
|
||||
'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', BACKSPACE, DONE,
|
||||
'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', BACKSPACE, DONE,
|
||||
'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z', SPACE, BACKSPACE, DONE,
|
||||
'1', '2', '3', '4', '5', '6', '7', '8', '9', '0', BACKSPACE, DONE,
|
||||
'!', '@', '#', '$', '\x25', '^', '&', '*', '(', ')', BACKSPACE, DONE,
|
||||
'`', '-', '=', '[', ']', '\\', ';', '\'', ',', '.', '/', BACKSPACE, DONE,
|
||||
'~', '_', '+', '{', '}', '|', ':', '\'', '<', '>', '?', BACKSPACE, DONE
|
||||
};
|
||||
const int EntriesGroups[] = { 0, 11, 22, 33, 44, 55, 66, 78, 90, 103, 116 };
|
||||
void inputPassphrase(char *passphrase) {
|
||||
const char Entries[] = {
|
||||
'a', 'b', 'c', 'd', 'e', 'f', 'g',
|
||||
'h', 'i', BACKSPACE, DONE, 'j', 'k', 'l',
|
||||
'm', 'n', 'o', 'p', 'q', 'r', BACKSPACE,
|
||||
DONE, 's', 't', 'u', 'v', 'w', 'x',
|
||||
'y', 'z', SPACE, BACKSPACE, DONE, 'A', 'B',
|
||||
'C', 'D', 'E', 'F', 'G', 'H', 'I',
|
||||
BACKSPACE, DONE, 'J', 'K', 'L', 'M', 'N',
|
||||
'O', 'P', 'Q', 'R', BACKSPACE, DONE, 'S',
|
||||
'T', 'U', 'V', 'W', 'X', 'Y', 'Z',
|
||||
SPACE, BACKSPACE, DONE, '1', '2', '3', '4',
|
||||
'5', '6', '7', '8', '9', '0', BACKSPACE,
|
||||
DONE, '!', '@', '#', '$', '\x25', '^',
|
||||
'&', '*', '(', ')', BACKSPACE, DONE, '`',
|
||||
'-', '=', '[', ']', '\\', ';', '\'',
|
||||
',', '.', '/', BACKSPACE, DONE, '~', '_',
|
||||
'+', '{', '}', '|', ':', '\'', '<',
|
||||
'>', '?', BACKSPACE, DONE};
|
||||
const int EntriesGroups[] = {0, 11, 22, 33, 44, 55, 66, 78, 90, 103, 116};
|
||||
|
||||
int numentries = sizeof(Entries) / sizeof(Entries[0]);
|
||||
int numentriesgroups = sizeof(EntriesGroups) / sizeof(EntriesGroups[0]);
|
||||
int numentries = sizeof(Entries) / sizeof(Entries[0]);
|
||||
int numentriesgroups = sizeof(EntriesGroups) / sizeof(EntriesGroups[0]);
|
||||
|
||||
usbSleep(5);
|
||||
buttonUpdate();
|
||||
usbSleep(5);
|
||||
buttonUpdate();
|
||||
|
||||
int passphrasecharindex = strlen(passphrase);
|
||||
int caret = 0;
|
||||
|
||||
for (;;)
|
||||
{
|
||||
int entryindex = random32() % numentries;
|
||||
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;
|
||||
}
|
||||
int passphrasecharindex = strlen(passphrase);
|
||||
int caret = 0;
|
||||
|
||||
for (;;) {
|
||||
int entryindex = random32() % numentries;
|
||||
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)
|
||||
{
|
||||
layoutCheckPassphrase(passphrase, PASSPHRASE_WIDTH, enable_edit, enable_done);
|
||||
bool checkPassphrase(const char *passphrase, bool enable_edit,
|
||||
bool enable_done) {
|
||||
layoutCheckPassphrase(passphrase, PASSPHRASE_WIDTH, enable_edit, enable_done);
|
||||
|
||||
buttonUpdate();
|
||||
buttonUpdate();
|
||||
|
||||
for(;;)
|
||||
{
|
||||
usbSleep(5);
|
||||
buttonUpdate();
|
||||
if (enable_done && button.YesUp)
|
||||
return true;
|
||||
if (enable_edit && button.NoUp)
|
||||
return false;
|
||||
}
|
||||
for (;;) {
|
||||
usbSleep(5);
|
||||
buttonUpdate();
|
||||
if (enable_done && button.YesUp) return true;
|
||||
if (enable_edit && button.NoUp) return false;
|
||||
}
|
||||
}
|
||||
|
||||
bool protectPassphraseDevice(void)
|
||||
{
|
||||
static char CONFIDENTIAL passphrase[MAX_PASSPHRASE_LEN];
|
||||
bool protectPassphraseDevice(void) {
|
||||
static char CONFIDENTIAL passphrase[MAX_PASSPHRASE_LEN];
|
||||
|
||||
memzero(passphrase, sizeof(passphrase));
|
||||
buttonUpdate();
|
||||
memzero(passphrase, sizeof(passphrase));
|
||||
buttonUpdate();
|
||||
|
||||
layoutDialog(NULL, NULL, _("Next"), NULL, _("You are about to enter"), _("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);
|
||||
buttonWaitForYesUp();
|
||||
layoutSwipe();
|
||||
|
||||
layoutDialog(NULL, _("Twice"), _("Once"), NULL, _("If you are creating a new"), _("wallet, it is advised"), _("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);
|
||||
for (;;) {
|
||||
usbSleep(5);
|
||||
buttonUpdate();
|
||||
if (button.YesUp || button.NoUp) break;
|
||||
}
|
||||
layoutSwipe();
|
||||
|
||||
bool twice = button.NoUp;
|
||||
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);
|
||||
buttonWaitForYesUp();
|
||||
layoutSwipe();
|
||||
|
||||
for (;;)
|
||||
{
|
||||
inputPassphrase(passphrase);
|
||||
for (;;) {
|
||||
inputPassphrase(passphrase);
|
||||
|
||||
if (checkPassphrase(passphrase, true, true))
|
||||
break;
|
||||
if (checkPassphrase(passphrase, true, true)) break;
|
||||
|
||||
oledSwipeRight();
|
||||
}
|
||||
oledSwipeRight();
|
||||
}
|
||||
|
||||
if (twice)
|
||||
{
|
||||
static char CONFIDENTIAL passphrase2[MAX_PASSPHRASE_LEN];
|
||||
if (twice) {
|
||||
static char CONFIDENTIAL passphrase2[MAX_PASSPHRASE_LEN];
|
||||
|
||||
memzero(passphrase2, sizeof(passphrase2));
|
||||
memzero(passphrase2, sizeof(passphrase2));
|
||||
|
||||
layoutSwipe();
|
||||
layoutDialog(NULL, NULL, _("Next"), NULL, _("Re-enter the passphrase."), NULL, NULL, NULL, NULL, NULL);
|
||||
buttonWaitForYesUp();
|
||||
layoutSwipe();
|
||||
layoutSwipe();
|
||||
layoutDialog(NULL, NULL, _("Next"), NULL, _("Re-enter the passphrase."),
|
||||
NULL, NULL, NULL, NULL, NULL);
|
||||
buttonWaitForYesUp();
|
||||
layoutSwipe();
|
||||
|
||||
for (;;)
|
||||
{
|
||||
inputPassphrase(passphrase2);
|
||||
for (;;) {
|
||||
inputPassphrase(passphrase2);
|
||||
|
||||
if (strcmp(passphrase, passphrase2) == 0)
|
||||
break;
|
||||
if (strcmp(passphrase, passphrase2) == 0) break;
|
||||
|
||||
checkPassphrase(passphrase2, true, false);
|
||||
oledSwipeRight();
|
||||
}
|
||||
checkPassphrase(passphrase2, true, false);
|
||||
oledSwipeRight();
|
||||
}
|
||||
|
||||
memzero(passphrase2, sizeof(passphrase2));
|
||||
}
|
||||
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] = ' ';
|
||||
|
||||
session_cachePassphrase(passphrase);
|
||||
memzero(passphrase, sizeof(passphrase));
|
||||
for (int i = 0; i < MAX_PASSPHRASE_LEN && passphrase[i]; ++i)
|
||||
if (passphrase[i] == SPACE) passphrase[i] = ' ';
|
||||
|
||||
layoutHome();
|
||||
session_cachePassphrase(passphrase);
|
||||
memzero(passphrase, sizeof(passphrase));
|
||||
|
||||
return true;
|
||||
layoutHome();
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool protectPassphrase(void)
|
||||
{
|
||||
bool passphrase_protection = false;
|
||||
config_getPassphraseProtection(&passphrase_protection);
|
||||
if (!passphrase_protection || session_isPassphraseCached()) {
|
||||
return true;
|
||||
}
|
||||
bool protectPassphrase(void) {
|
||||
bool passphrase_protection = false;
|
||||
config_getPassphraseProtection(&passphrase_protection);
|
||||
if (!passphrase_protection || session_isPassphraseCached()) {
|
||||
return true;
|
||||
}
|
||||
|
||||
bool result;
|
||||
if (!session_isUseOnDeviceTextInputCached())
|
||||
requestOnDeviceTextInput();
|
||||
if (session_isUseOnDeviceTextInput())
|
||||
result = protectPassphraseDevice();
|
||||
else
|
||||
result = protectPassphraseComputer();
|
||||
return result;
|
||||
bool result;
|
||||
if (!session_isUseOnDeviceTextInputCached()) requestOnDeviceTextInput();
|
||||
if (session_isUseOnDeviceTextInput())
|
||||
result = protectPassphraseDevice();
|
||||
else
|
||||
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) {
|
||||
return (c >= 0x80) ? (const uint8_t *)""
|
||||
: font_data[font % FONTS][c] + 1;
|
||||
return (c >= 0x80) ? (const uint8_t *)"" : font_data[font % FONTS][c] + 1;
|
||||
}
|
||||
|
183
legacy/oled.c
Executable file → Normal file
183
legacy/oled.c
Executable file → Normal file
@ -244,7 +244,8 @@ void oledSetBuffer(uint8_t *buf) {
|
||||
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) {
|
||||
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_y = y;
|
||||
caret_zoom = zoom;
|
||||
@ -283,7 +283,7 @@ void oledDrawChar(int x, int y, char c, uint8_t font) {
|
||||
}
|
||||
|
||||
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) {
|
||||
@ -355,91 +355,80 @@ void oledDrawStringRight(int x, int y, const char *text, uint8_t font) {
|
||||
oledDrawString(x, y, text, font);
|
||||
}
|
||||
|
||||
void oledDrawPartialStringSize(int x, int y, const char* text, uint8_t font, int size, int num)
|
||||
{
|
||||
if (!text) return;
|
||||
int l = 0;
|
||||
for (; *text && num; text++, num--) {
|
||||
uint8_t c = convert_char(*text);
|
||||
if (c) {
|
||||
oledDrawCharUpdateCaret(x + l, y, c, font, size, true);
|
||||
l += (fontCharWidth(font, c) + 1) * size;
|
||||
}
|
||||
}
|
||||
void oledDrawPartialStringSize(int x, int y, const char *text, uint8_t font,
|
||||
int size, int num) {
|
||||
if (!text) return;
|
||||
int l = 0;
|
||||
for (; *text && num; text++, num--) {
|
||||
uint8_t c = convert_char(*text);
|
||||
if (c) {
|
||||
oledDrawCharUpdateCaret(x + l, y, c, font, size, true);
|
||||
l += (fontCharWidth(font, c) + 1) * size;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void oledDrawPartialString(int x, int y, const char* text, uint8_t font, int num)
|
||||
{
|
||||
oledDrawPartialStringSize(x, y, text, font, 1, num);
|
||||
void oledDrawPartialString(int x, int y, const char *text, uint8_t font,
|
||||
int num) {
|
||||
oledDrawPartialStringSize(x, y, text, font, 1, num);
|
||||
}
|
||||
|
||||
void oledDrawStringCenterMultiline(int y, const char* text, uint8_t font, int maxwidth)
|
||||
{
|
||||
const int CenterX = OLED_WIDTH / 2;
|
||||
const int Height = FONT_HEIGHT + 1;
|
||||
void oledDrawStringCenterMultiline(int y, const char *text, uint8_t font,
|
||||
int maxwidth) {
|
||||
const int CenterX = OLED_WIDTH / 2;
|
||||
const int Height = FONT_HEIGHT + 1;
|
||||
|
||||
if (!text || !*text)
|
||||
{
|
||||
caret_x = CenterX;
|
||||
caret_y = y - Height / 2;
|
||||
caret_zoom = 1;
|
||||
return;
|
||||
}
|
||||
if (!text || !*text) {
|
||||
caret_x = CenterX;
|
||||
caret_y = y - Height / 2;
|
||||
caret_zoom = 1;
|
||||
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);
|
||||
|
||||
int lines = 0;
|
||||
int chars[8];
|
||||
const char* str;
|
||||
for (str = text; str < end;)
|
||||
{
|
||||
int lo = 1;
|
||||
int hi = strlen(str);
|
||||
int len = lo;
|
||||
for (;;)
|
||||
{
|
||||
if (lo > hi)
|
||||
break;
|
||||
int mid = (lo + hi) / 2;
|
||||
int width = oledPartialStringWidth(str, font, mid);
|
||||
if (width < maxwidth)
|
||||
{
|
||||
len = mid;
|
||||
lo = mid + 1;
|
||||
}
|
||||
else if (width > maxwidth)
|
||||
{
|
||||
if (mid == len + 1)
|
||||
break;
|
||||
else
|
||||
hi = mid - 1;
|
||||
}
|
||||
else
|
||||
{
|
||||
len = mid;
|
||||
break;
|
||||
}
|
||||
}
|
||||
str += len;
|
||||
chars[lines] = len;
|
||||
lines++;
|
||||
if (lines >= 8)
|
||||
break;
|
||||
}
|
||||
const char *end = text + strlen(text);
|
||||
|
||||
y -= Height * lines / 2;
|
||||
int lines = 0;
|
||||
int chars[8];
|
||||
const char *str;
|
||||
for (str = text; str < end;) {
|
||||
int lo = 1;
|
||||
int hi = strlen(str);
|
||||
int len = lo;
|
||||
for (;;) {
|
||||
if (lo > hi) break;
|
||||
int mid = (lo + hi) / 2;
|
||||
int width = oledPartialStringWidth(str, font, mid);
|
||||
if (width < maxwidth) {
|
||||
len = mid;
|
||||
lo = mid + 1;
|
||||
} else if (width > maxwidth) {
|
||||
if (mid == len + 1)
|
||||
break;
|
||||
else
|
||||
hi = mid - 1;
|
||||
} else {
|
||||
len = mid;
|
||||
break;
|
||||
}
|
||||
}
|
||||
str += len;
|
||||
chars[lines] = len;
|
||||
lines++;
|
||||
if (lines >= 8) break;
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
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) {
|
||||
@ -484,29 +473,25 @@ void oledBox(int x1, int y1, int x2, int y2, bool set) {
|
||||
}
|
||||
}
|
||||
|
||||
void oledPartialHLine(int x1, int x2, int y)
|
||||
{
|
||||
if (y < 0 || y >= OLED_HEIGHT || x1 >= x2 || x1 >= OLED_WIDTH || x2 <= 0) {
|
||||
return;
|
||||
}
|
||||
for (int x = x1; x < x2; x++) {
|
||||
oledDrawPixel(x, y);
|
||||
}
|
||||
void oledPartialHLine(int x1, int x2, int y) {
|
||||
if (y < 0 || y >= OLED_HEIGHT || x1 >= x2 || x1 >= OLED_WIDTH || x2 <= 0) {
|
||||
return;
|
||||
}
|
||||
for (int x = x1; x < x2; x++) {
|
||||
oledDrawPixel(x, y);
|
||||
}
|
||||
}
|
||||
|
||||
void oledPartialVLine(int x, int y1, int y2)
|
||||
{
|
||||
if (x < 0 || x >= OLED_WIDTH || y1 >= y2 || y1 >= OLED_HEIGHT || y2 <= 0) {
|
||||
return;
|
||||
}
|
||||
for (int y = y1; y < y2; y++) {
|
||||
oledDrawPixel(x, y);
|
||||
}
|
||||
void oledPartialVLine(int x, int y1, int y2) {
|
||||
if (x < 0 || x >= OLED_WIDTH || y1 >= y2 || y1 >= OLED_HEIGHT || y2 <= 0) {
|
||||
return;
|
||||
}
|
||||
for (int y = y1; y < y2; y++) {
|
||||
oledDrawPixel(x, y);
|
||||
}
|
||||
}
|
||||
|
||||
void oledHLine(int y) {
|
||||
oledPartialHLine(0, OLED_WIDTH, y);
|
||||
}
|
||||
void oledHLine(int y) { oledPartialHLine(0, OLED_WIDTH, y); }
|
||||
|
||||
/*
|
||||
* Draw a rectangle frame.
|
||||
|
3
legacy/oled.h
Executable file → Normal file
3
legacy/oled.h
Executable file → Normal file
@ -48,7 +48,8 @@ void oledDrawCaret(void);
|
||||
int oledStringWidth(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 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 oledDrawBitmap(int x, int y, const BITMAP *bmp);
|
||||
void oledInvert(int x1, int y1, int x2, int y2);
|
||||
|
Loading…
Reference in New Issue
Block a user