KT: Make USBMS work

This commit is contained in:
Nicolas Mailloux 2022-05-23 15:24:21 -04:00
parent 04ef2d132c
commit 5a716d2561
4 changed files with 53 additions and 20 deletions

View file

@ -353,6 +353,19 @@ namespace {
return 0; return 0;
} }
void get_battery_level() { void get_battery_level() {
QString batteryLevelFileQstr;
if(global::deviceID == "kt\n") {
QFile batt_level_file("/sys/devices/system/yoshi_battery/yoshi_battery0/battery_capacity");
if(batt_level_file.exists()) {
batt_level_file.open(QIODevice::ReadOnly);
batt_level = batt_level_file.readAll();
batt_level = batt_level.trimmed();
batt_level_int = batt_level.toInt();
batt_level = batt_level.append("%");
batt_level_file.close();
}
}
else {
QFile batt_level_file("/sys/devices/platform/pmic_battery.1/power_supply/mc13892_bat/capacity"); QFile batt_level_file("/sys/devices/platform/pmic_battery.1/power_supply/mc13892_bat/capacity");
if(batt_level_file.exists()) { if(batt_level_file.exists()) {
batt_level_file.open(QIODevice::ReadOnly); batt_level_file.open(QIODevice::ReadOnly);
@ -367,6 +380,7 @@ namespace {
batt_level = "100%"; batt_level = "100%";
} }
} }
}
void writeconfig(std::string file, std::string config) { void writeconfig(std::string file, std::string config) {
std::ofstream fhandler; std::ofstream fhandler;
fhandler.open(file); fhandler.open(file);
@ -767,7 +781,15 @@ namespace {
return checkconfig("/external_root/run/encfs_mounted"); return checkconfig("/external_root/run/encfs_mounted");
} }
bool isUsbPluggedIn() { bool isUsbPluggedIn() {
if(global::deviceID != "kt\n") { if(global::deviceID == "kt\n") {
if(readFile("/sys/devices/system/yoshi_battery/yoshi_battery0/battery_status") == "1\n") {
return 1;
}
else {
return 0;
}
}
else {
// Thanks to https://github.com/koreader/KoboUSBMS/blob/2efdf9d920c68752b2933f21c664dc1afb28fc2e/usbms.c#L148-L158 // Thanks to https://github.com/koreader/KoboUSBMS/blob/2efdf9d920c68752b2933f21c664dc1afb28fc2e/usbms.c#L148-L158
int ntxfd; int ntxfd;
if((ntxfd = open("/dev/ntx_io", O_RDWR)) == -1) { if((ntxfd = open("/dev/ntx_io", O_RDWR)) == -1) {

View file

@ -119,7 +119,7 @@ void koboxSettings::on_spinBox_valueChanged(int arg1)
void koboxSettings::on_pushButton_clicked() void koboxSettings::on_pushButton_clicked()
{ {
// Export Extensions disk image over USB with g_mass_storage // Export Extensions disk image over USB with g_mass_storage/g_file_storage
global::usbms::usbmsDialog = false; global::usbms::usbmsDialog = false;
global::usbms::launchUsbms = true; global::usbms::launchUsbms = true;
global::usbms::koboxExportExtensions = true; global::usbms::koboxExportExtensions = true;

View file

@ -86,19 +86,29 @@ void usbms_splash::usbms_launch()
QThread::msleep(1000); QThread::msleep(1000);
if(global::deviceID == "n306\n" or global::deviceID == "n873\n") { if(global::deviceID == "n306\n" or global::deviceID == "n873\n") {
QProcess::execute("insmod", QStringList() << "/external_root/modules/fs/configfs/configfs.ko"); QProcess::execute("insmod", QStringList() << "/external_root/lib/modules/fs/configfs/configfs.ko");
QProcess::execute("insmod", QStringList() << "/external_root/modules/drivers/usb/gadget/libcomposite.ko"); QProcess::execute("insmod", QStringList() << "/external_root/lib/modules/drivers/usb/gadget/libcomposite.ko");
QProcess::execute("insmod", QStringList() << "/external_root/modules/drivers/usb/gadget/function/usb_f_mass_storage.ko"); QProcess::execute("insmod", QStringList() << "/external_root/lib/modules/drivers/usb/gadget/function/usb_f_mass_storage.ko");
}
else if(global::deviceID == "kt\n") {
QProcess::execute("insmod", QStringList() << "/external_root/lib/modules/2.6.35-inkbox/kernel/drivers/usb/gadget/arcotg_udc.ko");
} }
QString prog_1 ("insmod"); QString prog_1 ("insmod");
QStringList args_1; QStringList args_1;
if(global::usbms::koboxExportExtensions == true) { if(global::deviceID == "kt\n") {
args_1 << "/external_root/modules/g_mass_storage.ko" << "file=/external_root/opt/storage/X11/extensions-user.img" << "removable=y" << "stall=0"; massStorageModule = "/external_root/lib/modules/2.6.35-inkbox/kernel/drivers/usb/gadget/g_file_storage.ko";
} }
else { else {
args_1 << "/external_root/modules/g_mass_storage.ko" << "file=/external_root/opt/storage/onboard" << "removable=y" << "stall=0"; massStorageModule = "/external_root/lib/modules/g_mass_storage.ko";
}
if(global::usbms::koboxExportExtensions == true) {
args_1 << massStorageModule << "file=/external_root/opt/storage/X11/extensions-user.img" << "removable=y" << "stall=0";
}
else {
args_1 << massStorageModule << "file=/external_root/opt/storage/onboard" << "removable=y" << "stall=0";
} }
QProcess *proc_1 = new QProcess(); QProcess *proc_1 = new QProcess();
@ -111,7 +121,7 @@ void usbms_splash::usbms_launch()
usbms_t->setInterval(1000); usbms_t->setInterval(1000);
connect(usbms_t, &QTimer::timeout, [&]() { connect(usbms_t, &QTimer::timeout, [&]() {
if(exitUsbMsDone == false) { if(exitUsbMsDone == false) {
if(isUsbPluggedIn() == false) { if(isUsbPluggedIn() == 0) {
if(global::usbms::koboxExportExtensions == true) { if(global::usbms::koboxExportExtensions == true) {
reboot(false); reboot(false);
qApp->quit(); qApp->quit();
@ -138,7 +148,7 @@ void usbms_splash::usbms_launch()
QString prog("rmmod"); QString prog("rmmod");
QStringList args; QStringList args;
args << "g_mass_storage"; args << massStorageModule;
QProcess * proc = new QProcess(); QProcess * proc = new QProcess();
proc->start(prog, args); proc->start(prog, args);
proc->waitForFinished(); proc->waitForFinished();

View file

@ -17,6 +17,7 @@ public:
~usbms_splash(); ~usbms_splash();
float sW; float sW;
float sH; float sH;
QString massStorageModule;
void usbms_launch(); void usbms_launch();