Skip to content

Commit

Permalink
Fixing basic poller, SysFsPin path issue and renaming modules
Browse files Browse the repository at this point in the history
  • Loading branch information
mpbarnwell committed Nov 20, 2016
1 parent 26e1544 commit 08c7cd2
Show file tree
Hide file tree
Showing 11 changed files with 126 additions and 9 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ A simple library for reading input and writing output to GPIO pins on Linux plat

## Usage
SimpleGPIO is split into three components
- **simplegpio-core** - Core components including a fallback input poller based on a naieve pure Java implementation
- **simplegpio-core** - Core components including a fallback input poller based on a naive pure Java implementation
- **simplegpio-module-libbulldog** - An enhanced input poller using JNI and libbulldog; this version offers most stability and performance but least portability - the libbulldog library should be [downloaded](http://search.maven.org/#search%7Cga%7C1%7Ca%3A%22bulldog-linux-native-raspberrypi%22) and named 'libbulldog-linux.so'
- **simplegpio-module-epoll** - A performant and slightly more portable input poller based on calls to epoll using JNA

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,11 @@
* other feature activation during that time.</p>
*
* <p>Mostly, the pin is just used to grab a feature that is available on
* it:<br/>
* {@code DigitalOutput output = pin.as(DigitalOutput.class);}<br/>
* {@code Pwm pwm = pin.as(Pwm.class); }
* it:
* {@code
* DigitalOutput output = pin.as(DigitalOutput.class);
* Pwm pwm = pin.as(Pwm.class);
* }
* </p>
*/
public class Pin {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,6 @@ public BasicPollResult(byte... data) {

@Override
public byte[] getData() {
return new byte[0];
return data;
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,22 @@
package com.doordeck.simplegpio.gpio.io;

/*
* (C) Copyright 2016 Doordeck Limited and others.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/

import com.doordeck.simplegpio.gpio.event.PollResult;
import com.doordeck.simplegpio.spi.InputPoller;
import com.doordeck.simplegpio.util.BulldogUtil;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,22 @@
package com.doordeck.simplegpio.gpio.io;

/*
* (C) Copyright 2016 Doordeck Limited and others.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/

import com.doordeck.simplegpio.gpio.event.BasicPollResult;
import com.doordeck.simplegpio.util.BulldogUtil;
import org.slf4j.Logger;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,22 @@
package com.doordeck.simplegpio.gpio.io;

/*
* (C) Copyright 2016 Doordeck Limited and others.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/

import com.doordeck.simplegpio.spi.InputPoller;
import com.doordeck.simplegpio.spi.InputPollerFactory;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ public Signal getValue() {
}

public void setValue(Signal signal) {
echoToFile(String.valueOf(signal.getNumericValue()), getPinDirectory());
echoToFile(String.valueOf(signal.getNumericValue()), getValueFilePath());
}

private void echoToFile(String value, Path file) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,12 @@ public static InputPollerFactory locate() {
boolean valid = factory.isValid();
LOG.debug("Trying to load {}... {}", factory.getClass().getSimpleName(), valid ? "success" : "failed");
if (valid) {
LOG.info("Using {} for GPIO input polling", factory.getClass().getSimpleName());
return factory;
}
}

LOG.info("Using {} for GPIO input polling", BasicInputPollerFactory.class.getSimpleName());
return new BasicInputPollerFactory();
}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,52 @@
package com.doordeck.simplegpio;

/*
* (C) Copyright 2016 Doordeck Limited and others.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/

import org.junit.Test;
import static org.junit.Assert.assertEquals;

public class SignalTest {

@Test
public void testSignal() {
assertEquals(Signal.Low, Signal.fromBooleanValue(false));
assertEquals(Signal.High, Signal.fromBooleanValue(true));

assertEquals(Signal.Low, Signal.fromNumericValue(0));
assertEquals(Signal.High, Signal.fromNumericValue(-1));
assertEquals(Signal.High, Signal.fromNumericValue(1));

assertEquals(Signal.Low, Signal.fromString("0"));
assertEquals(Signal.High, Signal.fromString("1"));
assertEquals(Signal.Low, Signal.fromString("-0"));

assertEquals(Signal.Low, Signal.fromString("LOW"));
assertEquals(Signal.High, Signal.fromString("HIGH"));
assertEquals(Signal.Low, Signal.fromString("low"));
}

@Test(expected = IllegalArgumentException.class)
public void testSignalFromNullStringThrowsException() {
Signal.fromString(null);
}

@Test(expected = IllegalArgumentException.class)
public void testSignalFromNonsenseStringThrowsException() {
Signal.fromString("highlow");
}
}
2 changes: 1 addition & 1 deletion simplegpio-module-epoll/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
</parent>
<modelVersion>4.0.0</modelVersion>

<artifactId>simplegpio-jna</artifactId>
<artifactId>simplegpio-module-epoll</artifactId>

<properties>
<jna.version>4.2.1</jna.version>
Expand Down
17 changes: 15 additions & 2 deletions simplegpio-module-libbulldog/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,10 @@
</parent>
<modelVersion>4.0.0</modelVersion>

<artifactId>simplegpio-libbulldog</artifactId>
<artifactId>simplegpio-module-libbulldog</artifactId>

<properties>
<bulldog.version>0.2.0</bulldog.version>
<bulldog.version>0.2.1</bulldog.version>
</properties>

<dependencies>
Expand All @@ -34,6 +34,19 @@
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>io.silverspoon</groupId>
<artifactId>bulldog-linux-native-raspberrypi</artifactId>
<version>${bulldog.version}</version>
<type>so</type>
<scope>provided</scope>
<exclusions>
<exclusion>
<groupId>io.silverspoon</groupId>
<artifactId>bulldog-linux</artifactId>
</exclusion>
</exclusions>
</dependency>
</dependencies>

</project>

0 comments on commit 08c7cd2

Please sign in to comment.