Scripting: add qr command

This commit is contained in:
d0k3 2017-09-19 15:57:29 +02:00
parent 1f2d6a78f2
commit 680c809d76
2 changed files with 28 additions and 3 deletions

View File

@ -12,7 +12,11 @@
# Unknown commands lead to script abort (remove the '#' below to test) # Unknown commands lead to script abort (remove the '#' below to test)
# iamunknown test test # iamunknown test test
# 'ask' COMMAND / (-o/-s) SWITCHES # 'qr' COMMAND
# The 'qr' command does the same as the echo command, but also displays a QR code on the top screen
qr "Scan for cool stuff!" https://github.com/d0k3/GodMode9
# 'ask' COMMAND
# The 'ask' command is similar to the 'echo' command, but will allow the user to abort # The 'ask' command is similar to the 'echo' command, but will allow the user to abort
# Note that normally any failed command (like a negative user response on 'ask') will result in script abort # Note that normally any failed command (like a negative user response on 'ask') will result in script abort
ask "Continue running this script?" ask "Continue running this script?"

View File

@ -9,6 +9,7 @@
#include "keydbutil.h" #include "keydbutil.h"
#include "filetype.h" #include "filetype.h"
#include "bootfirm.h" #include "bootfirm.h"
#include "qrcodegen.h"
#include "firm.h" #include "firm.h"
#include "power.h" #include "power.h"
#include "vff.h" #include "vff.h"
@ -49,6 +50,7 @@
typedef enum { typedef enum {
CMD_ID_NONE = 0, CMD_ID_NONE = 0,
CMD_ID_ECHO, CMD_ID_ECHO,
CMD_ID_QR,
CMD_ID_ASK, CMD_ID_ASK,
CMD_ID_INPUT, CMD_ID_INPUT,
CMD_ID_FILESEL, CMD_ID_FILESEL,
@ -74,7 +76,8 @@ typedef enum {
CMD_ID_BOOT, CMD_ID_BOOT,
CMD_ID_SWITCHSD, CMD_ID_SWITCHSD,
CMD_ID_REBOOT, CMD_ID_REBOOT,
CMD_ID_POWEROFF CMD_ID_POWEROFF,
CMD_ID_BKPT
} cmd_id; } cmd_id;
typedef struct { typedef struct {
@ -91,6 +94,7 @@ typedef struct {
Gm9ScriptCmd cmd_list[] = { Gm9ScriptCmd cmd_list[] = {
{ CMD_ID_ECHO , "echo" , 1, 0 }, { CMD_ID_ECHO , "echo" , 1, 0 },
{ CMD_ID_QR , "qr" , 2, 0 },
{ CMD_ID_ASK , "ask" , 1, 0 }, { CMD_ID_ASK , "ask" , 1, 0 },
{ CMD_ID_INPUT , "input" , 2, 0 }, { CMD_ID_INPUT , "input" , 2, 0 },
{ CMD_ID_FILESEL , "filesel" , 3, 0 }, { CMD_ID_FILESEL , "filesel" , 3, 0 },
@ -116,7 +120,8 @@ Gm9ScriptCmd cmd_list[] = {
{ CMD_ID_BOOT , "boot" , 1, 0 }, { CMD_ID_BOOT , "boot" , 1, 0 },
{ CMD_ID_SWITCHSD, "switchsd", 1, 0 }, { CMD_ID_SWITCHSD, "switchsd", 1, 0 },
{ CMD_ID_REBOOT , "reboot" , 0, 0 }, { CMD_ID_REBOOT , "reboot" , 0, 0 },
{ CMD_ID_POWEROFF, "poweroff", 0, 0 } { CMD_ID_POWEROFF, "poweroff", 0, 0 },
{ CMD_ID_BKPT , "bkpt" , 0, 0 }
}; };
// global vars for preview // global vars for preview
@ -503,6 +508,18 @@ bool run_cmd(cmd_id id, u32 flags, char** argv, char* err_str) {
if (id == CMD_ID_ECHO) { if (id == CMD_ID_ECHO) {
ShowPrompt(false, argv[0]); ShowPrompt(false, argv[0]);
} }
else if (id == CMD_ID_QR) {
u8 qrcode[qrcodegen_BUFFER_LEN_MAX];
u8 temp[qrcodegen_BUFFER_LEN_MAX];
ret = qrcodegen_encodeText(argv[1], temp, qrcode, qrcodegen_Ecc_LOW,
qrcodegen_VERSION_MIN, qrcodegen_VERSION_MAX, qrcodegen_Mask_AUTO, true);
if (ret) {
memcpy(TEMP_BUFFER, ALT_SCREEN, (SCREEN_HEIGHT * SCREEN_WIDTH_ALT * 3));
DrawQrCode(ALT_SCREEN, qrcode);
ShowPrompt(false, argv[0]);
memcpy(ALT_SCREEN, TEMP_BUFFER, (SCREEN_HEIGHT * SCREEN_WIDTH_ALT * 3));
}
}
else if (id == CMD_ID_ASK) { else if (id == CMD_ID_ASK) {
ret = ShowPrompt(true, argv[0]); ret = ShowPrompt(true, argv[0]);
if (err_str) snprintf(err_str, _ERR_STR_LEN, "user abort"); if (err_str) snprintf(err_str, _ERR_STR_LEN, "user abort");
@ -723,6 +740,10 @@ bool run_cmd(cmd_id id, u32 flags, char** argv, char* err_str) {
DeinitSDCardFS(); DeinitSDCardFS();
PowerOff(); PowerOff();
} }
else if (id == CMD_ID_BKPT) {
asm("bkpt\n\t");
while(1);
}
else { // command not recognized / bad number of arguments else { // command not recognized / bad number of arguments
ret = false; ret = false;
if (err_str) snprintf(err_str, _ERR_STR_LEN, "unknown error"); if (err_str) snprintf(err_str, _ERR_STR_LEN, "unknown error");