All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.pi4j.plugin.linuxfs.provider.pwm.LinuxFsPwmProviderImpl Maven / Gradle / Ivy

The newest version!
package com.pi4j.plugin.linuxfs.provider.pwm;

/*
 * #%L
 * **********************************************************************
 * ORGANIZATION  :  Pi4J
 * PROJECT       :  Pi4J :: PLUGIN   :: LinuxFS I/O Providers
 * FILENAME      :  LinuxFsPwmProviderImpl.java
 *
 * This file is part of the Pi4J project. More information about
 * this project can be found here:  https://pi4j.com/
 * **********************************************************************
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU Lesser General Public License as
 * published by the Free Software Foundation, either version 3 of the
 * License, or (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Lesser Public License for more details.
 *
 * You should have received a copy of the GNU General Lesser Public
 * License along with this program.  If not, see
 * .
 * #L%
 */


import com.pi4j.boardinfo.util.BoardInfoHelper;
import com.pi4j.io.exception.IOException;
import com.pi4j.io.pwm.Pwm;
import com.pi4j.io.pwm.PwmConfig;
import com.pi4j.io.pwm.PwmProviderBase;
import com.pi4j.io.pwm.PwmType;
import com.pi4j.plugin.linuxfs.internal.LinuxPwm;

import static java.text.MessageFormat.format;

/**
 * 

LinuxFsPwmProviderImpl class.

* * @author Robert Savage (http://www.savagehomeautomation.com) * @version $Id: $Id */ public class LinuxFsPwmProviderImpl extends PwmProviderBase implements LinuxFsPwmProvider { final String pwmFileSystemPath; final int pwmChip; /** *

Constructor for LinuxFsPwmProviderImpl.

*/ public LinuxFsPwmProviderImpl(String pwmFileSystemPath, int pwmChip) { this.id = ID; this.name = NAME; this.pwmFileSystemPath = pwmFileSystemPath; this.pwmChip = pwmChip; } @Override public int getPriority() { // the linux FS PWM driver should be higher priority on RP1 chip return BoardInfoHelper.usesRP1() ? 100 : 50; } /** *

Constructor for LinuxFsPwmProviderImpl.

*/ public LinuxFsPwmProviderImpl(String pwmFileSystemPath) { this.id = ID; this.name = NAME; this.pwmFileSystemPath = pwmFileSystemPath; if(BoardInfoHelper.usesRP1()) { this.pwmChip = LinuxPwm.DEFAULT_RP1_PWM_CHIP; }else{ this.pwmChip = LinuxPwm.DEFAULT_LEGACY_PWM_CHIP; } } /** * {@inheritDoc} */ @Override public Pwm create(PwmConfig config) { // create new I/O instance based on I/O config if (config.pwmType() != PwmType.HARDWARE) throw new IOException(format( "The Linux file system PWM provider does not support software-emulated PWM pins; PIN ADDRESS={0}", config.address())); // create filesystem based PWM instance using instance address (PWM PIN NUMBER) LinuxPwm pwm = new LinuxPwm(this.pwmFileSystemPath, this.pwmChip, config.address()); LinuxFsPwm fsPwm = new LinuxFsPwm(pwm, this, config); this.context.registry().add(fsPwm); return fsPwm; } }




© 2015 - 2024 Weber Informatics LLC | Privacy Policy