Skip to content

Commit

Permalink
Merge branch 'main' into port-gamepad
Browse files Browse the repository at this point in the history
  • Loading branch information
Brycey92 committed Nov 1, 2023
2 parents 780f4f8 + 6a09051 commit af28e49
Show file tree
Hide file tree
Showing 29 changed files with 462 additions and 1,649 deletions.
2 changes: 1 addition & 1 deletion .vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
"type": "cppdbg",
"request": "launch",
"program": "${workspaceFolder}/swadge_emulator",
"args": ["-t"],
"args": ["-t", "-m", "Main Menu"],
"stopAtEntry": false,
"cwd": "${workspaceFolder}",
"environment": [],
Expand Down
Binary file added assets/batt/batt1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/batt/batt2.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/batt/batt3.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/batt/batt4.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/batt/usb.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/credits.mid
Binary file not shown.
Binary file added assets/menu/item.mid
Binary file not shown.
6 changes: 2 additions & 4 deletions emulator/src/extensions/modes/ext_modes.c
Original file line number Diff line number Diff line change
Expand Up @@ -25,15 +25,14 @@
#include "jukebox.h"
#include "lumberjack.h"
#include "mainMenu.h"
#include "marbles.h"
#include "mode_paint.h"
#include "mode_ray.h"
#include "paint_share.h"
#include "pong.h"
#include "pushy.h"
#include "soko.h"
#include "touchTest.h"
#include "tunernome.h"
#include "mode_credits.h"

//==============================================================================
// Defines
Expand Down Expand Up @@ -69,14 +68,13 @@ static swadgeMode_t* allSwadgeModes[] = {
&jukeboxMode,
&lumberjackMode,
&mainMenuMode,
&marblesMode,
&modePaint,
&pongMode,
&pushyMode,
&rayMode,
&sokoMode,
&touchTestMode,
&tunernomeMode,
&modeCredits,
};
// clang-format on

Expand Down
47 changes: 45 additions & 2 deletions emulator/src/extensions/touch/ext_touch.c
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ static void calculateTouch(int32_t x, int32_t y, int32_t* angle, int32_t* radius
static bool updateTouch(int32_t x, int32_t y, bool clicked);

static bool touchInit(emuArgs_t* emuArgs);
static int32_t touchKey(uint32_t key, bool down);
static bool touchMouseMove(int32_t x, int32_t y, mouseButton_t buttonMask);
static bool touchMouseButton(int32_t x, int32_t y, mouseButton_t button, bool down);
static void touchRender(uint32_t winW, uint32_t winH, const emuPane_t* pane, uint8_t numPanes);
Expand All @@ -87,10 +88,11 @@ typedef struct
int32_t lastHoverX;
int32_t lastHoverY;

uint32_t keyState;

int32_t lastTouchPhi;
int32_t lastTouchRadius;
int32_t lastTouchIntensity;
buttonBit_t lastTouchButtons;

uint32_t paneX;
uint32_t paneY;
Expand All @@ -107,7 +109,7 @@ emuExtension_t touchEmuCallback = {
.fnInitCb = touchInit,
.fnPreFrameCb = NULL,
.fnPostFrameCb = NULL,
.fnKeyCb = NULL,
.fnKeyCb = touchKey,
.fnMouseMoveCb = touchMouseMove,
.fnMouseButtonCb = touchMouseButton,
.fnRenderCb = touchRender,
Expand Down Expand Up @@ -254,6 +256,47 @@ static bool touchInit(emuArgs_t* emuArgs)
}
}

static int32_t touchKey(uint32_t key, bool down)
{
const int32_t phiMap[] = {90, 0, 180, 270};

if (key < '1' || key > '4')
{
// Do not consume event, we only want 1 to 4
return 0;
}

int keyNum = (key - '1');
// Handle the key states separately so rolling over them works more or less how one might expect
if (down && !(emuTouch.keyState & (1 << keyNum)))
{
emuTouch.keyState |= (1 << keyNum);
}
else if (!down && (emuTouch.keyState & (1 << keyNum)))
{
emuTouch.keyState &= ~(1 << keyNum);
}

if (emuTouch.keyState)
{
for (int i = 0; i < 4; i++)
{
if (emuTouch.keyState & (1 << i))
{
emulatorSetTouchJoystick(phiMap[i], 1024, emuTouch.lastTouchIntensity);
break;
}
}
}
else
{
emulatorSetTouchJoystick(0, 0, 0);
}

// Consume event
return -1;
}

static bool touchMouseMove(int32_t x, int32_t y, mouseButton_t buttonMask)
{
return updateTouch(x, y, (buttonMask & EMU_MOUSE_LEFT) == EMU_MOUSE_LEFT);
Expand Down
6 changes: 2 additions & 4 deletions main/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ idf_component_register(SRCS "swadge2024.c"
"modes/breakout/starfield.c"
"modes/breakout/tilemap.c"
"modes/colorchord/colorchord.c"
"modes/credits/mode_credits.c"
"modes/dance/dance.c"
"modes/dance/portableDance.c"
"modes/demo/demoMode.c"
Expand All @@ -37,7 +38,6 @@ idf_component_register(SRCS "swadge2024.c"
"modes/lumberjack/lumberjackEntity.c"
"modes/lumberjack/lumberjackPlayer.c"
"modes/mainMenu/mainMenu.c"
"modes/marbles/marbles.c"
"modes/mfpaint/mode_paint.c"
"modes/mfpaint/paint_brush.c"
"modes/mfpaint/paint_common.c"
Expand All @@ -56,7 +56,6 @@ idf_component_register(SRCS "swadge2024.c"
"modes/platformer/mode_platformer.c"
"modes/platformer/plTilemap.c"
"modes/platformer/plSoundManager.c"
"modes/pong/pong.c"
"modes/pushy/pushy.c"
"modes/quickSettings/menuQuickSettingsRenderer.c"
"modes/quickSettings/quickSettings.c"
Expand Down Expand Up @@ -124,17 +123,16 @@ idf_component_register(SRCS "swadge2024.c"
"./modes/accelTest"
"./modes/breakout"
"./modes/colorchord"
"./modes/credits"
"./modes/dance"
"./modes/demo"
"./modes/factoryTest"
"./modes/gamepad"
"./modes/jukebox"
"./modes/lumberjack"
"./modes/mainMenu"
"./modes/marbles"
"./modes/mfpaint"
"./modes/platformer"
"./modes/pong"
"./modes/pushy"
"./modes/quickSettings"
"./modes/ray"
Expand Down
2 changes: 1 addition & 1 deletion main/menu/menu.c
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,6 @@ void removeSingleItemFromMenu(menu_t* menu, const char* label)
menuItem_t* item = listNode->val;
if (item->label == label)
{
removeEntry(menu->items, listNode);
if (menu->currentItem == listNode)
{
if (NULL != listNode->next)
Expand All @@ -231,6 +230,7 @@ void removeSingleItemFromMenu(menu_t* menu, const char* label)
menu->currentItem = listNode->prev;
}
}
removeEntry(menu->items, listNode);
free(item);
return;
}
Expand Down
12 changes: 7 additions & 5 deletions main/menu/menu.h
Original file line number Diff line number Diff line change
Expand Up @@ -174,11 +174,13 @@ typedef struct
*/
typedef struct _menu_t
{
const char* title; ///< The title for this menu
menuCb cbFunc; ///< The callback function to call when menu items are selected
list_t* items; ///< A list_t of menu items to display
node_t* currentItem; ///< The currently selected menu item
menu_t* parentMenu; ///< The parent menu, may be NULL if this is not a submenu
const char* title; ///< The title for this menu
menuCb cbFunc; ///< The callback function to call when menu items are selected
list_t* items; ///< A list_t of menu items to display
node_t* currentItem; ///< The currently selected menu item
menu_t* parentMenu; ///< The parent menu, may be NULL if this is not a submenu
int32_t batteryReadTimer; ///< A timer to read the battery every 10s
int batteryLevel; ///< The current battery measurement
} menu_t;

/// @brief A string used to return to super-menus that says "Back"
Expand Down
44 changes: 44 additions & 0 deletions main/menu/menuLogbookRenderer.c
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
//==============================================================================

#include <esp_random.h>
#include "hdw-battmon.h"
#include "menuLogbookRenderer.h"
#include "menu_utils.h"
#include "hdw-tft.h"
Expand Down Expand Up @@ -57,6 +58,12 @@ menuLogbookRenderer_t* initMenuLogbookRenderer(font_t* menuFont)
loadWsg("mnuArrow.wsg", &renderer->arrow, false);
loadWsg("mnuArrowS.wsg", &renderer->arrowS, false);

// Load battery images
loadWsg("batt1.wsg", &renderer->batt[0], false);
loadWsg("batt2.wsg", &renderer->batt[1], false);
loadWsg("batt3.wsg", &renderer->batt[2], false);
loadWsg("batt4.wsg", &renderer->batt[3], false);

// Initialize LEDs
for (uint16_t idx = 0; idx < CONFIG_NUM_LEDS; idx++)
{
Expand All @@ -78,6 +85,10 @@ void deinitMenuLogbookRenderer(menuLogbookRenderer_t* renderer)
{
freeWsg(&renderer->arrow);
freeWsg(&renderer->arrowS);
freeWsg(&renderer->batt[0]);
freeWsg(&renderer->batt[1]);
freeWsg(&renderer->batt[2]);
freeWsg(&renderer->batt[3]);
free(renderer);
}

Expand Down Expand Up @@ -207,6 +218,14 @@ static void drawMenuText(menuLogbookRenderer_t* renderer, const char* text, int1
*/
void drawMenuLogbook(menu_t* menu, menuLogbookRenderer_t* renderer, int64_t elapsedUs)
{
// Read battery every 10s
menu->batteryReadTimer -= elapsedUs;
if (0 >= menu->batteryReadTimer)
{
menu->batteryReadTimer += 10000000;
menu->batteryLevel = readBattmon();
}

// For each LED
for (uint16_t idx = 0; idx < CONFIG_NUM_LEDS; idx++)
{
Expand Down Expand Up @@ -284,6 +303,9 @@ void drawMenuLogbook(menu_t* menu, menuLogbookRenderer_t* renderer, int64_t elap
drawText(renderer->font, c542, menu->title, x, y);
y += renderer->font->height + Y_SECTION_MARGIN;

// Shift the text a little after drawing the title
x = 10;

if (menu->items->length > ITEMS_PER_PAGE)
{
// Draw UP page indicator
Expand Down Expand Up @@ -325,4 +347,26 @@ void drawMenuLogbook(menu_t* menu, menuLogbookRenderer_t* renderer, int64_t elap
int16_t arrowY = y + PAGE_ARROW_Y_OFFSET;
drawWsg(&renderer->arrow, arrowX, arrowY, false, false, 90);
}

// Draw the battery indicator depending on the last read value
wsg_t* toDraw = NULL;
// 872 is full
if (menu->batteryLevel == 0 || menu->batteryLevel > 741)
{
toDraw = &renderer->batt[3];
}
else if (menu->batteryLevel > 695)
{
toDraw = &renderer->batt[2];
}
else if (menu->batteryLevel > 652)
{
toDraw = &renderer->batt[1];
}
else // 452 is dead
{
toDraw = &renderer->batt[0];
}

drawWsg(toDraw, 212, 3, false, false, 0);
}
1 change: 1 addition & 0 deletions main/menu/menuLogbookRenderer.h
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ typedef struct
font_t* font; ///< The font to render the menu with
led_t leds[CONFIG_NUM_LEDS]; ///< An array with the RGB LED state to be output
menuLed_t ledTimers[CONFIG_NUM_LEDS]; ///< An array with the LED timers for animation
wsg_t batt[4];
} menuLogbookRenderer_t;

menuLogbookRenderer_t* initMenuLogbookRenderer(font_t* menuFont);
Expand Down
2 changes: 1 addition & 1 deletion main/modes/colorchord/colorchord.c
Original file line number Diff line number Diff line change
Expand Up @@ -254,7 +254,7 @@ void colorchordMainLoop(int64_t elapsedUs __attribute__((unused)))
}

// Draw reminder text
const char exitText[] = "Hold Select to Exit";
const char exitText[] = "Hold Menu to Exit";
int16_t exitWidth = textWidth(&colorchord->ibm_vga8, exitText);
drawText(&colorchord->ibm_vga8, c555, exitText, (TFT_WIDTH - exitWidth) / 2,
TFT_HEIGHT - colorchord->ibm_vga8.height - TEXT_Y);
Expand Down
Loading

0 comments on commit af28e49

Please sign in to comment.