001package com.pi4j.platform;
002
003/*
004 * #%L
005 * **********************************************************************
006 * ORGANIZATION  :  Pi4J
007 * PROJECT       :  Pi4J :: Java Library (Core)
008 * FILENAME      :  Platform.java
009 *
010 * This file is part of the Pi4J project. More information about
011 * this project can be found here:  http://www.pi4j.com/
012 * **********************************************************************
013 * %%
014 * Copyright (C) 2012 - 2016 Pi4J
015 * %%
016 * This program is free software: you can redistribute it and/or modify
017 * it under the terms of the GNU Lesser General Public License as
018 * published by the Free Software Foundation, either version 3 of the
019 * License, or (at your option) any later version.
020 *
021 * This program is distributed in the hope that it will be useful,
022 * but WITHOUT ANY WARRANTY; without even the implied warranty of
023 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
024 * GNU General Lesser Public License for more details.
025 *
026 * You should have received a copy of the GNU General Lesser Public
027 * License along with this program.  If not, see
028 * <http://www.gnu.org/licenses/lgpl-3.0.html>.
029 * #L%
030 */
031
032import com.pi4j.io.gpio.BananaPiGpioProvider;
033import com.pi4j.io.gpio.BananaProGpioProvider;
034import com.pi4j.io.gpio.GpioProvider;
035import com.pi4j.io.gpio.OdroidGpioProvider;
036import com.pi4j.io.gpio.RaspiGpioProvider;
037import com.pi4j.io.i2c.I2CFactoryProvider;
038import com.pi4j.io.i2c.impl.I2CFactoryProviderBananaPi;
039import com.pi4j.io.i2c.impl.I2CFactoryProviderOdroid;
040import com.pi4j.io.i2c.impl.I2CFactoryProviderRaspberryPi;
041import com.pi4j.system.SystemInfoProvider;
042import com.pi4j.system.impl.BananaPiSystemInfoProvider;
043import com.pi4j.system.impl.BananaProSystemInfoProvider;
044import com.pi4j.system.impl.OdroidSystemInfoProvider;
045import com.pi4j.system.impl.RaspiSystemInfoProvider;
046
047/**
048 * <p>
049 * This enumeration defines the platforms supported by Pi4J.
050 * </p>
051 *
052 * @see <a href="http://www.pi4j.com/">http://www.pi4j.com/</a>
053 * @author Robert Savage (<a
054 *         href="http://www.savagehomeautomation.com">http://www.savagehomeautomation.com</a>)
055 */
056public enum Platform {
057    // SUPPORTED PLATFORMS
058    RASPBERRYPI("raspberrypi", "Raspberry Pi"),
059    BANANAPI("bananapi", "BananaPi"),
060    BANANAPRO("bananapro", "BananaPro"),
061    ODROID("odroid", "Odroid");
062
063    // private variables
064    protected String platformId = null;
065    protected String label = null;
066
067    /**
068     * Private default constructor
069     * @param platformId
070     * @param label
071     */
072    private Platform(String platformId, String label) {
073        this.platformId = platformId;
074        this.label = label;
075    }
076
077    /**
078     * Get the platform's friendly string name/label.
079     * @return label of platform
080     */
081    public String getLabel() {
082        return this.label;
083    }
084
085    /**
086     * Get the platform's friendly string name/label.
087     * @return label of platform
088     */
089    public String label() {
090        return getLabel();
091    }
092
093    /**
094     * Get the platform's unique identifier string.
095     * @return platform id string
096     */
097    public String getId() {
098        return platformId;
099    }
100
101    /**
102     * Get the platform's unique identifier string.
103     * @return platform id string
104     */
105    public String id() {
106        return getId();
107    }
108
109    /**
110     * Lookup a platform enumeration by the platform's unique identifier string.
111     * @return platform enumeration
112     */
113    public static Platform fromId(String platformId) {
114        for(Platform platform : Platform.values()) {
115            if(platform.id().equalsIgnoreCase(platformId))
116                return platform;
117        }
118        return null;
119    }
120
121
122    public GpioProvider getGpioProvider() {
123        return getGpioProvider(this);
124    }
125
126    public static GpioProvider getGpioProvider(Platform platform) {
127        // create the provider based on the PlatformManager's selected platform
128        switch (PlatformManager.getPlatform()) {
129            case RASPBERRYPI: {
130                return new RaspiGpioProvider();
131            }
132            case BANANAPI: {
133                return new BananaPiGpioProvider();
134            }
135            case BANANAPRO: {
136                return new BananaProGpioProvider();
137            }
138            case ODROID: {
139                return new OdroidGpioProvider();
140            }
141            default: {
142                // if a platform cannot be determine, then assume it's the default RaspberryPi
143                return new RaspiGpioProvider();
144            }
145        }
146    }
147
148    public I2CFactoryProvider getI2CFactoryProvider() {
149        return getI2CFactoryProvider(this);
150    }
151
152    public static I2CFactoryProvider getI2CFactoryProvider(Platform platform) {
153        // return the I2C provider based on the provided platform
154        switch(platform) {
155            case RASPBERRYPI: {
156                return new I2CFactoryProviderRaspberryPi();
157            }
158            case BANANAPI: {
159                return new I2CFactoryProviderBananaPi();
160            }
161            case BANANAPRO: {
162                return new I2CFactoryProviderBananaPi();
163            }
164            case ODROID: {
165                return new I2CFactoryProviderOdroid();
166            }
167            default: {
168                // if a platform cannot be determine, then assume it's the default RaspberryPi
169                return new I2CFactoryProviderRaspberryPi();
170            }
171        }
172    }
173
174    public SystemInfoProvider getSystemInfoProvider() {
175        return getSystemInfoProvider(this);
176    }
177
178    public static SystemInfoProvider getSystemInfoProvider(Platform platform) {
179        // return the system info provider based on the provided platform
180        switch(platform) {
181            case RASPBERRYPI: {
182                return new RaspiSystemInfoProvider();
183            }
184            case BANANAPI: {
185                return new BananaPiSystemInfoProvider();
186            }
187            case BANANAPRO: {
188                return new BananaProSystemInfoProvider();
189            }
190            case ODROID: {
191                return new OdroidSystemInfoProvider();
192            }
193            default: {
194                // if a platform cannot be determine, then assume it's the default RaspberryPi
195                return new RaspiSystemInfoProvider();
196            }
197        }
198    }
199}