Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix for issue "Suspend causes oxide to crash on RM2 #113" #114

Merged
merged 16 commits into from
Jan 7, 2021
Merged
Show file tree
Hide file tree
Changes from 7 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 10 additions & 7 deletions applications/system-service/screenapi.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,13 @@
#include "stb_image.h"
#include "stb_image_write.h"
#include "fb2png.h"
#include "devicesettings.h"

#define DISPLAYWIDTH 1404
#define DISPLAYHEIGHT 1872
#define TEMP_USE_REMARKABLE_DRAW 0x0018
#define remarkable_color uint16_t
#define DISPLAYSIZE DISPLAYWIDTH * DISPLAYHEIGHT * sizeof(remarkable_color)
#define RDISPLAYWIDTH 1408
#define RDISPLAYHEIGHT 1920
#define RDISPLAYSIZE RDISPLAYWIDTH * RDISPLAYHEIGHT * sizeof(remarkable_color)

#define screenAPI ScreenAPI::singleton()

Expand Down Expand Up @@ -52,22 +50,27 @@ class ScreenAPI : public APIBase {
}
int width, height, channels;
auto decoded = (uint32_t*)stbi_load(path.toStdString().c_str(), &width, &height, &channels, 4);
int target_width = DeviceSettings::instance().getFrameBufferWidth();
int target_height = DeviceSettings::instance().getFrameBufferHeight();
int fd = open("/dev/fb0", O_RDWR);
auto ptr = (remarkable_color*)mmap(NULL, RDISPLAYSIZE, PROT_WRITE, MAP_SHARED, fd, 0);
auto ptr = (remarkable_color*)mmap(NULL,
DeviceSettings::instance().getFrameBufferSize(),
PROT_WRITE, MAP_SHARED, fd, 0);
auto src = decoded;

for(int j = 0; j < height; j++){
if(j >= RDISPLAYHEIGHT){
if(j >= target_height){
break;
}
for(int i = 0; i < width; i++){
if(i >= RDISPLAYWIDTH){
if(i >= target_width){
break;
}
if(src[i] != 0){
ptr[i] = (remarkable_color)src[i];
}
}
ptr += RDISPLAYWIDTH;
ptr += target_width;
src += width;
}
mxcfb_update_data update_data;
Expand Down
18 changes: 18 additions & 0 deletions applications/system-service/systemapi.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#include "systemapi.h"
#include "appsapi.h"
#include "powerapi.h"
#include "devicesettings.h"

void SystemAPI::PrepareForSleep(bool suspending){
if(suspending){
Expand All @@ -12,12 +13,29 @@ void SystemAPI::PrepareForSleep(bool suspending){
resumeApp = nullptr;
}
drawSleepImage();
if (DeviceSettings::instance().getDeviceType() == DeviceType::RM2) {
// RM2 needs some time to draw sleep image
// 0.5s is sometimes not enough, so I set it to 0.6s
struct timespec args{
Eeems marked this conversation as resolved.
Show resolved Hide resolved
.tv_sec = 0,
.tv_nsec = 600000000,
};
nanosleep(&args, NULL);
}
qDebug() << "Suspending...";
buttonHandler->setEnabled(false);
if (DeviceSettings::instance().getDeviceType() == DeviceType::RM2) {
qDebug() << "Removing module";
qDebug() << "Exit code: " << system("rmmod brcmfmac");
}
releaseSleepInhibitors();
}else{
inhibitSleep();
qDebug() << "Resuming...";
if (DeviceSettings::instance().getDeviceType() == DeviceType::RM2) {
qDebug() << "Inserting module";
qDebug() << "Exit code: " << system("modprobe brcmfmac");
}
QCoreApplication::processEvents(QEventLoop::AllEvents, 100);
if(resumeApp == nullptr){
resumeApp = appsAPI->getApplication(appsAPI->startupApplication());
Expand Down
20 changes: 16 additions & 4 deletions applications/system-service/wlan.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ class Wlan : public QObject, public SysObject {
QString iface() { return m_iface; }
bool up() { return !system(("ifconfig " + iface() + " up").toStdString().c_str()); }
bool down() { return !system(("ifconfig " + iface() + " down").toStdString().c_str()); }
bool isUp(){ return !system(("ip addr show " + iface() + " | grep UP > /dev/null").toStdString().c_str()); }
bool isUp(){ return !system(("ip addr show " + iface() + " | /bin/grep UP > /dev/null").toStdString().c_str()); }
Witos marked this conversation as resolved.
Show resolved Hide resolved
Interface* interface() { return m_interface; }
QSet<QString> blobs(){ return m_blobs; }
QString operstate(){
Expand All @@ -33,12 +33,24 @@ class Wlan : public QObject, public SysObject {
}
return "";
}
bool pingIP(std::string ip, const char* port) {
return !system(("echo -n > /dev/tcp/" + ip.substr(0, ip.length() - 1) + "/" + port).c_str());
}
bool isConnected(){
auto ip = exec("ip r | grep " + iface() + " | grep default | awk '{print $3}'");
return ip != "" && !system(("echo -n > /dev/tcp/" + ip.substr(0, ip.length() - 1) + "/53").c_str());
auto ip = exec("ip r | /bin/grep " + iface() + " | /bin/grep default | awk '{print $3}'");
Witos marked this conversation as resolved.
Show resolved Hide resolved
return ip != "" && (pingIP(ip, "53") || pingIP(ip, "80"));
}
int link(){
return std::stoi(exec("cat /proc/net/wireless | grep " + iface() + " | awk '{print $3}'"));
std::string out = exec("cat /proc/net/wireless | /bin/grep " + iface() + " | awk '{print $3}'");
Witos marked this conversation as resolved.
Show resolved Hide resolved
int ret = 0;
try {
ret = std::stoi(out);
}
catch (const std::invalid_argument& e) {
qDebug() << "link failed: " << out.c_str();
return -1;
}
return ret;
Witos marked this conversation as resolved.
Show resolved Hide resolved
}
signals:
void BSSAdded(Wlan*, QDBusObjectPath, QVariantMap);
Expand Down
26 changes: 26 additions & 0 deletions shared/devicesettings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -74,3 +74,29 @@ const char* DeviceSettings::getTouchEnvSetting() const {
return "";
}
}

int DeviceSettings::getFrameBufferWidth() const {
Eeems marked this conversation as resolved.
Show resolved Hide resolved
switch(getDeviceType()) {
case DeviceType::RM1:
return 1408;
case DeviceType::RM2:
return 1404;
default:
return 0;
}
}

int DeviceSettings::getFrameBufferHeight() const {
Eeems marked this conversation as resolved.
Show resolved Hide resolved
switch(getDeviceType()) {
case DeviceType::RM1:
return 1920;
case DeviceType::RM2:
return 1872;
default:
return 0;
}
}

int DeviceSettings::getFrameBufferSize() const {
Eeems marked this conversation as resolved.
Show resolved Hide resolved
return getFrameBufferWidth() * getFrameBufferHeight() * sizeof(uint16_t);
}
3 changes: 3 additions & 0 deletions shared/devicesettings.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@ class DeviceSettings{
const char* getWacomDevicePath() const;
const char* getTouchDevicePath() const;
const char* getTouchEnvSetting() const;
int getFrameBufferWidth() const;
int getFrameBufferHeight() const;
int getFrameBufferSize() const;
DeviceType getDeviceType() const;

};