Files
PhotonVision/photon-server/src/test/java/org/photonvision/hardware/HardwareManagerTest.java

49 lines
1.7 KiB
Java
Raw Normal View History

Hardware Management, Metrics, PWM/GPIO support. (#12) * [Server] Hardware Management * [Server] Hardware Management * [Server] Hardware Management * [Server] Hardware Management * [Server] Hardware Management * [Server] Hardware Management * Added metricsPublisher * [Server] Hardware Management * [Server] Hardware Management * Fill in HardwareConfig, allow JSON Comments * Use hardware config * [Hardware Management] Use Hardware Config * [Hardware Management] Use softPWM for dimming * [Hardware] Added HardwareConfig Test * [Hardware] Started HardwareManager * Start metrics thread in hardwareManager * [Hardware] Added Hardware Manager Test * [Hardware] Spotless * [Hardware] Added logging, cleaned up HardwareConfig * [Hardware] Added logging to PWM class * [Hardware] Rebase off master, fix merge conflicts * [Hardware] Ignore metrics commands if on pi * [Hardware] Remove GPIO provision after shutdown * [Hardware] Switch over to diozero * [Hardware] Use broadcom pins * [Hardware] Fix PWM port * [Hardware] Use jpi instead of pigpio * [Hardware] Use dizero-core * [Hardware] No need to close LED * [Hardware] Switch to jpigpio * [Hardware] Initalize JPiGPIO in unit tests * [Hardware] Use dutyCycle for LED dimming * [Hardware] Add blink test to HardwareManager * [Hardware] Fix PWM port * [Hardware] Fix HardwareManagerTest * [Hardware] Fix HardwareManagerTest * [Hardware] Use waves for LED blinking * [Hardware] Make blinking part of PWM * [Hardware] Add API methods to hardware Manager * [Hardware] Only start pigpio if on pi * [Hardware] Merge PWM classes into GPIO * [Hardware] Add Hardware stuff to VisionModules * [Hardware] Remove random semicolon Co-authored-by: Banks Troutman <btrout.dhrs@gmail.com>
2020-07-31 15:43:58 -04:00
/*
* Copyright (C) 2020 Photon Vision.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU 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 Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
package org.photonvision.hardware;
import com.fasterxml.jackson.databind.ObjectMapper;
import java.io.IOException;
import java.util.List;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;
import org.photonvision.common.configuration.HardwareConfig;
import org.photonvision.common.hardware.HardwareManager;
import org.photonvision.common.util.TestUtils;
public class HardwareManagerTest {
@Test
public void managementTest() throws IOException {
Hardware Management, Metrics, PWM/GPIO support. (#12) * [Server] Hardware Management * [Server] Hardware Management * [Server] Hardware Management * [Server] Hardware Management * [Server] Hardware Management * [Server] Hardware Management * Added metricsPublisher * [Server] Hardware Management * [Server] Hardware Management * Fill in HardwareConfig, allow JSON Comments * Use hardware config * [Hardware Management] Use Hardware Config * [Hardware Management] Use softPWM for dimming * [Hardware] Added HardwareConfig Test * [Hardware] Started HardwareManager * Start metrics thread in hardwareManager * [Hardware] Added Hardware Manager Test * [Hardware] Spotless * [Hardware] Added logging, cleaned up HardwareConfig * [Hardware] Added logging to PWM class * [Hardware] Rebase off master, fix merge conflicts * [Hardware] Ignore metrics commands if on pi * [Hardware] Remove GPIO provision after shutdown * [Hardware] Switch over to diozero * [Hardware] Use broadcom pins * [Hardware] Fix PWM port * [Hardware] Use jpi instead of pigpio * [Hardware] Use dizero-core * [Hardware] No need to close LED * [Hardware] Switch to jpigpio * [Hardware] Initalize JPiGPIO in unit tests * [Hardware] Use dutyCycle for LED dimming * [Hardware] Add blink test to HardwareManager * [Hardware] Fix PWM port * [Hardware] Fix HardwareManagerTest * [Hardware] Fix HardwareManagerTest * [Hardware] Use waves for LED blinking * [Hardware] Make blinking part of PWM * [Hardware] Add API methods to hardware Manager * [Hardware] Only start pigpio if on pi * [Hardware] Merge PWM classes into GPIO * [Hardware] Add Hardware stuff to VisionModules * [Hardware] Remove random semicolon Co-authored-by: Banks Troutman <btrout.dhrs@gmail.com>
2020-07-31 15:43:58 -04:00
var config =
new ObjectMapper().readValue(TestUtils.getHardwareConfigJson(), HardwareConfig.class);
HardwareManager.getInstance().setConfig(config);
var instance = HardwareManager.getInstance();
instance.getGPIO(13).setPwmRange(List.of(0, 100));
Assertions.assertEquals(instance.getGPIO(13).getPwmRange().get(0), 0);
Assertions.assertEquals(instance.getGPIO(13).getPwmRange().get(1), 100);
instance.getGPIO(13).blink(250, 5);
for (int i = 0; i < 101; i++) {
instance.getGPIO(13).dimLED(i);
}
}
}