Use software keyboard instead of string input prompt

This commit is contained in:
d0k3 2019-06-03 01:37:10 +02:00
parent ee86ffeb03
commit 40b4e3f541
7 changed files with 35 additions and 15 deletions

View File

@ -1,7 +1,6 @@
#include <stdarg.h>
#include "swkbd.h"
#include "ui.h"
#include "timer.h"
#include "hid.h"
@ -246,6 +245,9 @@ bool ShowKeyboard(char* inputstr, const u32 max_size, const char *format, ...) {
ClearScreen(BOT_SCREEN, COLOR_STD_BG);
DrawStringF(BOT_SCREEN, str_x, 20, COLOR_STD_FONT, COLOR_STD_BG, "%s", str);
// wait for all keys released
while (HID_ReadState() & BUTTON_ANY);
// handle keyboard
u32 uppercase = 0; // 1 -> uppercase once, 2 -> uppercase always
u32 scroll = 0;

View File

@ -1,6 +1,9 @@
#pragma once
#include "common.h"
#include "ui.h"
#include "touchcal.h"
// special key ids
enum {
@ -80,4 +83,6 @@ enum {
3, 30, 34, 30, 0, \
0
#define ShowKeyboardOrPrompt (TouchIsCalibrated() ? ShowKeyboard : ShowStringPrompt)
bool ShowKeyboard(char* inputstr, u32 max_size, const char *format, ...);

View File

@ -14,11 +14,14 @@ static const HID_CalibrationData default_calib = {
// so it's better to go with a sane default
};
static bool is_calibrated = false;
static bool SetCalibrationDefaults(void)
{
// Hardcoding this isn't ideal but it's better than
// leaving the system without any state to work with
is_calibrated = false; // no, this is not proper calibration
return HID_SetCalibrationData(&default_calib, 1, SCREEN_WIDTH_BOT, SCREEN_HEIGHT);
}
@ -70,7 +73,8 @@ bool ShowTouchCalibrationDialog(void)
}
}
return HID_SetCalibrationData(calibrations, countof(dot_positions), SCREEN_WIDTH_BOT, SCREEN_HEIGHT);
is_calibrated = HID_SetCalibrationData(calibrations, countof(dot_positions), SCREEN_WIDTH_BOT, SCREEN_HEIGHT);
return is_calibrated;
}
bool CalibrateTouchFromFlash(void) {
@ -106,5 +110,10 @@ bool CalibrateTouchFromFlash(void) {
data[i].screen_y = (((int)ts_data[base + 5]) * SCREEN_HEIGHT) / 192;
}
return HID_SetCalibrationData(data, 2, SCREEN_WIDTH_BOT, SCREEN_HEIGHT);
is_calibrated = HID_SetCalibrationData(data, 2, SCREEN_WIDTH_BOT, SCREEN_HEIGHT);
return is_calibrated;
}
bool TouchIsCalibrated(void) {
return is_calibrated;
}

View File

@ -4,3 +4,4 @@
bool ShowTouchCalibrationDialog(void);
bool CalibrateTouchFromFlash(void);
bool TouchIsCalibrated(void);

View File

@ -10,6 +10,7 @@
#include "sdmmc.h"
#include "ff.h"
#include "ui.h"
#include "swkbd.h"
#define SKIP_CUR (1UL<<10)
#define OVERWRITE_CUR (1UL<<11)
@ -625,7 +626,7 @@ bool PathMoveCopy(const char* dest, const char* orig, u32* flags, bool move) {
// check & fix destination == origin
while (strncasecmp(ldest, lorig, 255) == 0) {
if (!ShowStringPrompt(dname, 255 - (dname - ldest), "%s\nDestination equals origin\nChoose another name?", deststr))
if (!ShowKeyboardOrPrompt(dname, 255 - (dname - ldest), "%s\nDestination equals origin\nChoose another name?", deststr))
return false;
}
@ -641,7 +642,7 @@ bool PathMoveCopy(const char* dest, const char* orig, u32* flags, bool move) {
"Destination already exists:\n%s", deststr);
if (user_select == 1) {
do {
if (!ShowStringPrompt(dname, 255 - (dname - ldest), "Choose new destination name"))
if (!ShowKeyboardOrPrompt(dname, 255 - (dname - ldest), "Choose new destination name"))
return false;
} while (fa_stat(ldest, NULL) == FR_OK);
} else if (user_select == 2) {

View File

@ -3,6 +3,7 @@
#include "memmap.h"
#include "support.h"
#include "ui.h"
#include "swkbd.h"
#include "hid.h"
#include "swkbd.h"
#include "touchcal.h"
@ -450,7 +451,7 @@ u32 SdFormatMenu(const char* slabel) {
else cluster_size = cluster_size_table[user_select];
snprintf(label, 16, "0:%s", (slabel && *slabel) ? slabel : "GM9SD");
if (!ShowStringPrompt(label + 2, 11 + 1, "Format SD card (%lluMB)?\nEnter label:", sdcard_size_mb))
if (!ShowKeyboardOrPrompt(label + 2, 11 + 1, "Format SD card (%lluMB)?\nEnter label:", sdcard_size_mb))
return 1;
if (!FormatSDCard(emunand_size_mb, cluster_size, label)) {
@ -752,7 +753,7 @@ u32 FileHexViewer(const char* path) {
if (new_offset != (u64) -1) offset = new_offset;
} else if (user_select == 2) {
if (!found_size) *found_data = 0;
if (ShowStringPrompt((char*) found_data, 64 + 1, "Enter search string below.\n(R+X to repeat search)", (unsigned int) offset)) {
if (ShowKeyboardOrPrompt((char*) found_data, 64 + 1, "Enter search string below.\n(R+X to repeat search)", (unsigned int) offset)) {
found_size = strnlen((char*) found_data, 64);
found_offset = FileFindData(path, found_data, found_size, offset);
if (found_offset == (u32) -1) {
@ -2051,7 +2052,7 @@ u32 GodMode(int entrypoint) {
AutoEmuNandBase(true);
InitNandCrypto(true); // (entrypoint != ENTRY_B9S);
InitExtFS();
CalibrateTouchFromFlash(); // !!! this may need some further checking
CalibrateTouchFromFlash();
// custom font handling
if (CheckSupportFile("font.pbm")) {
@ -2218,7 +2219,7 @@ u32 GodMode(int entrypoint) {
char searchstr[256];
snprintf(searchstr, 256, (user_select == srch_t) ? "*.tmd" : "*");
TruncateString(namestr, curr_entry->name, 20, 8);
if ((user_select == srch_t) || ShowStringPrompt(searchstr, 256, "Search %s?\nEnter search below.", namestr)) {
if ((user_select == srch_t) || ShowKeyboardOrPrompt(searchstr, 256, "Search %s?\nEnter search below.", namestr)) {
SetFSSearch(searchstr, curr_entry->path, (user_select == srch_t));
snprintf(current_path, 256, "Z:");
GetDirContents(current_dir, current_path);
@ -2469,7 +2470,7 @@ u32 GodMode(int entrypoint) {
char namestr[20+1];
TruncateString(namestr, curr_entry->name, 20, 12);
snprintf(newname, 255, "%s", curr_entry->name);
if (ShowStringPrompt(newname, 256, "Rename %s?\nEnter new name below.", namestr)) {
if (ShowKeyboardOrPrompt(newname, 256, "Rename %s?\nEnter new name below.", namestr)) {
if (!PathRename(curr_entry->path, newname))
ShowPrompt(false, "Failed renaming path:\n%s", namestr);
else {
@ -2486,7 +2487,7 @@ u32 GodMode(int entrypoint) {
char ename[256];
u64 fsize = 0;
snprintf(ename, 255, (type == 1) ? "newdir" : "dummy.bin");
if ((ShowStringPrompt(ename, 256, "Create a new %s here?\nEnter name below.", typestr)) &&
if ((ShowKeyboardOrPrompt(ename, 256, "Create a new %s here?\nEnter name below.", typestr)) &&
((type != 2) || ((fsize = ShowNumberPrompt(0, "Create a new %s here?\nEnter file size below.", typestr)) != (u64) -1))) {
if (((type == 1) && !DirCreate(current_path, ename)) ||
((type == 2) && !FileCreateDummy(current_path, ename, fsize))) {
@ -2514,14 +2515,14 @@ u32 GodMode(int entrypoint) {
int reboot = ++n_opt;
int scripts = ++n_opt;
int payloads = ++n_opt;
int more = ++n_opt;
int test = ++n_opt;
int more = ++n_opt;
if (poweroff > 0) optionstr[poweroff - 1] = "Poweroff system";
if (reboot > 0) optionstr[reboot - 1] = "Reboot system";
if (scripts > 0) optionstr[scripts - 1] = "Scripts...";
if (payloads > 0) optionstr[payloads - 1] = "Payloads...";
if (more > 0) optionstr[more - 1] = "More...";
if (test > 0) optionstr[test - 1] = "Testing...";
if (more > 0) optionstr[more - 1] = "More...";
int user_select = 0;
while ((user_select = ShowSelectPrompt(n_opt, optionstr, "%s button pressed.\nSelect action:", buttonstr)) &&

View File

@ -12,6 +12,7 @@
#include "sha.h"
#include "hid.h"
#include "ui.h"
#include "swkbd.h"
#include "png.h"
#include "ips.h"
#include "bps.h"
@ -1012,7 +1013,7 @@ bool run_cmd(cmd_id id, u32 flags, char** argv, char* err_str) {
char* var = get_var(argv[1], NULL);
strncpy(input, var, _VAR_CNT_LEN);
input[_VAR_CNT_LEN - 1] = '\0';
ret = ShowStringPrompt(input, _VAR_CNT_LEN, "%s", argv[0]);
ret = ShowKeyboardOrPrompt(input, _VAR_CNT_LEN, "%s", argv[0]);
if (ret) set_var(argv[1], "");
if (err_str) snprintf(err_str, _ERR_STR_LEN, "user abort");
if (ret) {