本文整理汇总了Java中com.google.android.things.pio.PeripheralManagerService.openPwm方法的典型用法代码示例。如果您正苦于以下问题:Java PeripheralManagerService.openPwm方法的具体用法?Java PeripheralManagerService.openPwm怎么用?Java PeripheralManagerService.openPwm使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.google.android.things.pio.PeripheralManagerService
的用法示例。
在下文中一共展示了PeripheralManagerService.openPwm方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: tryToOpenPwm
import com.google.android.things.pio.PeripheralManagerService; //导入方法依赖的package包/类
/**
* Tries to open the PWM devices.
* Currently Android Things doesn't allow to set custom pins for the PWM and the PWR.A53.A
* is expecting to get it on pin 20 and pin 13. Unfortunately Android uses pin 18 and 13.
* If you want to use PWM with this board please star this issue:
* https://issuetracker.google.com/issues/70115494
*/
private boolean tryToOpenPwm(PeripheralManagerService pioService) {
try {
mPwmEnB = pioService.openPwm(PWR_A53_A_ENB_PWM);
mPwmEnA = pioService.openPwm(PWR_A53_A_ENA_PWM);
return true;
} catch (IOException e) {
Log.e(TAG, "Unable to open PWMs, falling back to SoftPwm", e);
try {
if (mPwmEnA != null) {
mPwmEnA.close();
}
if (mPwmEnB != null) {
mPwmEnB.close();
}
} catch (IOException ignored) {
// NO-OP
}
}
return false;
}
示例2: onCreate
import com.google.android.things.pio.PeripheralManagerService; //导入方法依赖的package包/类
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
Log.i(TAG, "Starting PWMActivity");
PeripheralManagerService service = new PeripheralManagerService();
try {
String pinName = BoardDefaults.getPWMPort();
mActivePulseDuration = MIN_ACTIVE_PULSE_DURATION_MS;
mPwm = service.openPwm(pinName);
// Always set frequency and initial duty cycle before enabling PWM
mPwm.setPwmFrequencyHz(1000 / PULSE_PERIOD_MS);
mPwm.setPwmDutyCycle(mActivePulseDuration);
mPwm.setEnabled(true);
// Post a Runnable that continuously change PWM pulse width, effectively changing the
// servo position
Log.d(TAG, "Start changing PWM pulse");
mHandler.post(mChangePWMRunnable);
} catch (IOException e) {
Log.e(TAG, "Error on PeripheralIO API", e);
}
}
示例3: Speaker
import com.google.android.things.pio.PeripheralManagerService; //导入方法依赖的package包/类
/**
* Create a Speaker connected to the given PWM pin name
*/
public Speaker(String pin) throws IOException {
PeripheralManagerService pioService = new PeripheralManagerService();
Pwm device = pioService.openPwm(pin);
try {
connect(device);
} catch (IOException|RuntimeException e) {
try {
close();
} catch (IOException|RuntimeException ignored) {
}
throw e;
}
}
示例4: Servo
import com.google.android.things.pio.PeripheralManagerService; //导入方法依赖的package包/类
/**
* Create a new Servo that connects to the named pin and uses the specified frequency
*
* @param pin the PWM pin name
* @param frequencyHz the frequency in Hertz
* @throws IOException
*/
public Servo(String pin, double frequencyHz) throws IOException {
PeripheralManagerService pioService = new PeripheralManagerService();
Pwm device = pioService.openPwm(pin);
try {
connect(device, frequencyHz);
} catch (IOException | RuntimeException e) {
try {
close();
} catch (IOException | RuntimeException ignored) {
}
throw e;
}
}