mirror of
https://github.com/niellun/FastCarPlay.git
synced 2026-06-11 02:47:47 +02:00
Better redraw logic, more logs
This commit is contained in:
+7
-10
@@ -371,15 +371,12 @@ void Application::loop()
|
||||
}
|
||||
}
|
||||
|
||||
if (_state.requestFrame > 0 && Settings::forceRedraw > 0)
|
||||
if (_state.requestFrame > 0 && Settings::forceRedraw > 0 && ++_state.requestFrame - Settings::forceRedrawTimeout > 0)
|
||||
{
|
||||
if (++_state.requestFrame % Settings::forceRedraw == 0)
|
||||
{
|
||||
log_d("Request screen update");
|
||||
protocol.send(Message::Control(BTN_SCREEN_REFRESH));
|
||||
if (_state.requestFrame >= Settings::forceRedraw * REDRAW_REQUEST)
|
||||
_state.requestFrame = 0;
|
||||
}
|
||||
log_d("Request screen update");
|
||||
protocol.send(Message::Control(BTN_SCREEN_REFRESH));
|
||||
if (_state.requestFrame > Settings::forceRedrawTimeout + Settings::forceRedraw)
|
||||
_state.requestFrame = 0;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -478,8 +475,8 @@ const std::string Application::status() const
|
||||
if (SDL_GetRendererInfo(renderer, &info) == 0)
|
||||
{
|
||||
out << " " << info.name
|
||||
<< ((info.flags & SDL_RENDERER_ACCELERATED) != 0?" accelerated":"")
|
||||
<< ((info.flags & SDL_RENDERER_PRESENTVSYNC) != 0?" vsync":"");
|
||||
<< ((info.flags & SDL_RENDERER_ACCELERATED) != 0 ? " accelerated" : "")
|
||||
<< ((info.flags & SDL_RENDERER_PRESENTVSYNC) != 0 ? " vsync" : "");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -46,4 +46,22 @@ inline void pushEvent(Uint32 evt, int code)
|
||||
SDL_PushEvent(&event);
|
||||
}
|
||||
|
||||
#include <sstream>
|
||||
#include <iomanip>
|
||||
|
||||
inline std::string bytes(uint8_t *data, uint32_t length, uint16_t max)
|
||||
{
|
||||
std::ostringstream out;
|
||||
|
||||
if (data && length >= 4)
|
||||
{
|
||||
for (size_t i = 0; (i < length) && (i < max); ++i)
|
||||
{
|
||||
out << std::setw(4) << static_cast<uint32_t>(data[i]);
|
||||
}
|
||||
}
|
||||
|
||||
return out.str();
|
||||
}
|
||||
|
||||
#endif /* SRC_COMMON_FUNCTIONS */
|
||||
|
||||
@@ -12,6 +12,7 @@
|
||||
#include "common/threading.h"
|
||||
#include "protocol/protocol_const.h"
|
||||
#include "libavcodec/defs.h"
|
||||
#include "common/functions.h"
|
||||
|
||||
ConnectionReader::ConnectionReader()
|
||||
: _active(false),
|
||||
@@ -133,7 +134,7 @@ void ConnectionReader::onUsbRead(libusb_transfer *transfer)
|
||||
if (!c->owner->_active)
|
||||
return;
|
||||
|
||||
log_p("USB read > status %d length %d", transfer->status, transfer->actual_length);
|
||||
log_p("Read %d [%d]: %s", transfer->actual_length, transfer->status, bytes(transfer->buffer, transfer->actual_length, 40).c_str());
|
||||
|
||||
if (transfer->status == LIBUSB_TRANSFER_CANCELLED)
|
||||
return;
|
||||
@@ -197,7 +198,7 @@ void ConnectionReader::processLoop()
|
||||
|
||||
if (!message->valid())
|
||||
{
|
||||
log_w("Received mallformed message");
|
||||
log_w("Mallformed message %s", message->toString(20).c_str());
|
||||
continue;
|
||||
}
|
||||
|
||||
|
||||
@@ -299,6 +299,56 @@ public:
|
||||
int32_t length() const { return _header.length - _offset; }
|
||||
uint8_t *data() const { return _data ? _data + _offset : nullptr; }
|
||||
|
||||
const std::string toString(int count) const
|
||||
{
|
||||
const char *cmds = "Unknown";
|
||||
for (size_t i = 0; i < sizeof(protocolCmdList) / sizeof(protocolCmdList[0]); ++i)
|
||||
{
|
||||
if (protocolCmdList[i].cmd == static_cast<int>(_header.type))
|
||||
{
|
||||
cmds = protocolCmdList[i].name;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
char len[32];
|
||||
std::snprintf(len, sizeof(len), "[%d]", _header.length);
|
||||
|
||||
char magic = '!';
|
||||
if (_header.magic == MAGIC)
|
||||
magic = ' ';
|
||||
else if (_header.magic == MAGIC_ENC)
|
||||
magic = '*';
|
||||
|
||||
char check = _header.typecheck == ~_header.type ? '+' : 'x';
|
||||
|
||||
char prefix[64];
|
||||
std::snprintf(prefix, sizeof(prefix), ">%c%c%3u%-8s%-15s",
|
||||
magic,
|
||||
check,
|
||||
static_cast<unsigned>(_header.type),
|
||||
len,
|
||||
cmds);
|
||||
|
||||
std::string result(prefix);
|
||||
uint8_t *payload = data();
|
||||
int32_t payloadLength = length();
|
||||
|
||||
if (payload && payloadLength > 0 && count > 0)
|
||||
{
|
||||
int limit = std::min(count, payloadLength);
|
||||
result.reserve(result.size() + static_cast<size_t>(limit));
|
||||
|
||||
for (int i = 0; i < limit; ++i)
|
||||
{
|
||||
char ch = static_cast<char>(payload[i]);
|
||||
result += (ch == '\n' || ch == '\r' || ch < 32 || ch > 126) ? '.' : ch;
|
||||
}
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
private:
|
||||
static inline void write_uint32_le(uint8_t *dst, uint32_t value)
|
||||
{
|
||||
|
||||
@@ -42,6 +42,7 @@ public:
|
||||
static inline Setting<int> renderingBuffer{"rendering-buffer", 5};
|
||||
static inline Setting<int> eventsSkip{"draw-skip-events", 3};
|
||||
static inline Setting<int> forceRedraw{"force-redraw", 0};
|
||||
static inline Setting<int> forceRedrawTimeout{"force-redraw-timeout", 0};
|
||||
static inline Setting<float> aspectCorrection{"aspect-correction", 1};
|
||||
static inline Setting<std::string> renderDriver{"renderer-driver", ""};
|
||||
static inline Setting<bool> alternativeRendering{"alternative-rendering", false};
|
||||
|
||||
Reference in New Issue
Block a user