Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Live range display #8

Merged
merged 38 commits into from
Apr 13, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
38 commits
Select commit Hold shift + click to select a range
5134810
Add Vim swap files to .gitignore
kerrymilan Apr 9, 2023
b12ac3b
WIP: Add page containing live numeric x/y values
kerrymilan Apr 9, 2023
5846a43
WIP: Add graphical display; move out of main.c
kerrymilan Apr 9, 2023
f5930d2
Implement graphical display of live values
kerrymilan Apr 9, 2023
edea126
Increase history size from 1024 to 2048
kerrymilan Apr 9, 2023
1e86095
Add help text and Z toggle
kerrymilan Apr 9, 2023
dcbd761
Add repo_url to live display page
kerrymilan Apr 9, 2023
1bd673e
Fix help label
kerrymilan Apr 9, 2023
f2fbd0c
Cycle through ranges with D pad and L/R
kerrymilan Apr 9, 2023
65bfafb
Fix history pixel offsets to align with middle of active cursor
kerrymilan Apr 9, 2023
bddd4b4
Add button display to live page
kerrymilan Apr 9, 2023
5b78f89
Reduce history count back to 1,024 due to eliminate flickering on con…
kerrymilan Apr 9, 2023
52bee52
Display label on top of Hori guides
kerrymilan Apr 9, 2023
ccb9bb0
Only update history if values changed
kerrymilan Apr 9, 2023
4cae3c9
Fix bounds check issue
kerrymilan Apr 9, 2023
5116889
Fix line breaks in help text
kerrymilan Apr 9, 2023
54adc8a
Free button images when exiting
kerrymilan Apr 10, 2023
507b434
Add Oscilloscope display screen
kerrymilan Apr 10, 2023
4b7fe1a
Fix y axis values
kerrymilan Apr 10, 2023
d112a7f
Fix x/y format on live range display
kerrymilan Apr 10, 2023
a604eec
Remove button display
kerrymilan Apr 10, 2023
4ec6916
Use green for all comparisons; don't compute comparison color on each…
kerrymilan Apr 10, 2023
8f78d5d
Use graphics_draw_pixel instead of graphics_draw_pixel_trans
kerrymilan Apr 10, 2023
ad7ff73
Don't clear history when toggling history display; Clear history with…
kerrymilan Apr 10, 2023
e2429a8
Move controls to separate help page; fix number formatting in help text
kerrymilan Apr 10, 2023
84a2915
Use graphics_draw_line instead of draw_aa_line in oscilloscope view
kerrymilan Apr 10, 2023
d12f188
Call controller_scan() before get_keys_pressed() to avoid reading uni…
kerrymilan Apr 10, 2023
e7bb34d
Oscilloscope page updates
kerrymilan Apr 10, 2023
0019fcd
Center x/y display on live range page
kerrymilan Apr 10, 2023
505f947
Additional live display updates
kerrymilan Apr 11, 2023
cbd3623
Oscilloscope fixes
kerrymilan Apr 11, 2023
b02675f
make range draw funcs take an x offset arg
wermipls Apr 12, 2023
9b2bb8b
Merge remote-tracking branch 'upstream/x-offset' into main
kerrymilan Apr 12, 2023
4d0c12e
Merge branch 'main' into live-range-display
kerrymilan Apr 12, 2023
8fd41ee
Center oscilloscope plots vertically on screen
kerrymilan Apr 13, 2023
f170b97
Add offset variables; center plots horizontally
kerrymilan Apr 13, 2023
031d447
Live range display cleanup
kerrymilan Apr 13, 2023
8f29f3a
Enable zoomout on live display
kerrymilan Apr 13, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@ build/
.tmp/
*.z64
fs/gfx/*.sprite
.*.sw*
3 changes: 2 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ $(FS): $(wildcard fs/*) $(wildcard gfx/*)
$(N64_ROOTDIR)/bin/mksprite 32 gfx/stick_6.png fs/gfx/stick_6.sprite
$(N64_ROOTDIR)/bin/mksprite 32 gfx/stick_7.png fs/gfx/stick_7.sprite
$(N64_ROOTDIR)/bin/mksprite 32 gfx/stick_neutral.png fs/gfx/stick_neutral.sprite
$(N64_ROOTDIR)/bin/mksprite 32 gfx/point.png fs/gfx/point.sprite
$(N64_MKDFS) $@ fs

$(BUILD_DIR)/$(NAME).elf: $(OBJS)
Expand All @@ -42,4 +43,4 @@ clean:
rm -f $(BUILD_DIR)/* *.z64
.PHONY: clean

-include $(wildcard $(BUILD_DIR)/*.d)
-include $(wildcard $(BUILD_DIR)/*.d)
Binary file added gfx/point.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
62 changes: 58 additions & 4 deletions src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
#include <stdlib.h>

#include "range_test.h"
#include "range_live.h"
#include "oscilloscope.h"
#include "text.h"
#include "colors.h"
#include "input.h"
Expand All @@ -14,6 +16,8 @@ enum Screen
SCR_ABOUT,
SCR_RANGE_TEST,
SCR_RANGE_RESULT,
SCR_LIVE,
SCR_OSCOPE,
};

void reset_handler(exception_t *ex)
Expand Down Expand Up @@ -65,6 +69,8 @@ int main(void)
"Range test (3 samples)",
"Range test (5 samples)",
"Display last range result",
"Live range display",
"Oscilloscope display",
"Help",
"About",
};
Expand Down Expand Up @@ -107,9 +113,15 @@ int main(void)
}
break;
case 4:
current_screen = SCR_HELP;
current_screen = SCR_LIVE;
break;
case 5:
current_screen = SCR_OSCOPE;
break;
case 6:
current_screen = SCR_HELP;
break;
case 7:
current_screen = SCR_ABOUT;
break;
}
Expand Down Expand Up @@ -167,9 +179,12 @@ int main(void)
case SCR_HELP:
const char *page_names[] = {
"Basic controls",
"Basic controls cont.",
"Range testing",
"Range testing cont.",
"Range testing cont.",
"Live range display",
"Oscilloscope display",
};
const int pages = sizeof(page_names) / sizeof(char*);
int page = 0;
Expand Down Expand Up @@ -221,6 +236,24 @@ int main(void)
"* Start - return to main menu\n", ALIGN_LEFT);
break;
case 1:
text_set_font(FONT_BOLD);
text_draw_wordwrap(ctx, 32, 44 + (11 * 0), 320-64,
"On the live range testing screen:\n");
text_set_font(FONT_MEDIUM);
text_draw_wordwrap(ctx, 32, 44 + (11 * 1), 320-64,
"* A - toggle history display\n"
"* B - clear history display\n"
"* Z - change zoom\n"
"* L/R, D-Pad Left/Right - cycle example ranges\n"
"* Start - return to main menu\n");
text_set_font(FONT_BOLD);
text_draw_wordwrap(ctx, 32, 44 + (11 * 7), 320-64,
"On the oscilloscope screen:\n");
text_set_font(FONT_MEDIUM);
text_draw_wordwrap(ctx, 32, 44 + (11 * 8), 320-64,
"* Start - return to main menu\n");
break;
case 2:
text_draw_wordwrap(ctx, 32, 44, 320-64,
"User can take one or more measurements of the "
"analog values. More measurements help even out "
Expand All @@ -236,7 +269,7 @@ int main(void)
"to judge the controller's range."
);
break;
case 2:
case 3:
text_draw_wordwrap(ctx, 32, 44, 320-64,
"The measurement display can also be overriden with "
"one of the example ones, to let user view the expected "
Expand All @@ -250,7 +283,7 @@ int main(void)
"overriden by user."
);
break;
case 3:
case 4:
text_draw_wordwrap(ctx, 32, 44, 320-64,
"Absolute analog values for each notch are displayed "
"on the right of the screen, as well as angles "
Expand All @@ -266,6 +299,21 @@ int main(void)
"magnitude diagonals on original N64 controllers."
);
break;
case 5:
text_draw_wordwrap(ctx, 32, 44, 320-64,
"Displays live X/Y values on a graph using ideal "
"OEM or Hori values as an overlay. Displays "
"the most recent 1024 values in blue, and the "
"current X/Y values as integers.\n\n"
);
break;
case 6:
text_draw_wordwrap(ctx, 32, 44, 320-64,
"Displays live X/Y values on an oscilloscope-style "
"display. Useful for identifying skips and "
"snapback issues.\n\n"
);
break;
}


Expand Down Expand Up @@ -328,6 +376,12 @@ int main(void)
case SCR_RANGE_RESULT:
display_angles(result, sample_count);
current_screen = SCR_MAIN_MENU;
case SCR_LIVE:
display_live_ranges();
current_screen = SCR_MAIN_MENU;
case SCR_OSCOPE:
display_oscilloscope();
current_screen = SCR_MAIN_MENU;
}
}
}
}
114 changes: 114 additions & 0 deletions src/oscilloscope.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,114 @@
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <libdragon.h>

#include "range_test.h"
#include "oscilloscope.h"
#include "drawing.h"
#include "text.h"
#include "colors.h"
#include "input.h"

void display_oscilloscope() {
int line_height = 11,
sz_history = 230,
x_offset = 24,
y_offset1 = 70,
y_offset2 = 170,
lbl_x_offset = 282,
lbl_y_offset1 = y_offset1 - (line_height / 2),
lbl_y_offset2 = y_offset2 - (line_height / 2),
count = 0;

float zoom = 0.4;
wermipls marked this conversation as resolved.
Show resolved Hide resolved
uint32_t c_blue = graphics_make_color(0, 192, 255, 255);
uint32_t c_green = graphics_make_color(64, 255, 0, 255);
struct Vec2 history[sz_history];

text_set_line_height(line_height);
display_context_t ctx;

for (;;) {
while ((ctx = display_lock()) == 0) {}
display_show(ctx);

graphics_fill_screen(ctx, COLOR_BACKGROUND);
graphics_set_color(COLOR_FOREGROUND, 0);

controller_scan();
struct controller_data cdata = get_keys_pressed();

struct Vec2 v = { cdata.c[0].x, cdata.c[0].y };

for (int i = count; i > 0; i--) {
history[i] = history[i - 1];
draw_aa_line(
ctx,
x_offset + sz_history - i,
y_offset1,
x_offset + sz_history - i,
y_offset1 + history[i].x * zoom,
c_blue
);
draw_aa_line(
ctx,
x_offset + sz_history - i,
y_offset2,
x_offset + sz_history - i,
y_offset2 + (history[i].y * -1) * zoom,
c_green
);
}

history[0] = v;
draw_aa_line(
ctx,
x_offset + sz_history,
y_offset1,
x_offset + sz_history,
y_offset1 + v.x * zoom,
c_blue
);
draw_aa_line(
ctx,
x_offset + sz_history,
y_offset2,
x_offset + sz_history,
y_offset2 + (v.y * -1) * zoom,
c_green
);

if (count < sz_history - 1) {
count++;
}

char buf[128];

text_set_font(FONT_BOLD);
snprintf(buf, sizeof(buf), "%3d", v.x);
text_draw(ctx, lbl_x_offset, lbl_y_offset1, buf, ALIGN_RIGHT);

snprintf(buf, sizeof(buf), "%3d", v.y);
text_draw(ctx, lbl_x_offset, lbl_y_offset2, buf, ALIGN_RIGHT);

text_set_font(FONT_MEDIUM);
snprintf(buf, sizeof(buf), "x");
text_draw(ctx, lbl_x_offset + 8, lbl_y_offset1, buf, ALIGN_LEFT);

snprintf(buf, sizeof(buf), "y");
text_draw(ctx, lbl_x_offset + 8, lbl_y_offset2, buf, ALIGN_LEFT);


snprintf(buf, sizeof(buf), "Oscilloscope display");
text_draw(ctx, 160, 15, buf, ALIGN_CENTER);

text_set_font(FONT_MEDIUM);
graphics_set_color(graphics_make_color(128, 128, 128, 255), 0);
text_draw(ctx, 320 - 16, 213, REPO_URL, ALIGN_RIGHT);

if (cdata.c[0].start) {
break;
}
}
}
4 changes: 4 additions & 0 deletions src/oscilloscope.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#pragma once

void display_oscilloscope();

Loading