Skip to content

Commit 0a74486

Browse files
committed
Fix to allow openPwmOutput to take second frequency argument #8
1 parent 89b6d21 commit 0a74486

File tree

6 files changed

+35
-22
lines changed

6 files changed

+35
-22
lines changed

include/proxy.h include/javaproxy.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -205,7 +205,7 @@ struct JavaProxy {
205205
int result = 0;
206206
if (_instance != nullptr) {
207207
attachCurrentThread();
208-
jmethodID method = g_env->GetMethodID(_clazz, name, "()F");
208+
jmethodID method = g_env->GetMethodID(_clazz, name, "(F)V");
209209
if (method != nullptr) {
210210
g_env->CallVoidMethod(_instance, method, value);
211211
}

ioio/api.json

+1
Original file line numberDiff line numberDiff line change
@@ -229,6 +229,7 @@
229229
{
230230
"name": "PwmOutput",
231231
"comment": "A pin used for PWM (Pulse-Width Modulation) output. A PWM pin produces a logic-level PWM signal. These signals are typically used for simulating analog outputs for controlling the intensity of LEDs, the rotation speed of motors, etc. They are also frequently used for controlling hobby servo motors. PwmOutput instances are obtained by calling IOIO#openPwmOutput. When used for motors and LEDs, a frequency of several KHz is typically used, where there is a trade-off between switching power-loses and smoothness of operation. The pulse width is typically set by specifying the duty cycle, with the setDutyCycle method. A duty cycle of 0 is \"off\", a duty cycle of 1 is \"on\", and every intermediate value produces an intermediate intensity. Please note that any devices consuming more than 20mA of current (e.g. motors) should not by directly connected the the IOIO pins, but rather through an amplification circuit suited for the specific load. When used for hobby servos, the PWM signal is rather used for encoding of the desired angle the motor should go to. By standard, a 100Hz signal is used and the pulse width is varied between 1ms and 2ms (corresponding to both extremes of the shaft angle), using setPulseWidth. The instance is alive since its creation. If the connection with the IOIO drops at any point, the instance transitions to a disconnected state, in which every attempt to use the pin (except close()) will throw a ConnectionLostException. Whenever close() is invoked the instance may no longer be used. Any resources associated with it are freed and can be reused. Typical usage (fading LED):",
232+
"pins": 2,
232233
"methods": [
233234
{
234235
"name": "setDutyCycle",

ioio/ioio/src/main/java/ioio/smallbasic/pc/SerialPortIOIOConnection.java

+13-14
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,14 @@
11
package ioio.smallbasic.pc;
22

33
import com.fazecast.jSerialComm.SerialPort;
4+
import ioio.lib.api.IOIOConnection;
5+
import ioio.lib.api.exception.ConnectionLostException;
6+
import ioio.lib.spi.Log;
47

58
import java.io.IOException;
69
import java.io.InputStream;
710
import java.io.OutputStream;
811

9-
import ioio.lib.api.IOIOConnection;
10-
import ioio.lib.api.exception.ConnectionLostException;
11-
import ioio.lib.spi.Log;
12-
1312
public class SerialPortIOIOConnection implements IOIOConnection {
1413
private static final String TAG = "SerialPortIOIOConnection";
1514
private static final int READ_TIMEOUT_MILLIS = 20000;
@@ -27,14 +26,8 @@ public SerialPortIOIOConnection(String portName) {
2726
}
2827

2928
@Override
30-
public void waitForConnect() throws ConnectionLostException {
31-
if (!abort && serialPort.openPort()) {
32-
inputStream = serialPort.getInputStream();
33-
outputStream = serialPort.getOutputStream();
34-
serialPort.setDTR();
35-
} else {
36-
throw new ConnectionLostException();
37-
}
29+
public boolean canClose() {
30+
return serialPort.isOpen();
3831
}
3932

4033
@Override
@@ -67,7 +60,13 @@ public OutputStream getOutputStream() throws ConnectionLostException {
6760
}
6861

6962
@Override
70-
public boolean canClose() {
71-
return true;
63+
public void waitForConnect() throws ConnectionLostException {
64+
if (!abort && serialPort.openPort()) {
65+
inputStream = serialPort.getInputStream();
66+
outputStream = serialPort.getOutputStream();
67+
serialPort.setDTR();
68+
} else {
69+
throw new ConnectionLostException();
70+
}
7271
}
7372
}

ioio/ioio/src/main/java/ioio/smallbasic/pc/SerialPortIOIOConnectionBootstrap.java

+4-5
Original file line numberDiff line numberDiff line change
@@ -30,18 +30,17 @@
3030
package ioio.smallbasic.pc;
3131

3232
import com.fazecast.jSerialComm.SerialPort;
33+
import ioio.lib.api.IOIOConnection;
34+
import ioio.lib.spi.IOIOConnectionBootstrap;
35+
import ioio.lib.spi.IOIOConnectionFactory;
36+
import ioio.lib.spi.Log;
3337

3438
import java.util.Arrays;
3539
import java.util.Collection;
3640
import java.util.Collections;
3741
import java.util.LinkedList;
3842
import java.util.List;
3943

40-
import ioio.lib.api.IOIOConnection;
41-
import ioio.lib.spi.IOIOConnectionBootstrap;
42-
import ioio.lib.spi.IOIOConnectionFactory;
43-
import ioio.lib.spi.Log;
44-
4544
public class SerialPortIOIOConnectionBootstrap implements IOIOConnectionBootstrap {
4645
private static final String TAG = "SerialPortIOIOConnectionBootstrap";
4746

ioio/main.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
#include "include/var.h"
1414
#include "include/module.h"
1515
#include "include/param.h"
16-
#include "include/proxy.h"
16+
#include "include/javaproxy.h"
1717

1818
#define CLASS_ANALOGINPUT "ioio/smallbasic/AnalogInputImpl"
1919
#define CLASS_DIGITALINPUT "ioio/smallbasic/DigitalInputImpl"
@@ -122,7 +122,7 @@ FUNC_SIG lib_func[] = {
122122
{1, 1, "OPENDIGITALINPUT", cmd_opendigitalinput},
123123
{1, 1, "OPENDIGITALOUTPUT", cmd_opendigitaloutput},
124124
{1, 1, "OPENPULSEINPUT", cmd_openpulseinput},
125-
{1, 1, "OPENPWMOUTPUT", cmd_openpwmoutput},
125+
{2, 2, "OPENPWMOUTPUT", cmd_openpwmoutput},
126126
{2, 2, "OPENTWIMASTER", cmd_opentwimaster},
127127
{4, 4, "OPENSPIMASTER", cmd_openspimaster},
128128
};

ioio/samples/pwm.bas

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
import ioio
2+
3+
led = ioio.openPwmOutput(46, 99)
4+
5+
print "wait for connect"
6+
ioio.waitForConnect(10)
7+
print "ready!!!"
8+
9+
for DutyCycle = 0 to 1 step 0.1
10+
led.setDutyCycle(DutyCycle)
11+
delay 100
12+
next
13+
14+
print "Done"

0 commit comments

Comments
 (0)