Skip to content

Commit

Permalink
298 screenshots lcd (#308)
Browse files Browse the repository at this point in the history
* Add key shortcut for LCD snapshot
  • Loading branch information
vintagepc authored Apr 19, 2021
1 parent 8963a54 commit be21d85
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 11 deletions.
39 changes: 32 additions & 7 deletions parts/components/GLHelper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,13 +43,16 @@
#include <vector>


GLHelper::GLHelper(const std::string &strName):Scriptable(strName)
GLHelper::GLHelper(const std::string &strName, bool bIsPrimary):Scriptable(strName)
{
RegisterAction("CheckPixel","Checks the pixel color at the given position matches specified (x,y,RGBA).",ActCheckPixel, {ArgType::uint32,ArgType::uint32, ArgType::uint32});
RegisterAction("Snapshot", "Takes a snap of the current GL rendering", ActTakeSnapshot, {ArgType::String});
RegisterAction("SnapRect", "Takes a snap a region (file,x,y,w,h)", ActTakeSnapshotArea, {ArgType::String,ArgType::Int,ArgType::Int,ArgType::Int,ArgType::Int});
RegisterActionAndMenu("AutoSnap", "Takes a snap of the current GL rendering and gives it the current date/time.", ActTakeSnapDT);

//RegisterActionAndMenu("AutoSnapLCD", "Takes a snap of the current LCD window and gives it the current date/time.", ActTakeSnapLCD);
if (bIsPrimary) {
RegisterKeyHandler('S',"Take a snapshot of the LCD");
}
}

// Function for running the GL stuff inside the GL context.
Expand Down Expand Up @@ -82,9 +85,16 @@ void GLHelper::OnDraw()
}
/* FALLTHRU */
case ActTakeSnapshotArea:
case ActTakeSnapLCD:
{
WritePNG(width, height, m_iAct==ActTakeSnapshotArea);
m_iState = St_Done;
WritePNG(width, height, (m_iAct == ActTakeSnapshotArea || m_iAct == ActTakeSnapLCD));
std::cout << "Wrote: " << m_strFile << '\n';
if (m_bIsKeySnap) {
m_bIsKeySnap = false;
m_iState = St_Idle;
} else {
m_iState = St_Done;
}
}
break;
default:
Expand All @@ -100,6 +110,21 @@ void GLHelper::OnDraw()
}
}

void GLHelper::OnKeyPress(const Key& key)
{
switch (key)
{
case 'S':
{
std::cout << "LCD Snapshot toggled!\n";
m_bIsKeySnap = true;
// GLHelper::SnapRect(tests/snaps/LCD01,0,0,500,164)
ProcessAction(ActTakeSnapLCD,{"","0","0","500","164"});
}
break;
}
}

bool GLHelper::WritePNG(int width, int height, bool bRegion)
{
auto w = m_w.load(), h = m_h.load();
Expand Down Expand Up @@ -186,11 +211,12 @@ IScriptable::LineStatus GLHelper::ProcessAction(unsigned int iAct, const std::ve
case ActTakeSnapshot:
case ActTakeSnapshotArea:
case ActTakeSnapDT:
case ActTakeSnapLCD:
{
bool bIsArea = iAct == ActTakeSnapshotArea;
bool bIsArea = (iAct == ActTakeSnapshotArea || iAct == ActTakeSnapLCD);
if (m_iState == St_Idle)
{
if (iAct == ActTakeSnapDT) {
if (iAct == ActTakeSnapDT || iAct == ActTakeSnapLCD) {
auto tNow = std::chrono::system_clock::to_time_t(std::chrono::system_clock::now());
m_strFile = std::ctime(&tNow);
m_strFile = m_strFile.substr(0,m_strFile.size()-1);// strip newline.
Expand All @@ -211,7 +237,6 @@ IScriptable::LineStatus GLHelper::ProcessAction(unsigned int iAct, const std::ve
else if (m_iState == St_Done)
{
m_iState = St_Idle;
std::cout << "Wrote: " << m_strFile << '\n';
return LineStatus::Finished;
}
return LineStatus::HoldExec; // Pauses primary board execution until finished.
Expand Down
11 changes: 8 additions & 3 deletions parts/components/GLHelper.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,17 +20,18 @@

#pragma once

#include "IKeyClient.h"
#include "IScriptable.h"
#include "Scriptable.h"
#include <atomic>
#include <cstdint>
#include <string>
#include <vector>

class GLHelper: public Scriptable
class GLHelper: public Scriptable, private IKeyClient
{
public:
explicit GLHelper(const std::string &strName = "GLHelper");
explicit GLHelper(const std::string &strName = "GLHelper", bool isPrimary = true);

inline bool IsTakingSnapshot() { return m_iState >= St_Queued; }

Expand All @@ -39,6 +40,8 @@ class GLHelper: public Scriptable

protected:

void OnKeyPress(const Key& key) override;

bool WritePNG(int width, int height, bool bRegion);

// Useful for debugging as it's a very simple format.
Expand All @@ -51,7 +54,8 @@ class GLHelper: public Scriptable
ActCheckPixel,
ActTakeSnapshot,
ActTakeSnapshotArea,
ActTakeSnapDT
ActTakeSnapDT,
ActTakeSnapLCD,
};
enum ActState
{
Expand All @@ -66,5 +70,6 @@ class GLHelper: public Scriptable
std::atomic_uint32_t m_x{0}, m_y{0}, m_h{0}, m_w{0}, m_color{0};
std::atomic_int m_iState {St_Idle};
std::vector<uint8_t> m_vBuffer{};
std::atomic_bool m_bIsKeySnap {false};
bool m_bVFlip = true;
};
2 changes: 1 addition & 1 deletion utility/MK3SGL.h
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ class MK3SGL: public BasePeripheral, public Scriptable, private IKeyClient
GLObj m_MMUSel {"assets/MMU_Selector.obj"};
GLObj m_MMUIdl {"assets/Idler_moving.obj"};

GLHelper m_snap{"3DView"};
GLHelper m_snap{"3DView",false};

OBJCollection *m_Objs = nullptr;

Expand Down

0 comments on commit be21d85

Please sign in to comment.