Skip to content

Instantly share code, notes, and snippets.

@jadonk
Created October 4, 2010 23:00
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jadonk/610628 to your computer and use it in GitHub Desktop.
Save jadonk/610628 to your computer and use it in GitHub Desktop.
These are the labs for the University of Texas BeagleBoard Open Source Design Challenge training (www.ti.com/beagleboardchallenge).
The SYSFS entries for the BeagleBoard LEDs are mounted
at "/sys/class/leds". You'll find "beagleboard::usr0"
and "beagleboard::usr1". Each of those directories will
have "trigger" and "brightness" entries.
For this lab exercise, attempt to stop USR0 from blinking
and then turn it on steady, then off, then back to the
blinking state.
You'll need two common Unix/Linux tools called "echo"
and "cat". "echo" allows you to create output to be
sent to the SYSFS entries and "cat" allows you to read
them. Not all SYSFS entries can be read or written.
1) Start by using "cat" to print out the current state of
"trigger".
2) Change the state of the "trigger" to "none" using "echo".
The syntax of "echo" is roughly:
echo "text to write" > file_to_be_written
3) Change the state of the "brightness" to "1" using "echo".
Observe the USR0 LED.
4) Change the state of the "brightness" to "0" using "echo".
Observe the USR0 LED.
5) Restore the state of the "trigger" to "heartbeat" using
echo. Use "cat" to see that the state is restored and
observe the USR0 LED.
/****************************************************************
**
** Lab 2
**
** My references in creating this (starting with most recent):
** http://doc.trolltech.com/4.6/qabstractbutton.html#signals
** http://doc.qt.nokia.com/4.6/widgets-groupbox.html
** http://lists.trolltech.com/qt-interest/1997-06/thread00071-0.html
** http://doc.trolltech.com/4.7/moc.html
** http://lists.trolltech.com/qt-interest/2007-06/thread01171-0.html
** http://cartan.cas.suffolk.edu/oopdocbook/html/
** http://doc.trolltech.com/4.3/signalsandslots.html
** http://doc.trolltech.com/4.3/tutorial-t2.html
** http://doc.trolltech.com/3.0/toggleaction-example.html
** http://sector.ynet.sk/qt4-tutorial/my-first-qt-gui-application.html
** http://doc.trolltech.com/4.3/tutorial-t1.html
** http://www.gidforums.com/t-13690.html
** http://doc.trolltech.com/3.0/t1.html
**
****************************************************************/
#include <qapplication.h>
#include <qpushbutton.h>
#include "lab2.h"
void myQtObj::doSomething(bool checked)
{
// Put your code here to toggle the state of the USR0 LED
if(checked)
{
system("echo 1");
}
else
{
system("echo 0");
}
}
int main(int argc, char **argv)
{
QApplication a(argc, argv);
QPushButton b("Push me!", 0);
b.setCheckable(true);
b.setChecked(false);
b.resize(100, 30);
myQtObj c;
QObject::connect(&b, SIGNAL(toggled(bool)), &c, SLOT(doSomething(bool)));
b.show();
return a.exec();
}
/****************************************************************
**
** Lab 2
**
** My references in creating this (starting with most recent):
** http://doc.trolltech.com/4.6/qabstractbutton.html#signals
** http://doc.qt.nokia.com/4.6/widgets-groupbox.html
** http://lists.trolltech.com/qt-interest/1997-06/thread00071-0.html
** http://doc.trolltech.com/4.7/moc.html
** http://lists.trolltech.com/qt-interest/2007-06/thread01171-0.html
** http://cartan.cas.suffolk.edu/oopdocbook/html/
** http://doc.trolltech.com/4.3/signalsandslots.html
** http://doc.trolltech.com/4.3/tutorial-t2.html
** http://doc.trolltech.com/3.0/toggleaction-example.html
** http://sector.ynet.sk/qt4-tutorial/my-first-qt-gui-application.html
** http://doc.trolltech.com/4.3/tutorial-t1.html
** http://www.gidforums.com/t-13690.html
** http://doc.trolltech.com/3.0/t1.html
**
****************************************************************/
#include <qapplication.h>
#include <qpushbutton.h>
#include "lab2.h"
void myQtObj::doSomething(bool checked)
{
const char * fileName = "/sys/class/leds/beagleboard::usr0/trigger";
FILE * fileTrigger = NULL;
if(!fileTrigger)
{
fileTrigger = fopen(fileName, "w");
}
if(!fileTrigger)
{
printf("ERROR: unable to open %s", fileName);
exit(-1);
}
if(checked)
{
fprintf(fileTrigger, "none");
fflush(fileTrigger);
printf("trigger: none\n");
fflush(stdout);
}
else
{
fprintf(fileTrigger, "heartbeat");
fflush(fileTrigger);
printf("trigger: heartbeat\n");
fflush(stdout);
}
}
int main(int argc, char **argv)
{
QApplication a(argc, argv);
QPushButton b("Push me!", 0);
b.setCheckable(true);
b.setChecked(false);
b.resize(100, 30);
myQtObj c;
QObject::connect(&b, SIGNAL(toggled(bool)), &c, SLOT(doSomething(bool)));
b.show();
return a.exec();
}
#include <QObject>
class myQtObj : public QObject
{
Q_OBJECT
public slots:
void doSomething(bool);
};
#include <QObject>
class myQtObj : public QObject
{
Q_OBJECT
public slots:
void doSomething(bool);
};
######################################################################
# Automatically generated by qmake (2.01a) Sat Jun 5 06:07:15 2010
######################################################################
TEMPLATE = app
TARGET =
DEPENDPATH += .
INCLUDEPATH += .
# Input
HEADERS += lab2.h
SOURCES += lab2.cpp
######################################################################
# Automatically generated by qmake (2.01a) Sat Jun 5 06:07:15 2010
######################################################################
TEMPLATE = app
TARGET =
DEPENDPATH += .
INCLUDEPATH += .
# Input
HEADERS += lab2.h
SOURCES += lab2.cpp
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment