Skip to content

Commit

Permalink
linux battery start
Browse files Browse the repository at this point in the history
  • Loading branch information
brad.zdanivsky committed Jan 4, 2012
1 parent 834ad86 commit ba1a47c
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 6 deletions.
18 changes: 16 additions & 2 deletions oculus/WEB-INF/src/oculus/BatteryLife.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ public class BatteryLife {
private String query;
private ActiveXComponent axWMI;

private final String os = System.getProperty("os.name");
private static final String os = System.getProperty("os.name");

private boolean battcharging = false;
private boolean batterypresent = false;
Expand Down Expand Up @@ -60,7 +60,21 @@ public void init(Application parent){
query = "Select * from Win32_Battery";
axWMI = new ActiveXComponent(connectStr);

} else System.out.println("linux battery... ");
} else /* if(.equals("linux")*/ {

System.out.println("linux battery... ");

// cat /proc/acpi/battery/BAT0/state
String[] result = Util.systemCallBlocking("cat /proc/acpi/battery/BAT0/state").split(":");

for(int i = 0 ; i < result.length ; i++){
if(result[i].equals("present")){
// if()
}
}


}
}
}

Expand Down
21 changes: 17 additions & 4 deletions oculus/WEB-INF/src/oculus/Util.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@

public class Util {

private static final String os = System.getProperty("os.name");
private static final int PRECISION = 2;

/**
Expand Down Expand Up @@ -210,7 +211,10 @@ public static boolean copyfile(String srFile, String dtFile) {
* @param str is the command to run, like: "restart
*
*/
public static void systemCallBlocking(final String args) {
public static String systemCallBlocking(final String args) {

String result = null;

try {

long start = System.currentTimeMillis();
Expand All @@ -220,15 +224,18 @@ public static void systemCallBlocking(final String args) {

String line = null;
System.out.println(proc.hashCode() + "OCULUS: exec(): " + args);
while ((line = procReader.readLine()) != null)
while ((line = procReader.readLine()) != null){
System.out.println(proc.hashCode() + " systemCallBlocking() : " + line);

result += line;
}
System.out.println("OCULUS: process exit value = " + proc.exitValue());
System.out.println("OCULUS: bocking run time = " + (System.currentTimeMillis()-start) + " ms");

} catch (Exception e) {
e.printStackTrace();
}

return result;
}

/**
Expand Down Expand Up @@ -367,7 +374,9 @@ public static void setSystemVolume(int percent, Application app){
* is the phrase to turn from text to speech
*/
public static void beep() {
systemCall("nircmdc.exe beep 500 1000");
if(os.startsWith("windows")){
systemCall("nircmdc.exe beep 500 1000");
}else log("need linux beep"); // TODO:
}

public static String[] tail ( File file, String match ){
Expand Down Expand Up @@ -452,4 +461,8 @@ public static void debug(String str, Object c) {
public static void log(String str, Object c) {
System.out.println("OCULUS: " + c.getClass().getName() + ", " +str);
}

public static void log(String str) {
System.out.println("OCULUS: Util, " +str);
}
}

0 comments on commit ba1a47c

Please sign in to comment.