001/*
002 * Copyright (C) Photon Vision.
003 *
004 * This program is free software: you can redistribute it and/or modify
005 * it under the terms of the GNU General Public License as published by
006 * the Free Software Foundation, either version 3 of the License, or
007 * (at your option) any later version.
008 *
009 * This program is distributed in the hope that it will be useful,
010 * but WITHOUT ANY WARRANTY; without even the implied warranty of
011 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
012 * GNU General Public License for more details.
013 *
014 * You should have received a copy of the GNU General Public License
015 * along with this program.  If not, see <https://www.gnu.org/licenses/>.
016 */
017
018package org.photonvision.common.hardware;
019
020import java.util.List;
021import org.photonvision.common.hardware.GPIO.CustomGPIO;
022import org.photonvision.common.hardware.GPIO.GPIOBase;
023import org.photonvision.common.hardware.GPIO.pi.PigpioPin;
024
025public class StatusLED {
026    public final GPIOBase redLED;
027    public final GPIOBase greenLED;
028    public final GPIOBase blueLED;
029
030    public StatusLED(List<Integer> statusLedPins) {
031        // fill unassigned pins with -1 to disable
032        if (statusLedPins.size() != 3) {
033            for (int i = 0; i < 3 - statusLedPins.size(); i++) {
034                statusLedPins.add(-1);
035            }
036        }
037
038        if (Platform.isRaspberryPi()) {
039            redLED = new PigpioPin(statusLedPins.get(0));
040            greenLED = new PigpioPin(statusLedPins.get(1));
041            blueLED = new PigpioPin(statusLedPins.get(2));
042        } else {
043            redLED = new CustomGPIO(statusLedPins.get(0));
044            greenLED = new CustomGPIO(statusLedPins.get(1));
045            blueLED = new CustomGPIO(statusLedPins.get(2));
046        }
047    }
048
049    public void setRGB(boolean r, boolean g, boolean b) {
050        // Outputs are active-low, so invert the level applied
051        redLED.setState(!r);
052        redLED.setBrightness(r ? 0 : 100);
053        greenLED.setState(!g);
054        greenLED.setBrightness(g ? 0 : 100);
055        blueLED.setState(!b);
056        blueLED.setBrightness(b ? 0 : 100);
057    }
058}