Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit31079af

Browse files
committed
Reading the short is definitely faster. Not sure about how to interpret it.
1 parent8a9a9cf commit31079af

File tree

1 file changed

+29
-16
lines changed

1 file changed

+29
-16
lines changed

‎src/main/java/ev3dev/utils/Sysfs2.java‎

Lines changed: 29 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
packageev3dev.utils;
22

3+
importjava.io.DataInputStream;
34
importjava.io.File;
45
importjava.io.IOException;
56
importjava.io.InputStream;
@@ -110,7 +111,7 @@ public static int readInteger(final String filePath) {
110111
}
111112

112113
publicstaticfloatreadFloat(finalStringfilePath) {
113-
returnFloat.parseFloat(readString(filePath));
114+
return(float)readS16CustomChannel(/*filePath*/);
114115
}
115116

116117
/**
@@ -161,22 +162,8 @@ public static boolean writeBytes(final String path, final byte[] value) {
161162
}
162163

163164
//Skipping much of the boilerplate between InputStream and Channels. 12 ms, but 6 ms with the static path!
164-
//static float fetchSampleCustomChannel() {
165-
// return Float.parseFloat(readStringCustomChannel());
166-
//}
167-
168-
//Static Setter to test the idea from @dwalend
169-
/*
170-
public static void setPathString(String pathString) {
171-
Sysfs2.pathString = pathString;
172-
}
173-
174-
public static String pathString = "";
175165

176-
private static final byte[] buffer = new byte[8];
177-
static final Path staticPath = Paths.get(pathString);
178-
*/
179-
publicstaticStringreadStringCustomChannel(Pathpath) {
166+
staticStringreadStringCustomChannel(Pathpath) {
180167
finalbyte[]buffer =newbyte[8];
181168
try {
182169
try (InputStreamin =customInputStream(path)) {
@@ -194,4 +181,30 @@ static InputStream customInputStream(final Path path) throws IOException {
194181
returnChannels.newInputStream(rbc);
195182
}
196183

184+
staticintreadS16CustomChannel() {
185+
finalPathusePath =Paths.get("/sys/class/lego-sensor/sensor0/bin_data");
186+
187+
try {
188+
try (DataInputStreamin =dataInputStream(usePath)) {
189+
// return Short.reverseBytes(in.readShort()); //Nope 1 = 8193
190+
// return in.readShort(); //Nope 1 = 288
191+
intch1 =in.read();
192+
intch2 =in.read();
193+
194+
System.out.println(ch1 +" " +ch2);
195+
196+
returnch1 <<8 |ch2 &0x00FF;
197+
198+
}
199+
}catch (IOExceptione) {
200+
thrownewRuntimeException("Problem reading path: " +usePath,e);
201+
}
202+
}
203+
204+
staticDataInputStreamdataInputStream(finalPathpath)throwsIOException {
205+
ReadableByteChannelrbc =Files.newByteChannel(path);
206+
returnnewDataInputStream(Channels.newInputStream(rbc));
207+
}
208+
209+
197210
}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp