-
-
Save davelopez01/81a89caf1eb5685883e9913abdcbd06d to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* Reads AIN0 once a second using LJFuse. */ | |
#define PATH "root-ljfuse/My U6/connection/AIN0" | |
#include <stdio.h> /* For file operations */ | |
#include <unistd.h> /* For sleep */ | |
#include <time.h> /* For time */ | |
FILE *fr; | |
int main() { | |
float value; | |
char line[80]; | |
time_t now; | |
while (1) { | |
fr = fopen (PATH, "rt"); | |
if (fgets(line, 80, fr) != NULL) { | |
sscanf (line, "%f", &value); | |
now = time(NULL); | |
printf ("%i,%f\n", (int)now, value); | |
} | |
fclose(fr); | |
sleep(1); | |
} | |
return 0; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
// Read AIN0 once a second | |
$PATH="root-ljfuse/My U6/connection/AIN0"; | |
while (true) { | |
$ain0 = file_get_contents($PATH, true); | |
echo time() .",$ain0"; | |
sleep(1); | |
} | |
?> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Read AIN0 once a second | |
while (1) { | |
open PATH, "root-ljfuse/My U6/connection/AIN0" or die $!; | |
printf "%d,%f\n", int(time()), <PATH>; | |
sleep 1; | |
close PATH; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Read AIN0 once a second | |
from time import time, sleep | |
PATH = "root-ljfuse/My U6/connection/AIN0" | |
while True: | |
f = file(PATH) | |
print "%d,%f" % (int(time()), float(f.read())) | |
sleep(1) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Read AIN0 once a second | |
AIN0_filepath = 'root-ljfuse/My U6/connection/AIN0' | |
while true | |
f = File.open(AIN0_filepath, 'r') | |
puts "%i,%f" % [ Time.now.to_i, f.read.to_f ] | |
f.close | |
sleep 1 | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Read AIN0 once a second | |
while (true) { | |
val ain0 = io.Source.fromFile("root-ljfuse/My U6/connection/AIN0").mkString | |
print(System.currentTimeMillis()/1000 + "," + ain0) | |
Thread.sleep(1000) | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Read AIN0 once a second | |
AIN0_PATH="root-ljfuse/My U6/connection/AIN0" | |
while true | |
do | |
echo $(date "+%s"),$(cat "$AIN0_PATH") | |
sleep 1 | |
done |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Read AIN0 once a second | |
import java.io.BufferedReader; | |
import java.io.FileNotFoundException; | |
import java.io.FileReader; | |
import java.io.IOException; | |
public class LogAIN0 { | |
public static void main(String[] args) { | |
LogAIN0 logAin0 = new LogAIN0(); | |
logAin0.log("root-ljfuse/My U6/connection/AIN0"); | |
} | |
public void log(String path){ | |
while (true) { | |
try { | |
FileReader fr = new FileReader(path); | |
BufferedReader br = new BufferedReader(fr); | |
String line; | |
line = br.readLine(); | |
System.out.println(System.currentTimeMillis()/1000 + "," + line); | |
br.close(); | |
Thread.sleep(1000); | |
} catch (FileNotFoundException e) { | |
e.printStackTrace(); | |
} catch (IOException e) { | |
e.printStackTrace(); | |
} catch (InterruptedException e) { | |
e.printStackTrace(); | |
} | |
} | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* Toggles FIO0 once a second using LJFuse. */ | |
#define PATH "root-ljfuse/My U6/connection/FIO0" | |
#include <stdio.h> /* For file operations */ | |
#include <unistd.h> /* For sleep */ | |
#include <time.h> /* For time */ | |
FILE *fr; | |
int main() { | |
int state = 1; | |
char line[80]; | |
time_t now; | |
while (1) { | |
fr = fopen (PATH, "w"); | |
if (state == 0) { | |
printf("Setting FIO0 Low.\n"); | |
fprintf(fr, "0"); | |
state = 1; | |
} | |
else { | |
printf("Setting FIO0 High.\n"); | |
fprintf(fr, "1"); | |
state = 0; | |
} | |
fclose(fr); | |
sleep(1); | |
} | |
return 0; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
// Toggle FIO0's state once a second | |
$PATH="root-ljfuse/My U6/connection/FIO0"; | |
# Set FIO0 to digital output | |
$handle = fopen($PATH."-dir", 'w'); | |
fwrite($handle, "1"); | |
fclose($handle); | |
$state = 1; | |
while (true) { | |
$handle = fopen($PATH, 'w'); | |
if ($state) { | |
echo "Setting FIO0 High.\n"; | |
} | |
else { | |
echo "Setting FIO0 Low.\n"; | |
} | |
fwrite($handle, $state); | |
fclose($handle); | |
$state = $state ? 0 : 1; | |
sleep(1); | |
} | |
?> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Set FIO0 to digital output | |
open PATH, ">root-ljfuse/My U6/connection/FIO0-dir" or die $!; | |
print PATH "1"; | |
close PATH; | |
$state = 1; | |
# Toggle FIO0's state once a second | |
while (1) { | |
open PATH, ">root-ljfuse/My U6/connection/FIO0" or die $!; | |
if ($state) { | |
print "Setting FIO0 Low.\n"; | |
} else { | |
print "Setting FIO0 High.\n"; | |
} | |
print PATH $state; | |
close PATH; | |
$state = $state ? 0 : 1; | |
sleep(1); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Toggle FIO0's state once a second | |
from time import sleep | |
PATH = "root-ljfuse/My U6/connection/FIO0" | |
# Set FIO0 to digital output | |
f = file(PATH+"-dir", "w") | |
f.write("1") | |
f.close() | |
state = True | |
while True: | |
f = file(PATH, "w") | |
if state: | |
print "Setting FIO0 Low." | |
else: | |
print "Setting FIO0 High." | |
f.write(str(int(state))) | |
f.close() | |
state = not state | |
sleep(1) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Toggle FIO0's state once a second | |
FIO0_filepath = 'root-ljfuse/My U6/connection/FIO0' | |
# Set FIO0 to digital output | |
f = File.open(FIO0_filepath+"-dir", 'w') | |
f.write(1) | |
f.close | |
state = 1 | |
while true | |
f = File.open(FIO0_filepath, 'w') | |
if state == 0 | |
puts "Setting FIO0 Low." | |
else | |
puts "Setting FIO0 High." | |
end | |
f.write(state) | |
f.close | |
state = if state == 0 then 1 else 0 end | |
sleep 1 | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Toggle FIO0's state once a second | |
import java.io.FileWriter | |
import java.io.BufferedWriter | |
val fio0path = "root-ljfuse/My U6/connection/FIO0" | |
// Set FIO0 to digital output | |
var fw = new BufferedWriter(new FileWriter(fio0path + "-dir")) | |
fw.write("1") | |
fw.close() | |
var state = true; | |
while (true) { | |
var fw = new BufferedWriter(new FileWriter(fio0path)) | |
if (state) { | |
println("Setting FIO0 High.") | |
fw.write("1") | |
} else { | |
println("Setting FIO0 Low.") | |
fw.write("0") | |
} | |
fw.close() | |
state = !state | |
Thread.sleep(1000) | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Toggle FIO0's state once a second | |
FIO0_PATH="root-ljfuse/My U6/connection/FIO0" | |
echo 1 > "${FIO0_PATH}-dir" | |
STATE=1 | |
while true | |
do | |
if [ $STATE -eq 1 ] | |
then | |
STATE=0 | |
echo "Setting FIO0 Low." | |
else | |
STATE=1 | |
echo "Setting FIO0 High." | |
fi | |
echo $STATE > "$FIO0_PATH" | |
sleep 1 | |
done |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Toggle FIO0's state once a second | |
import java.io.BufferedWriter; | |
import java.io.FileNotFoundException; | |
import java.io.FileWriter; | |
import java.io.IOException; | |
public class ToggleFIO0 { | |
public static void main(String[] args) { | |
ToggleFIO0 toggleFio0 = new ToggleFIO0(); | |
toggleFio0.toggle("root-ljfuse/My U6/connection/FIO0"); | |
} | |
public void toggle(String path){ | |
try { | |
// Set FIO0 to digital output | |
FileWriter fw = new FileWriter(path + "-dir"); | |
BufferedWriter bw = new BufferedWriter(fw); | |
bw.write("1"); | |
bw.close(); | |
boolean state = true; | |
while (true) { | |
fw = new FileWriter(path); | |
bw = new BufferedWriter(fw); | |
if (state) { | |
System.out.println("Setting FIO0 High."); | |
bw.write("1"); | |
} else { | |
System.out.println("Setting FIO0 Low."); | |
bw.write("0"); | |
} | |
state = !state; | |
bw.close(); | |
Thread.sleep(1000); | |
} | |
} catch (FileNotFoundException e) { | |
e.printStackTrace(); | |
} catch (IOException e) { | |
e.printStackTrace(); | |
} catch (InterruptedException e) { | |
e.printStackTrace(); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment