Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion core/src/main/java/edu/wpi/grip/core/GRIPCoreModule.java
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,6 @@ public <I> void hear(TypeLiteral<I> type, TypeEncounter<I> encounter) {

bind(ConnectionValidator.class).to(Pipeline.class);
bind(Source.SourceFactory.class).to(Source.SourceFactoryImpl.class);
bind(CameraSource.FrameGrabberFactory.class).to(CameraSource.FrameGrabberFactoryImpl.class);
install(new FactoryModuleBuilder()
.implement(CameraSource.class, CameraSource.class)
.build(CameraSource.Factory.class));
Expand Down
3 changes: 2 additions & 1 deletion core/src/main/java/edu/wpi/grip/core/Main.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import edu.wpi.grip.core.operations.Operations;
import edu.wpi.grip.core.operations.network.GRIPNetworkModule;
import edu.wpi.grip.core.serialization.Project;
import edu.wpi.grip.core.sources.GRIPSourcesHardwareModule;
import edu.wpi.grip.generated.CVOperations;

import javax.inject.Inject;
Expand All @@ -30,7 +31,7 @@ public class Main {

@SuppressWarnings("PMD.SystemPrintln")
public static void main(String[] args) throws IOException, InterruptedException {
final Injector injector = Guice.createInjector(new GRIPCoreModule(), new GRIPNetworkModule());
final Injector injector = Guice.createInjector(new GRIPCoreModule(), new GRIPNetworkModule(), new GRIPSourcesHardwareModule());
injector.getInstance(Main.class).start(args);
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package edu.wpi.grip.core.sources;

import com.google.inject.AbstractModule;

/**
* Adds bindings for hardware that is required by {@link edu.wpi.grip.core.Source Sources}
*/
public class GRIPSourcesHardwareModule extends AbstractModule {
@Override
protected void configure() {
bind(CameraSource.FrameGrabberFactory.class).to(CameraSource.FrameGrabberFactoryImpl.class);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ public void tearDown() {
}

@Test
public void testFoo() throws Exception {
public void testCompatibilityIsMaintained() throws Exception {
assertEquals("The expected number of steps were not found", 50, pipeline.getSteps().size());
assertEquals("The expected number of sources were not found", 2, pipeline.getSources().size());
pipeline.clear();
Expand Down
19 changes: 2 additions & 17 deletions core/src/test/java/edu/wpi/grip/core/sources/MockCameraSource.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,34 +2,19 @@

import com.google.common.eventbus.EventBus;
import edu.wpi.grip.core.util.MockExceptionWitness;
import org.bytedeco.javacv.FrameGrabber;

import java.io.IOException;
import java.net.MalformedURLException;

public class MockCameraSource extends CameraSource {

private boolean started = false;

static class FrameGrabberFactory implements CameraSource.FrameGrabberFactory {

@Override
public FrameGrabber create(int deviceNumber) {
return null;
}

@Override
public FrameGrabber create(String addressProperty) throws MalformedURLException {
return null;
}
}

public MockCameraSource(EventBus eventBus, String address) throws IOException {
super(eventBus, new FrameGrabberFactory(), MockExceptionWitness.MOCK_FACTORY, address);
super(eventBus, new MockFrameGrabberFactory(), MockExceptionWitness.MOCK_FACTORY, address);
}

public MockCameraSource(EventBus eventBus, int deviceNumber) throws IOException {
super(eventBus, new FrameGrabberFactory(), MockExceptionWitness.MOCK_FACTORY, deviceNumber);
super(eventBus, new MockFrameGrabberFactory(), MockExceptionWitness.MOCK_FACTORY, deviceNumber);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package edu.wpi.grip.core.sources;

import org.bytedeco.javacv.FrameGrabber;

import java.net.MalformedURLException;

/**
* Frame Grabber Factory that mocks out the frame grabber that it returns
*/
public class MockFrameGrabberFactory implements CameraSource.FrameGrabberFactory {

@Override
public FrameGrabber create(int deviceNumber) {
return new SimpleMockFrameGrabber();
}

@Override
public FrameGrabber create(String addressProperty) throws MalformedURLException {
return new SimpleMockFrameGrabber();
}
}
3 changes: 3 additions & 0 deletions core/src/test/java/edu/wpi/grip/util/GRIPCoreTestModule.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@

import com.google.common.eventbus.SubscriberExceptionContext;
import edu.wpi.grip.core.GRIPCoreModule;
import edu.wpi.grip.core.sources.CameraSource;
import edu.wpi.grip.core.sources.MockFrameGrabberFactory;

import java.util.ArrayList;
import java.util.List;
Expand Down Expand Up @@ -68,6 +70,7 @@ public void tearDown() {
@Override
protected void configure() {
assert setUp : "The GRIPCoreTestModule handler was not set up. Call 'setUp' before passing the injector";
bind(CameraSource.FrameGrabberFactory.class).to(MockFrameGrabberFactory.class);
super.configure();
}

Expand Down
3 changes: 2 additions & 1 deletion ui/src/main/java/edu/wpi/grip/ui/Main.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
import edu.wpi.grip.core.operations.Operations;
import edu.wpi.grip.core.operations.network.GRIPNetworkModule;
import edu.wpi.grip.core.serialization.Project;
import edu.wpi.grip.core.sources.GRIPSourcesHardwareModule;
import edu.wpi.grip.core.util.SafeShutdown;
import edu.wpi.grip.generated.CVOperations;
import edu.wpi.grip.ui.util.DPIUtility;
Expand Down Expand Up @@ -67,7 +68,7 @@ public void start(Stage stage) throws Exception {
parameters.remove("--headless");
} else {
// Otherwise, run with both the core and UI modules, and show the JavaFX stage
injector = Guice.createInjector(Modules.override(new GRIPCoreModule(), new GRIPNetworkModule()).with(new GRIPUIModule()));
injector = Guice.createInjector(Modules.override(new GRIPCoreModule(), new GRIPNetworkModule(), new GRIPSourcesHardwareModule()).with(new GRIPUIModule()));
injector.injectMembers(this);

root = FXMLLoader.load(Main.class.getResource("MainWindow.fxml"), null, null, injector::getInstance);
Expand Down