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:  https://www.pi4j.com/
012 * **********************************************************************
013 * %%
014 * Copyright (C) 2012 - 2019 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.*;
033import com.pi4j.io.i2c.I2CFactoryProvider;
034import com.pi4j.io.i2c.impl.I2CProviderImpl;
035import com.pi4j.system.SystemInfoProvider;
036import com.pi4j.system.impl.*;
037
038/**
039 * <p>
040 * This enumeration defines the platforms supported by Pi4J.
041 * </p>
042 *
043 * @see <a href="https://www.pi4j.com/">https://www.pi4j.com/</a>
044 * @author Robert Savage (<a
045 *         href="http://www.savagehomeautomation.com">http://www.savagehomeautomation.com</a>)
046 */
047public enum Platform {
048    // SUPPORTED PLATFORMS
049    RASPBERRYPI("raspberrypi", "Raspberry Pi"),
050    BANANAPI("bananapi", "BananaPi"),
051    BANANAPRO("bananapro", "BananaPro"),
052    BPI("bpi", "Synovoip BPI"),
053    ODROID("odroid", "Odroid"),
054    ORANGEPI("orangepi", "OrangePi"),
055    NANOPI("nanopi", "NanoPi"),
056    SIMULATED("simulated", "Simulated");
057
058    // private variables
059    protected String platformId = null;
060    protected String label = null;
061
062    /**
063     * Private default constructor
064     * @param platformId
065     * @param label
066     */
067    private Platform(String platformId, String label) {
068        this.platformId = platformId;
069        this.label = label;
070    }
071
072    /**
073     * Get the platform's friendly string name/label.
074     * @return label of platform
075     */
076    public String getLabel() {
077        return this.label;
078    }
079
080    /**
081     * Get the platform's friendly string name/label.
082     * @return label of platform
083     */
084    public String label() {
085        return getLabel();
086    }
087
088    /**
089     * Get the platform's unique identifier string.
090     * @return platform id string
091     */
092    public String getId() {
093        return platformId;
094    }
095
096    /**
097     * Get the platform's unique identifier string.
098     * @return platform id string
099     */
100    public String id() {
101        return getId();
102    }
103
104    /**
105     * Lookup a platform enumeration by the platform's unique identifier string.
106     * @return platform enumeration
107     */
108    public static Platform fromId(String platformId) {
109        for(Platform platform : Platform.values()) {
110            if(platform.id().equalsIgnoreCase(platformId))
111                return platform;
112        }
113        return null;
114    }
115
116
117    public GpioProvider getGpioProvider() {
118        return getGpioProvider(this);
119    }
120
121    public static GpioProvider getGpioProvider(Platform platform) {
122        // create the provider based on the PlatformManager's selected platform
123        switch (PlatformManager.getPlatform()) {
124            case RASPBERRYPI: {
125                return new RaspiGpioProvider();
126            }
127            case BANANAPI: {
128                return new BananaPiGpioProvider();
129            }
130            case BANANAPRO: {
131                return new BananaProGpioProvider();
132            }
133            case BPI: {
134                return new BpiGpioProvider();
135            }
136            case ODROID: {
137                return new OdroidGpioProvider();
138            }
139            case ORANGEPI: {
140                return new OrangePiGpioProvider();
141            }
142            case NANOPI: {
143                return new NanoPiGpioProvider();
144            }
145            case SIMULATED: {
146                return new SimulatedGpioProvider();
147            }
148            default: {
149                // if a platform cannot be determine, then assume it's the default RaspberryPi
150                return new RaspiGpioProvider();
151            }
152        }
153    }
154
155    public I2CFactoryProvider getI2CFactoryProvider() {
156        return getI2CFactoryProvider(this);
157    }
158
159    public static I2CFactoryProvider getI2CFactoryProvider(Platform platform) {
160        return new I2CProviderImpl();
161    }
162
163    public SystemInfoProvider getSystemInfoProvider() {
164        return getSystemInfoProvider(this);
165    }
166
167    public static SystemInfoProvider getSystemInfoProvider(Platform platform) {
168        // return the system info provider based on the provided platform
169        switch(platform) {
170            case RASPBERRYPI: {
171                return new RaspiSystemInfoProvider();
172            }
173            case BANANAPI: {
174                return new BananaPiSystemInfoProvider();
175            }
176            case BANANAPRO: {
177                return new BananaProSystemInfoProvider();
178            }
179            case BPI: {
180                return new BpiSystemInfoProvider();
181            }
182            case ODROID: {
183                return new OdroidSystemInfoProvider();
184            }
185            case ORANGEPI: {
186                return new OrangePiSystemInfoProvider();
187            }
188            case NANOPI: {
189                return new NanoPiSystemInfoProvider();
190            }
191            default: {
192                // if a platform cannot be determine, then assume it's the default RaspberryPi
193                return new RaspiSystemInfoProvider();
194            }
195        }
196    }
197}