/*
 * Copyright 2016, The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package fr.eyal.androidcatapult;

import android.os.Build;

import com.google.android.things.pio.PeripheralManagerService;

import java.util.List;

@SuppressWarnings("WeakerAccess")
public class BoardDefaults {
    private static final String DEVICE_EDISON_ARDUINO = "edison_arduino";
    private static final String DEVICE_EDISON = "edison";
    private static final String DEVICE_RPI3 = "rpi3";
    private static final String DEVICE_NXP = "imx6ul_pico";
    private static String sBoardVariant = "";

    /**
     * Return the preferred PWM port for each board.
     */
    public static String getButtonPort() {
        switch (getBoardVariant()) {
            case DEVICE_EDISON_ARDUINO:
                return "IO13";
//            case DEVICE_EDISON:
//                return "GP12";
//            case DEVICE_RPI3:
//                return "PWM0";
//            case DEVICE_NXP:
//                return "PWM7";
            default:
                throw new IllegalStateException("Unknown Build.DEVICE " + Build.DEVICE);
        }
    }

    /**
     * Return the preferred PWM port for each board.
     */
    public static String getServoPort() {
        switch (getBoardVariant()) {
            case DEVICE_EDISON_ARDUINO:
                return "IO6";
//            case DEVICE_EDISON:
//                return "GP12";
//            case DEVICE_RPI3:
//                return "PWM0";
            case DEVICE_NXP:
                return "PWM7";
            default:
                throw new IllegalStateException("Unknown Build.DEVICE " + Build.DEVICE);
        }
    }

    private static String getBoardVariant() {
        if (!sBoardVariant.isEmpty()) {
            return sBoardVariant;
        }
        sBoardVariant = Build.DEVICE;
        // For the edison check the pin prefix
        // to always return Edison Breakout pin name when applicable.
        if (sBoardVariant.equals(DEVICE_EDISON)) {
            PeripheralManagerService pioService = new PeripheralManagerService();
            List<String> gpioList = pioService.getGpioList();
            if (gpioList.size() != 0) {
                String pin = gpioList.get(0);
                if (pin.startsWith("IO")) {
                    sBoardVariant = DEVICE_EDISON_ARDUINO;
                }
            }
        }
        return sBoardVariant;
    }
}

@@ -1394,34 +1394,32 @@
  return %22GP12%22;%0A
-//
             case
@@ -1424,34 +1424,32 @@
 se DEVICE_RPI3:%0A
-//
                 
@@ -1456,20 +1456,21 @@
 return %22
-PWM0
+BCM17
 %22;%0A//   
@@ -1940,18 +1940,16 @@
 %22GP12%22;%0A
-//
         
@@ -1970,18 +1970,16 @@
 E_RPI3:%0A
-//
         
@@ -2001,16 +2001,18 @@
 %22PWM0%22;%0A
+//
         
@@ -2032,16 +2032,18 @@
 CE_NXP:%0A
+//
         

Make the app compatible with Raspberry PI