Skip to content

Commit

Permalink
server: added reset command
Browse files Browse the repository at this point in the history
  • Loading branch information
jsm174 committed Oct 3, 2023
1 parent dc944f2 commit 80d57cb
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 11 deletions.
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,12 @@ curl -S "http://127.0.0.1:8111/update?display=dmd&image=/userdata/roms/vpinball/

For more information on custom EmulationStation scripts, refer to this [wiki](https://wiki.batocera.org/launch_a_script#emulationstation_scripting).

If you would like to clear the backglass and dmd windows, you can use the `reset` command:

```bash
curl -S "http://127.0.0.1:8111/reset" > /dev/null 2>&1
```

## Shoutouts

All the great people at the Batocera team, especially @dmanlfc and @maximumentropy!
38 changes: 30 additions & 8 deletions VPXDisplayServer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,26 +4,29 @@
#include "inc/mongoose/mongoose.h"
#include "inc/mINI/ini.h"
#include "inc/tinyxml2/tinyxml2.h"

#include <iostream>
#include <filesystem>
#include <algorithm>
#include <X11/Xlib.h>


void VPXDisplayServer::EventHandler(struct mg_connection *c, int ev, void *ev_data, void *fn_data)
{
static_cast<VPXDisplayServer*>(fn_data)->EventHandler(c, ev, ev_data);
}

void VPXDisplayServer::EventHandler(struct mg_connection *c, int ev, void *ev_data)
{
if (ev != MG_EV_HTTP_MSG)
return;

VPXDisplayServer* pServer = static_cast<VPXDisplayServer*>(fn_data);

struct mg_http_message *hm = (struct mg_http_message *) ev_data;

if (mg_http_match_uri(hm, "/update"))
pServer->UpdateRequest(c, ev_data);
UpdateRequest(c, ev_data);
else if (mg_http_match_uri(hm, "/b2s"))
pServer->B2SRequest(c, ev_data);
B2SRequest(c, ev_data);
else if (mg_http_match_uri(hm, "/reset"))
ResetRequest(c, ev_data);
else {
mg_http_reply(c, 200, "", "");
return;
Expand Down Expand Up @@ -125,8 +128,12 @@ void VPXDisplayServer::B2SRequest(struct mg_connection *c, void *ev_data)
if (!std::filesystem::exists(szCacheImagePath)) {
pImage = GetB2SImage(string(szVpx));
if (pImage) {
IMG_SavePNG(pImage, szCacheImagePath.c_str());
PLOGI.printf("Backglass image saved to %s", szCacheImagePath.c_str());
if (!IMG_SavePNG(pImage, szCacheImagePath.c_str())) {
PLOGI.printf("Backglass image saved to %s", szCacheImagePath.c_str());
}
else {
PLOGE.printf("Unable to saving backglass image to %s", szCacheImagePath.c_str());
}
}
}
else {
Expand All @@ -147,6 +154,21 @@ void VPXDisplayServer::B2SRequest(struct mg_connection *c, void *ev_data)
mg_http_reply(c, 200, "", "");
}

void VPXDisplayServer::ResetRequest(struct mg_connection *c, void *ev_data)
{
if (m_pBackglassDisplay && m_pBackglassDisplay->pTexture) {
SDL_DestroyTexture(m_pBackglassDisplay->pTexture);
m_pBackglassDisplay->pTexture = NULL;
}

if (m_pDMDDisplay && m_pDMDDisplay->pTexture) {
SDL_DestroyTexture(m_pBackglassDisplay->pTexture);
m_pBackglassDisplay->pTexture = NULL;
}

mg_http_reply(c, 200, "", "");
}

int VPXDisplayServer::OpenDisplay(const string& szName, VPXDisplay* pDisplay)
{
PLOGI.printf("Creating %s window, x=%d, y=%d, width=%d, height=%d", szName.c_str(),
Expand Down
7 changes: 4 additions & 3 deletions VPXDisplayServer.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,7 @@ class VPXDisplayServer
~VPXDisplayServer();

static void EventHandler(struct mg_connection *c, int ev, void *ev_data, void *fn_data);

void UpdateRequest(struct mg_connection *c, void *ev_data);
void B2SRequest(struct mg_connection *c, void *ev_data);
void EventHandler(struct mg_connection *c, int ev, void *ev_data);

int Start();
void SetBasePath(const string& path) { m_szBasePath = path; }
Expand All @@ -36,6 +34,9 @@ class VPXDisplayServer
int OpenDisplay(const string& szName, VPXDisplay* pDisplay);
void CloseDisplay(VPXDisplay* pDisplay);
void RenderDisplay(VPXDisplay* pDisplay);
void UpdateRequest(struct mg_connection *c, void *ev_data);
void B2SRequest(struct mg_connection *c, void *ev_data);
void ResetRequest(struct mg_connection *c, void *ev_data);
SDL_Surface* GetB2SImage(const string& filename);
SDL_Surface* Base64ToImage(const string& image);
vector<unsigned char> Base64Decode(const string &encoded_string);
Expand Down

0 comments on commit 80d57cb

Please sign in to comment.