-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
488fb10
commit 9332669
Showing
29 changed files
with
3,580 additions
and
0 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<classpath> | ||
<classpathentry kind="src" path="src"/> | ||
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.7"/> | ||
<classpathentry kind="lib" path="libs/cling-core-2.0.1.jar"/> | ||
<classpathentry kind="lib" path="libs/seamless-http-1.1.0.jar"/> | ||
<classpathentry kind="lib" path="libs/seamless-util-1.1.0.jar"/> | ||
<classpathentry kind="lib" path="libs/seamless-xml-1.1.0.jar"/> | ||
<classpathentry kind="lib" path="libs/mpeg-metadata-1.0.0.jar"/> | ||
<classpathentry kind="lib" path="libs/RXTXcomm.jar"/> | ||
<classpathentry kind="output" path="bin"/> | ||
</classpath> |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
/bin |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<projectDescription> | ||
<name>SERenderer</name> | ||
<comment></comment> | ||
<projects> | ||
</projects> | ||
<buildSpec> | ||
<buildCommand> | ||
<name>org.eclipse.jdt.core.javabuilder</name> | ||
<arguments> | ||
</arguments> | ||
</buildCommand> | ||
</buildSpec> | ||
<natures> | ||
<nature>org.eclipse.jdt.core.javanature</nature> | ||
</natures> | ||
</projectDescription> |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
eclipse.preferences.version=1 | ||
encoding/<project>=UTF-8 |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
eclipse.preferences.version=1 | ||
line.separator=\n |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
eclipse.preferences.version=1 | ||
org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled | ||
org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.7 | ||
org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve | ||
org.eclipse.jdt.core.compiler.compliance=1.7 | ||
org.eclipse.jdt.core.compiler.debug.lineNumber=generate | ||
org.eclipse.jdt.core.compiler.debug.localVariable=generate | ||
org.eclipse.jdt.core.compiler.debug.sourceFile=generate | ||
org.eclipse.jdt.core.compiler.problem.assertIdentifier=error | ||
org.eclipse.jdt.core.compiler.problem.enumIdentifier=error | ||
org.eclipse.jdt.core.compiler.source=1.7 |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,115 @@ | ||
#include <Adafruit_NeoPixel.h> | ||
|
||
const int PIN_STRIP = 2; | ||
const int N_LEDS = 60; | ||
|
||
const int PIN_FAN_1 = 5; | ||
const int PIN_FAN_2 = 6; | ||
const int PIN_VIB_1 = 9; | ||
const int PIN_VIB_2 = 10; | ||
|
||
const int DEVICE_TYPE_FAN = 81; | ||
const int DEVICE_TYPE_VIB = 82; | ||
|
||
boolean cmdComplete = false; | ||
String command = ""; | ||
|
||
Adafruit_NeoPixel strip = Adafruit_NeoPixel(N_LEDS, PIN_STRIP, NEO_GRB + NEO_KHZ800); | ||
|
||
void setup() { | ||
Serial.begin(9600); | ||
pinMode(PIN_FAN_1, OUTPUT); | ||
pinMode(PIN_FAN_2, OUTPUT); | ||
pinMode(PIN_VIB_1, OUTPUT); | ||
pinMode(PIN_VIB_2, OUTPUT); | ||
analogWrite(PIN_FAN_1, 0); | ||
analogWrite(PIN_FAN_2, 0); | ||
analogWrite(PIN_VIB_1, 0); | ||
analogWrite(PIN_VIB_2, 0); | ||
strip.begin(); | ||
strip.show(); | ||
} | ||
|
||
void loop() { | ||
// L* controla leds | ||
// LICRGB. liga o led no índice I, até C, onde R = red, G = green, B = blue | ||
// F* controla ventiladores | ||
// FIX. seta o ventilador I com intensidade X (0 até 255) | ||
// V* controla motores vibradores | ||
// VIX. seta o motor vibrador I com intensidade X (0 até 255) | ||
|
||
if (cmdComplete){ | ||
//Serial.println(command); | ||
switch(command[0]) { | ||
case 'L': | ||
processLed(); | ||
break; | ||
case 'F': | ||
processPwm(DEVICE_TYPE_FAN); | ||
break; | ||
case 'V': | ||
processPwm(DEVICE_TYPE_VIB); | ||
break; | ||
default : break; | ||
} | ||
cmdComplete = false; | ||
command = ""; | ||
} | ||
} | ||
|
||
void serialEvent() { | ||
while (Serial.available()) { | ||
char inChar = (char)Serial.read(); | ||
if (inChar == '.') { | ||
cmdComplete = true; | ||
} else { | ||
command += inChar; | ||
} | ||
} | ||
} | ||
|
||
void processPwm(int deviceType){ | ||
int deviceIndex, intensity = 0; | ||
deviceIndex = command[1]; | ||
intensity = command[2]; | ||
if (intensity < 0) | ||
intensity = intensity + 256; | ||
else if (intensity >0 && intensity < 80) | ||
intensity = 80; | ||
if (deviceType == DEVICE_TYPE_FAN){ | ||
//Serial.println("F I=" + (String)deviceIndex + " X="+ (String)intensity); | ||
if (deviceIndex == 1) | ||
analogWrite(PIN_FAN_1, intensity); | ||
else if (deviceIndex == 2) | ||
analogWrite(PIN_FAN_2, intensity); | ||
} | ||
else if (deviceType == DEVICE_TYPE_VIB){ | ||
//Serial.println("V I=" + (String)deviceIndex + " X="+ (String)intensity); | ||
if (intensity > 153) | ||
intensity = 153; | ||
if (deviceIndex == 1) | ||
analogWrite(PIN_VIB_1, intensity); | ||
else if (deviceIndex == 2) | ||
analogWrite(PIN_VIB_2, intensity); | ||
} | ||
} | ||
|
||
void processLed(){ | ||
int ledIndex, count, red, green, blue = 0; | ||
ledIndex = command[1]; | ||
count = command[2]; | ||
red = command[3]; | ||
green = command[4]; | ||
blue = command[5]; | ||
if (red < 0) | ||
red = red + 256; | ||
if (green < 0) | ||
green = green + 256; | ||
if (blue < 0) | ||
blue = blue + 256; | ||
//Serial.println("L I=" + (String)ledIndex + " C=" + (String)count + " R=" + (String)red + " G=" + (String)green + " B=" + (String)blue); | ||
for (int i=0; i<count;i++){ | ||
strip.setPixelColor(i + ledIndex, strip.Color(red,green,blue)); | ||
} | ||
strip.show(); | ||
} |
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
Use -Dcom.sun.xml.internal.bind.v2.runtime.JAXBContextImpl.fastBoot=true |
153 changes: 153 additions & 0 deletions
153
src/br/ufes/inf/lprm/sensoryeffect/renderer/SERendererDevice.java
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,153 @@ | ||
package br.ufes.inf.lprm.sensoryeffect.renderer; | ||
|
||
import java.io.BufferedReader; | ||
import java.io.File; | ||
import java.io.FileInputStream; | ||
import java.io.FileOutputStream; | ||
import java.io.IOException; | ||
import java.io.InputStream; | ||
import java.io.InputStreamReader; | ||
import java.io.OutputStream; | ||
import java.util.Date; | ||
import java.util.Properties; | ||
import java.util.Timer; | ||
|
||
import javax.xml.bind.JAXBContext; | ||
|
||
import org.fourthline.cling.UpnpService; | ||
import org.fourthline.cling.UpnpServiceImpl; | ||
import org.fourthline.cling.binding.LocalServiceBindingException; | ||
import org.fourthline.cling.binding.annotations.AnnotationLocalServiceBinder; | ||
import org.fourthline.cling.model.DefaultServiceManager; | ||
import org.fourthline.cling.model.ValidationException; | ||
import org.fourthline.cling.model.meta.DeviceDetails; | ||
import org.fourthline.cling.model.meta.DeviceIdentity; | ||
import org.fourthline.cling.model.meta.Icon; | ||
import org.fourthline.cling.model.meta.LocalDevice; | ||
import org.fourthline.cling.model.meta.LocalService; | ||
import org.fourthline.cling.model.meta.ManufacturerDetails; | ||
import org.fourthline.cling.model.meta.ModelDetails; | ||
import org.fourthline.cling.model.types.DeviceType; | ||
import org.fourthline.cling.model.types.UDADeviceType; | ||
import org.fourthline.cling.model.types.UDN; | ||
import org.iso.mpeg.mpegv._2010.sedl.SEM; | ||
|
||
import br.ufes.inf.lprm.sensoryeffect.renderer.parser.SEMParser; | ||
import br.ufes.inf.lprm.sensoryeffect.renderer.serial.SerialCom; | ||
import br.ufes.inf.lprm.sensoryeffect.renderer.timer.TimeLine; | ||
|
||
public class SERendererDevice implements Runnable { | ||
|
||
public static TimeLine timeLine = new TimeLine(); | ||
private static final File configFile = new File("config.properties"); | ||
static Properties configProps; | ||
public static boolean debugMode = false; | ||
|
||
public static void main(String[] args) throws Exception { | ||
SEMParser.jaxbContext = JAXBContext.newInstance(SEM.class); | ||
String capabilitiesXmlResource = "br/ufes/inf/lprm/sensoryeffect/renderer/capabilities.xml"; | ||
String capabilitiesMetadata = fileToBuffer(Thread.currentThread().getContextClassLoader().getResourceAsStream(capabilitiesXmlResource)); | ||
SERendererService.setCapabilitiesMetadata(capabilitiesMetadata); | ||
|
||
Thread serverThread = new Thread(new SERendererDevice()); | ||
serverThread.setDaemon(false); | ||
serverThread.start(); | ||
|
||
int interval = 1; | ||
Timer timer = new Timer(); | ||
timer.scheduleAtFixedRate(timeLine, new Date(), interval); | ||
|
||
Properties defaultProps = new Properties(); | ||
if (configFile.exists()){ | ||
InputStream inputStream = new FileInputStream(configFile); | ||
configProps = new Properties(defaultProps); | ||
configProps.load(inputStream); | ||
SerialCom.port = configProps.getProperty("serial_port"); | ||
if ("1".equalsIgnoreCase(configProps.getProperty("emulateDevices")) || "yes".equalsIgnoreCase(configProps.getProperty("emulateDevices")) || | ||
"true".equalsIgnoreCase(configProps.getProperty("emulateDevices")) || "on".equalsIgnoreCase(configProps.getProperty("emulateDevices"))) | ||
SerialCom.emulateDevices = true; | ||
else | ||
SerialCom.emulateDevices = false; | ||
if ("1".equalsIgnoreCase(configProps.getProperty("debugMode")) || "yes".equalsIgnoreCase(configProps.getProperty("debugMode")) || | ||
"true".equalsIgnoreCase(configProps.getProperty("debugMode")) || "on".equalsIgnoreCase(configProps.getProperty("debugMode"))) | ||
debugMode = true; | ||
else | ||
debugMode = false; | ||
inputStream.close(); | ||
} | ||
else { | ||
configProps = new Properties(defaultProps); | ||
configProps.setProperty("serial_port", "COM3"); | ||
configProps.setProperty("emulateDevices", "true"); | ||
configProps.setProperty("debugMode", "true"); | ||
SerialCom.port = configProps.getProperty("serial_port"); | ||
SerialCom.emulateDevices = Boolean.parseBoolean(configProps.getProperty("emulateDevices")); | ||
debugMode = Boolean.parseBoolean(configProps.getProperty("debugMode")); | ||
OutputStream outputStream = new FileOutputStream(configFile); | ||
configProps.store(outputStream, "PlaySEM SE Renderer - Settings"); | ||
outputStream.close(); | ||
} | ||
// new SerialCom(); | ||
} | ||
|
||
private static String fileToBuffer(InputStream is) throws IOException { | ||
StringBuilder sb = new StringBuilder(""); | ||
try (BufferedReader rdr = new BufferedReader(new InputStreamReader(is))) { | ||
for (int c; (c = rdr.read()) != -1;) { | ||
sb.append((char) c); | ||
} | ||
} | ||
return sb.toString(); | ||
} | ||
|
||
public void run() { | ||
try { | ||
final UpnpService upnpService = new UpnpServiceImpl(); | ||
Runtime.getRuntime().addShutdownHook(new Thread() { | ||
@Override | ||
public void run() { | ||
upnpService.shutdown(); | ||
} | ||
}); | ||
upnpService.getRegistry().addDevice(createDevice()); | ||
|
||
} catch (Exception ex) { | ||
System.err.println("Exception occured: " + ex); | ||
ex.printStackTrace(System.err); | ||
System.exit(1); | ||
} | ||
} | ||
|
||
@SuppressWarnings({ "unchecked", "rawtypes" }) | ||
LocalDevice createDevice() throws ValidationException, LocalServiceBindingException, IOException { | ||
|
||
DeviceIdentity identity = new DeviceIdentity(UDN.uniqueSystemIdentifier("SensoryEffectRendererDevice")); | ||
DeviceType type = new UDADeviceType("SensoryEffectRenderer", 1); | ||
DeviceDetails details = | ||
new DeviceDetails( | ||
"LPRM - PlaySEM - Sensory Effect Renderer Device", | ||
new ManufacturerDetails("LPRM"), | ||
new ModelDetails( | ||
"PlaySEM.SERendererDevice.ModelA", | ||
"A remote Sensory Effect Renderer Device. Model A supports Light, Fan and Vibration.", | ||
"v1" | ||
) | ||
); | ||
|
||
String iconResource = "br/ufes/inf/lprm/sensoryeffect/renderer/icon.png"; | ||
Icon icon = new Icon("image/png", 48, 48, 8, "icon.png", Thread.currentThread().getContextClassLoader().getResourceAsStream(iconResource)); | ||
|
||
LocalService<SERendererService> seRendererService = new AnnotationLocalServiceBinder().read(SERendererService.class); | ||
seRendererService.setManager(new DefaultServiceManager(seRendererService, SERendererService.class)); | ||
|
||
try { | ||
return new LocalDevice(identity, type, details, icon, seRendererService); | ||
} | ||
catch (Exception e) { | ||
System.out.print("Exception occured: " + e.getMessage()); | ||
e.printStackTrace(); | ||
return null; | ||
} | ||
} | ||
|
||
} |
Oops, something went wrong.