mirror of
https://github.com/portapack-mayhem/mayhem-firmware.git
synced 2025-12-02 22:01:47 +00:00
Unistroke in dirty code
This commit is contained in:
@@ -23,6 +23,7 @@
|
||||
|
||||
#include "portapack.hpp"
|
||||
#include "portapack_shared_memory.hpp"
|
||||
#include "portapack_persistent_memory.hpp"
|
||||
|
||||
#include "sd_card.hpp"
|
||||
#include "time.hpp"
|
||||
|
||||
@@ -24,6 +24,7 @@
|
||||
#include "ch.h"
|
||||
|
||||
#include "ff.h"
|
||||
#include "unistroke.hpp"
|
||||
#include "portapack.hpp"
|
||||
#include "event_m0.hpp"
|
||||
#include "string_format.hpp"
|
||||
@@ -36,10 +37,6 @@
|
||||
using namespace portapack;
|
||||
|
||||
namespace ui {
|
||||
|
||||
HandWriteView::~HandWriteView() {
|
||||
time::signal_tick_second -= signal_token_tick_second;
|
||||
}
|
||||
|
||||
HandWriteView::HandWriteView(
|
||||
NavigationView& nav,
|
||||
@@ -68,7 +65,7 @@ HandWriteView::HandWriteView(
|
||||
24, 20
|
||||
});
|
||||
const std::string label {
|
||||
n + 0x30
|
||||
(char)(n + 0x30)
|
||||
};
|
||||
button.set_text(label);
|
||||
button.id = n;
|
||||
@@ -91,17 +88,12 @@ HandWriteView::HandWriteView(
|
||||
|
||||
add_child(&text_debug_x);
|
||||
add_child(&text_debug_y);
|
||||
add_child(&text_debug_write);
|
||||
add_child(&button_done);
|
||||
button_done.on_select = [this, &nav, txt, max_len](Button&) {
|
||||
//memcpy(txt, txtinput, max_len+1);
|
||||
//on_changed(this->value());
|
||||
nav.pop();
|
||||
};
|
||||
|
||||
signal_token_tick_second = time::signal_tick_second += [this]() {
|
||||
this->on_tick_second();
|
||||
};
|
||||
|
||||
//update_text();
|
||||
}
|
||||
@@ -161,7 +153,7 @@ bool HandWriteView::on_touch(const TouchEvent event) {
|
||||
);
|
||||
|
||||
// Letter guessing
|
||||
guess = '?';
|
||||
guess = ' ';
|
||||
|
||||
if (MM(0, 'U')) {
|
||||
if (MM(0, 'U', '?')) {
|
||||
@@ -174,7 +166,10 @@ bool HandWriteView::on_touch(const TouchEvent event) {
|
||||
guess = 'K';
|
||||
} else {
|
||||
if (MM(1, 'L')) {
|
||||
if (txt_idx > 0) txtinput[txt_idx--] = 0; // Erase
|
||||
if (txtidx > 0) {
|
||||
txtinput[--txtidx] = 0; // Erase
|
||||
guess = '!';
|
||||
}
|
||||
} else {
|
||||
guess = 'N';
|
||||
}
|
||||
@@ -218,7 +213,7 @@ bool HandWriteView::on_touch(const TouchEvent event) {
|
||||
if (MI(1))
|
||||
guess = 'E';
|
||||
else
|
||||
guess = 'S';
|
||||
if (MM(1, 'R')) guess = 'S';
|
||||
}
|
||||
} else if (MM(0, 'R')) {
|
||||
if (!MI(2) && (MLAST('U') || MLAST('R'))) guess = 'X';
|
||||
@@ -234,9 +229,8 @@ bool HandWriteView::on_touch(const TouchEvent event) {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// if (guess = '?') guess = ' ';
|
||||
if (guess != '!') txtinput[txt_idx++] = guess;
|
||||
|
||||
if (guess != '!') txtinput[txtidx++] = guess;
|
||||
update_text();
|
||||
}
|
||||
if (event.type == ui::TouchEvent::Type::Move) {
|
||||
@@ -249,7 +243,28 @@ bool HandWriteView::on_touch(const TouchEvent event) {
|
||||
|
||||
void HandWriteView::sample_pen() {
|
||||
int16_t diff_x, diff_y;
|
||||
uint8_t dir, i;
|
||||
uint8_t dir;
|
||||
|
||||
// Blink cursor
|
||||
if (!(sample_skip & 15)) {
|
||||
Point cursor_pos;
|
||||
|
||||
cursor_pos.x = text_input.screen_rect().pos.x + (txtidx * 8);
|
||||
cursor_pos.y = text_input.screen_rect().pos.y + 17;
|
||||
|
||||
if (cursor) {
|
||||
display.fill_rectangle(
|
||||
{{text_input.screen_rect().pos.x, cursor_pos.y}, {text_input.screen_rect().size.w, 4}},
|
||||
Color::black()
|
||||
);
|
||||
} else {
|
||||
display.fill_rectangle(
|
||||
{cursor_pos, {8, 4}},
|
||||
Color::white()
|
||||
);
|
||||
}
|
||||
cursor = !cursor;
|
||||
}
|
||||
|
||||
if (!(sample_skip & 1)) {
|
||||
if (tracing) {
|
||||
|
||||
@@ -36,7 +36,6 @@ public:
|
||||
std::function<void(char *)> on_changed;
|
||||
|
||||
HandWriteView(NavigationView& nav, char txt[], uint8_t max_len);
|
||||
~HandWriteView();
|
||||
|
||||
void on_show() override;
|
||||
bool on_touch(const TouchEvent event) override;
|
||||
@@ -49,11 +48,10 @@ public:
|
||||
void char_delete();
|
||||
|
||||
private:
|
||||
SignalToken signal_token_tick_second;
|
||||
|
||||
uint8_t _max_len, txt_idx = 0;
|
||||
uint8_t _max_len;
|
||||
uint8_t dir_cnt = 0;
|
||||
uint8_t dir_prev;
|
||||
bool cursor = false;
|
||||
bool tracing = false;
|
||||
uint8_t move_index;
|
||||
uint8_t sample_skip, move_wait;
|
||||
@@ -72,7 +70,7 @@ private:
|
||||
void sample_pen();
|
||||
|
||||
Text text_input {
|
||||
{ 0, 0, 240, 16 }
|
||||
{ 8, 0, 224, 16 }
|
||||
};
|
||||
|
||||
Text text_debug_x {
|
||||
@@ -81,10 +79,6 @@ private:
|
||||
Text text_debug_y {
|
||||
{ 0, 32, 32, 16 }
|
||||
};
|
||||
Text text_debug_write {
|
||||
{ 80, 24, 150, 16 }
|
||||
};
|
||||
|
||||
std::array<Button, 10> num_buttons;
|
||||
|
||||
Button button_lowercase {
|
||||
|
||||
87
firmware/application/unistroke.hpp
Normal file
87
firmware/application/unistroke.hpp
Normal file
@@ -0,0 +1,87 @@
|
||||
/*
|
||||
* Copyright (C) 2015 Jared Boone, ShareBrained Technology, Inc.
|
||||
*
|
||||
* This file is part of PortaPack.
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2, or (at your option)
|
||||
* any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; see the file COPYING. If not, write to
|
||||
* the Free Software Foundation, Inc., 51 Franklin Street,
|
||||
* Boston, MA 02110-1301, USA.
|
||||
*/
|
||||
|
||||
#define HWDIR_TWO 0x40
|
||||
#define HWDIR_ONLY 0x80
|
||||
|
||||
enum Condition {
|
||||
cond_empty = -1,
|
||||
stroke_a = 0,
|
||||
stroke_b = 1,
|
||||
stroke_c = 2,
|
||||
stroke_d = 3,
|
||||
last = 8
|
||||
};
|
||||
|
||||
enum Direction {
|
||||
dir_empty = -1,
|
||||
Uw = 0x00,
|
||||
Dw = 0x10,
|
||||
Lw = 0x00,
|
||||
Rw = 0x01,
|
||||
U = 0x00 | HWDIR_ONLY,
|
||||
D = 0x10 | HWDIR_ONLY,
|
||||
L = 0x00 | HWDIR_ONLY,
|
||||
R = 0x01 | HWDIR_ONLY,
|
||||
UL = 0x00 | HWDIR_TWO,
|
||||
DL = 0x10 | HWDIR_TWO,
|
||||
UR = 0x01 | HWDIR_TWO,
|
||||
DR = 0x11 | HWDIR_TWO
|
||||
};
|
||||
|
||||
struct HandWriting {
|
||||
struct HandWritingLetter {
|
||||
Condition cond;
|
||||
Direction dir;
|
||||
} letter[3];
|
||||
int8_t count;
|
||||
};
|
||||
|
||||
const HandWriting handwriting_unistroke[32] = {
|
||||
{{{stroke_a, U}, {cond_empty, dir_empty}, {cond_empty, dir_empty}}, 1}, // A 0=U MI=1
|
||||
{{{stroke_a, DR}, {stroke_b, DL}, {cond_empty, dir_empty}}, 0}, // B 0=DR 1=DL
|
||||
{{{stroke_a, UL}, {stroke_b, UR}, {cond_empty, dir_empty}}, 0}, // C 0=UL 1=UR
|
||||
{{{stroke_a, DL}, {stroke_b, DR}, {cond_empty, dir_empty}}, 0}, // D 0=DL 1=DR
|
||||
{{{stroke_a, L}, {cond_empty, dir_empty}, {cond_empty, dir_empty}}, 1}, // E 0=L MI=1
|
||||
{{{stroke_a, U}, {stroke_b, R}, {cond_empty, dir_empty}}, 0}, // F 0=U 1=R
|
||||
{{{stroke_a, R}, {stroke_b, U}, {cond_empty, dir_empty}}, 0}, // G 0=R 1=U
|
||||
{{{stroke_a, R}, {stroke_b, D}, {cond_empty, dir_empty}}, 0}, // H 0=R 1=D
|
||||
{{{stroke_a, D}, {cond_empty, dir_empty}, {cond_empty, dir_empty}}, 1}, // I 0=D MI=1
|
||||
{{{stroke_a, D}, {stroke_b, L}, {cond_empty, dir_empty}}, 0}, // J 0=D 1=L
|
||||
{{{stroke_a, UR}, {cond_empty, dir_empty}, {cond_empty, dir_empty}}, 1}, // K 0=UR MI=1
|
||||
{{{stroke_a, D}, {stroke_b, R}, {cond_empty, dir_empty}}, 0}, // L 0=D 1=R
|
||||
{{{stroke_a, UL}, {stroke_b, DL}, {cond_empty, dir_empty}}, 0}, // M 0=UL 1=DL
|
||||
{{{stroke_a, UR}, {stroke_b, DR}, {cond_empty, dir_empty}}, 0}, // N 0=UR 1=DR
|
||||
{{{stroke_a, Lw}, {last, Lw}, {cond_empty, dir_empty}}, 2}, // O 0=Lw MI>2 -=Lw !!!
|
||||
{{{stroke_a, Dw}, {last, Dw}, {cond_empty, dir_empty}}, 2}, // P 0=Dw MI>2 -=Dw !!!
|
||||
{{{stroke_a, Dw}, {stroke_b, Lw}, {cond_empty, dir_empty}}, 2}, // Q 0=Dw MI>2 1=Lw
|
||||
{{{stroke_a, DR}, {cond_empty, dir_empty}, {cond_empty, dir_empty}}, 1}, // R 0=DR MI=1
|
||||
{{{stroke_a, Lw}, {stroke_b, Rw}, {cond_empty, dir_empty}}, 0}, // S 0=Lw 1=Rw
|
||||
{{{stroke_a, R}, {cond_empty, dir_empty}, {cond_empty, dir_empty}}, 1}, // T 0=R MI=1
|
||||
{{{stroke_a, DL}, {stroke_b, UL}, {cond_empty, dir_empty}}, 2}, // U 0=DL 1=UL MI=2
|
||||
{{{stroke_a, DR}, {stroke_b, UR}, {cond_empty, dir_empty}}, 2}, // V 0=DR 1=UR MI=2
|
||||
{{{stroke_a, D}, {stroke_b, UR}, {stroke_c, D}}, 0}, // W 0=D 1=UR 2=D
|
||||
{{{stroke_a, Rw}, {last, Rw}, {cond_empty, dir_empty}}, 0}, // X 0=Rw MI>2 -=Rw
|
||||
{{{stroke_a, DL}, {cond_empty, dir_empty}, {cond_empty, dir_empty}}, 1}, // Y 0=DL MI=1
|
||||
{{{stroke_a, Rw}, {stroke_b, DL}, {cond_empty, dir_empty}}, 0}, // Z 0=Rw 1=DL
|
||||
|
||||
// Erase 0=UR MI!1 1=L
|
||||
};
|
||||
Reference in New Issue
Block a user