Skip to content

Commit

Permalink
Add new SMB command to send custom character to OLED.
Browse files Browse the repository at this point in the history
  • Loading branch information
jose1711 committed Mar 10, 2023
1 parent 3fda2d6 commit c7acb8f
Show file tree
Hide file tree
Showing 7 changed files with 55 additions and 4 deletions.
Binary file modified firmware/beta_1.1.2_duckyscript3img.dfu
Binary file not shown.
15 changes: 15 additions & 0 deletions firmware/code_duckyscript3/Src/ds3_vm.c
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ uint16_t rand_min, rand_max;
uint16_t loop_size;
uint8_t epilogue_actions;

extern SSD1306_t SSD1306;

extern uint8_t hid_tx_buf[HID_TX_BUF_SIZE];

typedef struct
Expand Down Expand Up @@ -598,6 +600,19 @@ void execute_instruction(uint16_t curr_pc, ds3_exe_result* exe, uint8_t keynum)
ssd1306_UpdateScreen();
f_close(&image_file);
}
else if (this_opcode == OP_SMB)
{
char* str_buf = make_str(op_data);
for (int y=0; y<strlen(str_buf); y++) {
if (y>9) break;
for (int x=0; x<6; x++) {
if (((str_buf[y] - '0') >> (5-x)) & 0x1) {
ssd1306_DrawPixel(SSD1306.CurrentX+x, SSD1306.CurrentY+y, White);
}
}
}
SSD1306.CurrentX += 6;
}

else if(this_opcode == OP_OLU)
{
Expand Down
2 changes: 1 addition & 1 deletion firmware/code_duckyscript3/Src/ssd1306.c
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
static uint8_t SSD1306_Buffer[SSD1306_WIDTH * SSD1306_HEIGHT / 8];

// Een scherm-object om lokaal in te werken
static SSD1306_t SSD1306;
SSD1306_t SSD1306;

uint8_t i2c_status;
uint8_t last_dim;
Expand Down
2 changes: 1 addition & 1 deletion pc_software/duckyscript3/ds_syntax_check.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z', '{', '|', '}', '~']

mouse_commands = [cmd_LMOUSE, cmd_RMOUSE, cmd_MMOUSE, cmd_MOUSE_MOVE, cmd_MOUSE_WHEEL]
ignored_but_valid_commands = [cmd_UARTPRINT, cmd_LCR, cmd_REM, cmd_DP_SLEEP, cmd_PREV_PROFILE, cmd_NEXT_PROFILE, cmd_INJECT_MOD, cmd_SEND_HID, cmd_IMG]
ignored_but_valid_commands = [cmd_UARTPRINT, cmd_LCR, cmd_REM, cmd_DP_SLEEP, cmd_PREV_PROFILE, cmd_NEXT_PROFILE, cmd_INJECT_MOD, cmd_SEND_HID, cmd_IMG, cmd_SMB]

def is_ignored_but_valid_command(ducky_line):
for item in ignored_but_valid_commands:
Expand Down
1 change: 1 addition & 0 deletions pc_software/duckyscript3/keywords.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
cmd_DP_SLEEP = "DP_SLEEP"
cmd_SEND_HID = "SEND_HID"
cmd_IMG = "IMG"
cmd_SMB = "SMB"
cmd_PREV_PROFILE = "PREV_PROFILE"
cmd_NEXT_PROFILE = "NEXT_PROFILE"
cmd_GOTO_PROFILE = "GOTO_PROFILE"
Expand Down
7 changes: 5 additions & 2 deletions pc_software/duckyscript3/make_bytecode.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@
OP_SLEEP = ("SLEEP", 47)
OP_HID = ("HID", 48)
OP_IMG = ("IMG", 49)
OP_SMB = ("SMB", 50)

arith_lookup = {
"Eq" : OP_EQ,
Expand Down Expand Up @@ -533,7 +534,7 @@ def make_dsb(program_listing):
this_instruction['opcode'] = OP_CALL
this_instruction['oparg'] = label_dict[func_lookup[fun_name]['fun_start']]
assembly_listing.append(this_instruction)
elif this_line.startswith(cmd_STRING) or first_word == cmd_OLED_PRINT or first_word == cmd_SEND_HID or first_word == cmd_IMG:
elif this_line.startswith(cmd_STRING) or first_word in (cmd_OLED_PRINT, cmd_SEND_HID, cmd_IMG, cmd_SMB):
str_content = this_line.split(' ', 1)[-1]
if str_content not in str_lookup:
str_lookup[str_content] = lnum
Expand All @@ -547,6 +548,8 @@ def make_dsb(program_listing):
this_instruction['opcode'] = OP_HID
elif first_word == cmd_IMG:
this_instruction['opcode'] = OP_IMG
elif first_word == cmd_SMB:
this_instruction['opcode'] = OP_SMB
this_instruction['oparg'] = f"STR@{str_lookup[str_content]}"
assembly_listing.append(this_instruction)
elif first_word == cmd_DELAY:
Expand Down Expand Up @@ -695,7 +698,7 @@ def make_dsb(program_listing):
label_to_addr_dict[item['label']] = item['addr']

for item in assembly_listing:
if item['opcode'] == OP_STR or item['opcode'] == OP_STRLN or item['opcode'] == OP_OLP or item['opcode'] == OP_HID or item['opcode'] == OP_IMG:
if item['opcode'] in (OP_STR, OP_STRLN, OP_OLP, OP_HID, OP_IMG, OP_SMB):
str_lnum = int(item['oparg'].replace('STR@', ''))
for sssss in str_list:
if sssss['lnum'] == str_lnum:
Expand Down
32 changes: 32 additions & 0 deletions txt2symbol.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
#!/usr/bin/env python
"""
example character definition, note that only the first
10 lines are converted, width may not exceed 6 characters
character = '''
oo
o o
oo
'''
"""
character = '''
o o
o
ooo
o o
o
o
o o
ooo
'''

output = ''
for line in character.splitlines()[1:]:
bits = 0
for pos, x in enumerate(line):
if x != ' ':
bits |= (x != '') << (5-pos)
output += chr(bits + 48)

print(f'SMB {output[:10]}')

0 comments on commit c7acb8f

Please sign in to comment.