Skip to content

Commit

Permalink
Merge pull request #8 from kerrymilan/live-range-display
Browse files Browse the repository at this point in the history
Live range display
  • Loading branch information
wermipls authored Apr 13, 2023
2 parents 64a8ba6 + 8f29f3a commit 6126231
Show file tree
Hide file tree
Showing 10 changed files with 378 additions and 18 deletions.
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;
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

0 comments on commit 6126231

Please sign in to comment.