當前位置: 首頁>>代碼示例>>Java>>正文


Java PeripheralManagerService.openPwm方法代碼示例

本文整理匯總了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;
}
 
開發者ID:leinardi,項目名稱:androidthings-kuman-sm9,代碼行數:28,代碼來源:PwrA53A.java

示例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);
    }
}
 
開發者ID:androidthings,項目名稱:sample-simplepio,代碼行數:26,代碼來源:PWMActivity.java

示例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;
    }
}
 
開發者ID:androidthings,項目名稱:contrib-drivers,代碼行數:17,代碼來源:Speaker.java

示例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;
    }
}
 
開發者ID:androidthings,項目名稱:contrib-drivers,代碼行數:21,代碼來源:Servo.java


注:本文中的com.google.android.things.pio.PeripheralManagerService.openPwm方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。