2018-05-23 18:34:05 -07:00
|
|
|
#include <QObject>
|
|
|
|
|
#include <QJSValue>
|
|
|
|
|
|
2018-05-22 15:08:11 -07:00
|
|
|
#include <chrono>
|
|
|
|
|
#include <thread>
|
|
|
|
|
#include <stdint.h>
|
|
|
|
|
|
|
|
|
|
#include "jssystem.h"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
JSSystem::JSSystem(QObject* parent) : QObject(parent){
|
|
|
|
|
framebufferWidth = 0;
|
|
|
|
|
framebufferHeight = 0;
|
2018-05-23 18:34:05 -07:00
|
|
|
framebufferRender = false;
|
2018-05-22 15:08:11 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void JSSystem::testJsAttachment(QString str){
|
|
|
|
|
printf("C++ executed through javascript!, str:%s\n", str.toStdString().c_str());
|
|
|
|
|
}
|
|
|
|
|
|
2018-05-29 11:10:43 -07:00
|
|
|
void JSSystem::uSleep(unsigned int uSeconds){
|
2018-05-22 15:08:11 -07:00
|
|
|
std::this_thread::sleep_for(std::chrono::microseconds(uSeconds));
|
|
|
|
|
}
|
|
|
|
|
|
2018-05-29 11:10:43 -07:00
|
|
|
void JSSystem::setFramebufferSize(unsigned int w, unsigned int h){
|
2018-05-23 18:34:05 -07:00
|
|
|
systemData.lock();
|
2018-05-22 15:08:11 -07:00
|
|
|
framebufferPixels.resize(w * h);
|
|
|
|
|
framebufferWidth = w;
|
|
|
|
|
framebufferHeight = h;
|
2018-05-23 18:34:05 -07:00
|
|
|
systemData.unlock();
|
2018-05-22 15:08:11 -07:00
|
|
|
}
|
|
|
|
|
|
2018-05-23 18:34:05 -07:00
|
|
|
void JSSystem::setFramebuffer(QJSValue framebuffer){
|
|
|
|
|
systemData.lock();
|
|
|
|
|
for(uint16_t y = 0; y < framebufferHeight; y++)
|
|
|
|
|
for(uint16_t x = 0; x < framebufferWidth; x++)
|
2018-05-23 19:10:51 -07:00
|
|
|
framebufferPixels[y * framebufferWidth + x] = framebuffer.property(y * framebufferWidth + x).toUInt();
|
2018-05-23 18:34:05 -07:00
|
|
|
framebufferRender = true;
|
|
|
|
|
systemData.unlock();
|
2018-05-22 15:08:11 -07:00
|
|
|
}
|