diff --git a/functions.h b/functions.h index e562c24..d2934b2 100644 --- a/functions.h +++ b/functions.h @@ -353,18 +353,32 @@ namespace { return 0; } void get_battery_level() { - QFile batt_level_file("/sys/devices/platform/pmic_battery.1/power_supply/mc13892_bat/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(); + 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 { - batt_level_int = 100; - batt_level = "100%"; + QFile batt_level_file("/sys/devices/platform/pmic_battery.1/power_supply/mc13892_bat/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 { + batt_level_int = 100; + batt_level = "100%"; + } } } void writeconfig(std::string file, std::string config) { @@ -767,7 +781,15 @@ namespace { return checkconfig("/external_root/run/encfs_mounted"); } 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 int ntxfd; if((ntxfd = open("/dev/ntx_io", O_RDWR)) == -1) { diff --git a/koboxsettings.cpp b/koboxsettings.cpp index 1ec1be2..5730b36 100644 --- a/koboxsettings.cpp +++ b/koboxsettings.cpp @@ -119,7 +119,7 @@ void koboxSettings::on_spinBox_valueChanged(int arg1) 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::launchUsbms = true; global::usbms::koboxExportExtensions = true; diff --git a/usbms_splash.cpp b/usbms_splash.cpp index e1446d7..ea49d70 100644 --- a/usbms_splash.cpp +++ b/usbms_splash.cpp @@ -86,19 +86,29 @@ void usbms_splash::usbms_launch() QThread::msleep(1000); 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/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/fs/configfs/configfs.ko"); + QProcess::execute("insmod", QStringList() << "/external_root/lib/modules/drivers/usb/gadget/libcomposite.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"); QStringList args_1; - if(global::usbms::koboxExportExtensions == true) { - args_1 << "/external_root/modules/g_mass_storage.ko" << "file=/external_root/opt/storage/X11/extensions-user.img" << "removable=y" << "stall=0"; + if(global::deviceID == "kt\n") { + massStorageModule = "/external_root/lib/modules/2.6.35-inkbox/kernel/drivers/usb/gadget/g_file_storage.ko"; } 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(); @@ -111,7 +121,7 @@ void usbms_splash::usbms_launch() usbms_t->setInterval(1000); connect(usbms_t, &QTimer::timeout, [&]() { if(exitUsbMsDone == false) { - if(isUsbPluggedIn() == false) { + if(isUsbPluggedIn() == 0) { if(global::usbms::koboxExportExtensions == true) { reboot(false); qApp->quit(); @@ -138,7 +148,7 @@ void usbms_splash::usbms_launch() QString prog("rmmod"); QStringList args; - args << "g_mass_storage"; + args << massStorageModule; QProcess * proc = new QProcess(); proc->start(prog, args); proc->waitForFinished(); diff --git a/usbms_splash.h b/usbms_splash.h index 132e1e0..3d8d8af 100644 --- a/usbms_splash.h +++ b/usbms_splash.h @@ -17,6 +17,7 @@ public: ~usbms_splash(); float sW; float sH; + QString massStorageModule; void usbms_launch();