Skip to content

Instantly share code, notes, and snippets.

@YutaSeya

YutaSeya/inputSw.cpp Secret

Created May 9, 2019
Embed
What would you like to do?
#include <cstdio>
#include <unistd.h>
#include <iostream>
using namespace std;
bool get0()
{
bool sw_data = false;
FILE *sw;
sw = fopen("/dev/rtswitch0", "r");
char data = fgetc(sw);
if ( data == '0' ){
sw_data = true;
} else {
sw_data = false;
}
fclose(sw);
return sw_data;
}
bool get1()
{
bool sw_data = false;
FILE *sw;
sw = fopen("/dev/rtswitch1", "r");
char data = fgetc(sw);
if ( data == '0' ){
sw_data = true;
} else {
sw_data = false;
}
fclose(sw);
return sw_data;
}
bool get2()
{
bool sw_data = false;
FILE *sw;
sw = fopen("/dev/rtswitch2", "r");
char data = fgetc(sw);
if ( data == '0' ){
sw_data = true;
} else {
sw_data = false;
}
fclose(sw);
return sw_data;
}
int main()
{
while( 1 )
{
cout << get0() << "," << get1() << "," << get2() << endl;
}
return 0;
}
#include <cstdio>
#include <unistd.h>
using namespace std;
void set0( bool data )
{
FILE *led;
led = fopen("/dev/rtled0", "w" );
if ( data ){
fprintf( led, "1" );
} else {
fprintf( led, "0" );
}
fclose( led );
}
void set1( bool data )
{
FILE *led;
led = fopen("/dev/rtled1", "w" );
if ( data ){
fprintf( led, "1" );
} else {
fprintf( led, "0" );
}
fclose( led );
}
void set2( bool data )
{
FILE *led;
led = fopen("/dev/rtled2", "w" );
if ( data ){
fprintf( led, "1" );
} else {
fprintf( led, "0" );
}
fclose( led );
}
void set3( bool data )
{
FILE *led;
led = fopen("/dev/rtled3", "w" );
if ( data ){
fprintf( led, "1" );
} else {
fprintf( led, "0" );
}
fclose( led );
}
int main()
{
while( 1 )
{
set0( true );
set1( true );
set2( true );
set3( true );
usleep( 500 * 1000 );
set0( false );
set1( false );
set2( false );
set3( false );
usleep( 500 * 1000 );
}
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment