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

Gpio on complete #1

Merged
merged 7 commits into from Jul 4, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion buildroot/.config
Expand Up @@ -312,7 +312,7 @@ BR2_LINUX_KERNEL_VERSION="12d78096b1669a08d440f7ebaddf5d925e52fe79"
BR2_LINUX_KERNEL_PATCH="linux-regdb.patch"
# BR2_LINUX_KERNEL_USE_DEFCONFIG is not set
BR2_LINUX_KERNEL_USE_CUSTOM_CONFIG=y
BR2_LINUX_KERNEL_CUSTOM_CONFIG_FILE="kernelconfig-recovery.armv6"
BR2_LINUX_KERNEL_CUSTOM_CONFIG_FILE="kernelconfig-recovery.armv7"
# BR2_LINUX_KERNEL_UIMAGE is not set
# BR2_LINUX_KERNEL_APPENDED_UIMAGE is not set
BR2_LINUX_KERNEL_ZIMAGE=y
Expand Down
10 changes: 9 additions & 1 deletion buildroot/package/recovery/init
Expand Up @@ -64,6 +64,8 @@ else
DEFAULT_PARTITION=
GPIO_CHANNEL=
GPIO_CHANNEL_VALUE=
GPIO_ON_COMPLETE_CHANNEL=
GPIO_ON_COMPLETE_CHANNEL_VALUE=

if grep -q runinstaller /proc/cmdline; then
RUN_INSTALLER=-runinstaller
Expand Down Expand Up @@ -96,9 +98,15 @@ else
if [ "${p%%=*}" == "gpiochannelvalue" ] ; then
GPIO_CHANNEL_VALUE="-gpiochannelvalue ${p#*=}"
fi
if [ "${p%%=*}" == "gpiochannel-oncomplete" ] ; then
GPIO_ON_COMPLETE_CHANNEL="-gpiochannel-oncomplete ${p#*=}"
fi
if [ "${p%%=*}" == "gpiochannel-oncompletevalue" ] ; then
GPIO_ON_COMPLETE_CHANNEL_VALUE="-gpiochannel-oncompletevalue ${p#*=}"
fi
done

/usr/bin/recovery $RUN_INSTALLER $GPIO_TRIGGER $KEYBOARD_NO_TRIGGER $FORCE_TRIGGER $DEFAULT_KBD $DEFAULT_LANG $DEFAULT_DISPLAY $DEFAULT_PARTITION $GPIO_CHANNEL $GPIO_CHANNEL_VALUE -qws 2>/tmp/debug
/usr/bin/recovery $RUN_INSTALLER $GPIO_TRIGGER $KEYBOARD_NO_TRIGGER $FORCE_TRIGGER $DEFAULT_KBD $DEFAULT_LANG $DEFAULT_DISPLAY $DEFAULT_PARTITION $GPIO_CHANNEL $GPIO_CHANNEL_VALUE $GPIO_ON_COMPLETE_CHANNEL $GPIO_ON_COMPLETE_CHANNEL_VALUE -qws 2>/tmp/debug

fi

Expand Down
2 changes: 1 addition & 1 deletion recovery/cmdline.txt
@@ -1 +1 @@
runinstaller quiet ramdisk_size=32768 root=/dev/ram0 init=/init vt.cur_default=1 elevator=deadline
runinstaller quiet ramdisk_size=32768 root=/dev/ram0 init=/init vt.cur_default=1 elevator=deadline gpiotriggerenable gpiochannel=40 gpiochannelvalue=1 keyboardtriggerdisable gpiochannel-oncomplete=41 gpiochannel-oncompletevalue=1
4 changes: 2 additions & 2 deletions recovery/config.h
Expand Up @@ -18,11 +18,11 @@
#define ENABLE_LANGUAGE_CHOOSER

/* Website launched when launching Arora */
#define HOMEPAGE "https://www.hrsid.com"
#define HOMEPAGE "http://repository.hrs.cloud/help.html"

/* Location to download the list of available distributions from
* Multiple lists can be specified by space separating the URLs */
#define DEFAULT_REPO_SERVER "https://repository.hrs.cloud/os_list_v3.json"
#define DEFAULT_REPO_SERVER "http://repository.hrs.cloud/os_list_v3.json"

/* Size of recovery FAT partition in MB when using reformat drive initialization method. */
#define RESCUE_PARTITION_SIZE 63
Expand Down
50 changes: 50 additions & 0 deletions recovery/gpiooutput.cpp
@@ -0,0 +1,50 @@
#include "gpiooutput.h"
#include <QFile>
#include <QDebug>

/* Class to set the value of a gpio output using /sys/class/gpio
*
*/

GpioOutput::GpioOutput(int number)
: _number(number)
{
if(_number == 0){
return;
}
_numberStr = QByteArray::number(_number);
QFile f("/sys/class/gpio/export");
f.open(f.WriteOnly);
f.write(_numberStr+"\n");
f.close();
f.setFileName("/sys/class/gpio/gpio"+_numberStr+"/direction");
f.open(f.WriteOnly);
f.write("out\n");
f.close();
}

GpioOutput::~GpioOutput()
{
if(_number == 0){
return;
}
QFile f("/sys/class/gpio/unexport");
f.open(f.WriteOnly);
f.write(_numberStr+"\n");
f.close();
}

bool GpioOutput::value(bool value)
{
if(_number == 0){
return false;
}
bool ok;

QFile f("/sys/class/gpio/gpio"+_numberStr+"/value");
f.open(f.WriteOnly);
f.write(QByteArray::number(value) +"\n");
f.close();
qDebug() << "gpio" << _number << "value" << value;
return ok;
}
22 changes: 22 additions & 0 deletions recovery/gpiooutput.h
@@ -0,0 +1,22 @@
#ifndef GPIOOUTPUT_H
#define GPIOOUTPUT_H

/* Class to set the value of a gpio output using /sys/class/gpio
*
*/

#include <QByteArray>

class GpioOutput
{
public:
GpioOutput(int number);
virtual ~GpioOutput();
bool value(bool value);

protected:
int _number;
QByteArray _numberStr;
};

#endif // GPIOOUTPUT_H
24 changes: 20 additions & 4 deletions recovery/main.cpp
Expand Up @@ -124,13 +124,13 @@ int main(int argc, char *argv[])

qDebug() << "Board revision is " << rev;

int gpioChannel;
int gpioChannel = 2;
int gpioChannelValue = 0;
int gpioChannelOnComplete = 0;
int gpioChannelValueOnComplete = 1;

if (rev == 2 || rev == 3)
gpioChannel = 0;
else
gpioChannel = 2;

QApplication a(argc, argv);
RightButtonFilter rbf;
Expand Down Expand Up @@ -185,7 +185,7 @@ int main(int argc, char *argv[])
if (argc > i+1)
defaultPartition = argv[i+1];
}
// Allow gpio channel to be specified in commandline
// Allow gpio channel to be specified in commandline
else if (strcmp(argv[i], "-gpiochannel") == 0)
{
if (argc > i+1)
Expand All @@ -197,6 +197,18 @@ int main(int argc, char *argv[])
if (argc > i+1)
gpioChannelValue = atoi(argv[i+1]);
}
// Allow gpio channel to be specified in commandline
else if (strcmp(argv[i], "-gpiochannel-oncomplete") == 0)
{
if (argc > i+1)
gpioChannelOnComplete = atoi(argv[i+1]);
}
// Allow gpio channel value i.e pull up or pull down to be specified in commandline
else if (strcmp(argv[i], "-gpiochannel-oncompletevalue") == 0)
{
if (argc > i+1)
gpioChannelValueOnComplete = atoi(argv[i+1]);
}
}

GpioInput gpio(gpioChannel);
Expand Down Expand Up @@ -303,9 +315,13 @@ int main(int argc, char *argv[])

// Main window in the middle of screen
MainWindow mw(drive, defaultDisplay, splash);
if(gpioChannelOnComplete > 0){
mw.configureOnCompleteGpio(gpioChannelOnComplete, gpioChannelValueOnComplete);
}
mw.setGeometry(QStyle::alignedRect(Qt::LeftToRight, Qt::AlignCenter, mw.size(), a.desktop()->availableGeometry()));
mw.show();


#ifdef ENABLE_LANGUAGE_CHOOSER
// Language chooser at the bottom center
LanguageDialog* ld = new LanguageDialog(defaultLang, defaultKeyboard);
Expand Down
28 changes: 22 additions & 6 deletions recovery/mainwindow.cpp
Expand Up @@ -10,6 +10,7 @@
#include "util.h"
#include "twoiconsdelegate.h"
#include "wifisettingsdialog.h"
#include "gpiooutput.h"
#include <QMessageBox>
#include <QProgressDialog>
#include <QMap>
Expand Down Expand Up @@ -73,8 +74,9 @@ MainWindow::MainWindow(const QString &drive, const QString &defaultDisplay, QSpl
QMainWindow(parent),
ui(new Ui::MainWindow),
_qpd(NULL), _kcpos(0), _defaultDisplay(defaultDisplay),
_silent(false), _allowSilent(false), _showAll(false), _fixate(false), _splash(splash), _settings(NULL),
_hasWifi(false), _numInstalledOS(0), _devlistcount(0), _netaccess(NULL), _displayModeBox(NULL), _drive(drive), _bootdrive(drive)
_silent(false), _allowSilent(false), _showAll(false), _fixate(false), _splash(splash), _settings(NULL), _forceSilentInstall(false),
_hasWifi(false), _numInstalledOS(0), _devlistcount(0), _netaccess(NULL), _displayModeBox(NULL), _drive(drive), _bootdrive(drive),
_onCompleteGpio(NULL)
{
ui->setupUi(this);
setWindowFlags(Qt::Window | Qt::CustomizeWindowHint | Qt::WindowTitleHint);
Expand Down Expand Up @@ -222,6 +224,7 @@ MainWindow::MainWindow(const QString &drive, const QString &defaultDisplay, QSpl
{
/* If silentinstall is specified, auto-install single image in /os */
_allowSilent = true;
_forceSilentInstall = cmdline.contains("forcesilentinstall");
}
else
{
Expand All @@ -244,6 +247,14 @@ MainWindow::~MainWindow()
delete ui;
}


void MainWindow::configureOnCompleteGpio(const int &gpioChannel, const int &value)
{
_raiseGpioOnComplete = gpioChannel > 0;
_onCompleteGpio = new GpioOutput(gpioChannel);
_onCompleteGpioValue = value;
}

/* Discover which images we have, and fill in the list */
void MainWindow::populate()
{
Expand Down Expand Up @@ -294,7 +305,7 @@ void MainWindow::populate()
ui->list->setCurrentRow(0);
}

if (_allowSilent && !_numInstalledOS && ui->list->count() == 1)
if (_allowSilent && ((!_numInstalledOS && ui->list->count() == 1) || _forceSilentInstall))
{
// No OS installed, perform silent installation
qDebug() << "Performing silent installation";
Expand Down Expand Up @@ -671,11 +682,16 @@ void MainWindow::onCompleted()
QSettings settings("/settings/noobs.conf", QSettings::IniFormat, this);
settings.setValue("default_partition_to_boot", "800");
settings.sync();

if (!_silent)
QMessageBox::information(this,

if(_raiseGpioOnComplete && _onCompleteGpio){
_onCompleteGpio->value(_onCompleteGpioValue);
}
else if (!_silent){
QMessageBox::information(this,
tr("OS(es) installed"),
tr("OS(es) Installed Successfully"), QMessageBox::Ok);
}

_qpd->deleteLater();
_qpd = NULL;
close();
Expand Down
6 changes: 5 additions & 1 deletion recovery/mainwindow.h
Expand Up @@ -17,6 +17,7 @@
#include <QMessageBox>
#include <QTimer>
#include <QTime>
#include "gpiooutput.h"

namespace Ui {
class MainWindow;
Expand All @@ -26,6 +27,7 @@ class QSettings;
class QListWidgetItem;
class QNetworkAccessManager;
class QMessageBox;
class GPIOOutput;

class MainWindow : public QMainWindow
{
Expand All @@ -34,14 +36,15 @@ class MainWindow : public QMainWindow
public:
explicit MainWindow(const QString &drive, const QString &defaultDisplay, QSplashScreen *splash, QWidget *parent = 0);
~MainWindow();
void configureOnCompleteGpio(const int &gpioChannel, const int &value);

protected:
Ui::MainWindow *ui;
QDialog *_qpd;
QList <int> _kc;
int _kcpos;
const QString _defaultDisplay;
bool _silent, _allowSilent, _showAll, _fixate, _usbimages;
bool _silent, _allowSilent, _showAll, _fixate, _usbimages, _raiseGpioOnComplete, _onCompleteGpioValue, _forceSilentInstall;
static bool _partInited;
static int _currentMode;
QSplashScreen *_splash;
Expand All @@ -55,6 +58,7 @@ class MainWindow : public QMainWindow
QTimer _networkStatusPollTimer, _piDrivePollTimer;
QTime _time;
QString _model, _repo, _drive, _bootdrive;
GpioOutput *_onCompleteGpio;

QMap<QString,QVariantMap> listImages(const QString &folder = "/mnt/os", bool includeInstalled = true);
virtual void changeEvent(QEvent * event);
Expand Down
2 changes: 2 additions & 0 deletions recovery/recovery.pro
Expand Up @@ -21,6 +21,7 @@ SOURCES += \
initdrivethread.cpp \
keydetection.cpp \
gpioinput.cpp \
gpiooutput.cpp \
progressslideshowdialog.cpp \
confeditdialog.cpp \
rightbuttonfilter.cpp \
Expand All @@ -47,6 +48,7 @@ HEADERS += \
config.h \
keydetection.h \
gpioinput.h \
gpiooutput.h \
mbr.h \
progressslideshowdialog.h \
confeditdialog.h \
Expand Down