Search in sources :

Example 1 with FogRuntime

use of com.ociweb.iot.maker.FogRuntime in project FogLight-Examples by oci-pronghorn.

the class AppTest method testApp.

@Test
public void testApp() {
    FogRuntime runtime = FogRuntime.test(new IoTApp(false));
    TestHardware hardware = (TestHardware) runtime.getHardware();
    TestI2CBacking backing = (TestI2CBacking) hardware.getI2CBacking();
    ScriptedNonThreadScheduler scheduler = (ScriptedNonThreadScheduler) runtime.getScheduler();
    scheduler.startup();
    hardware.clearI2CWriteCount();
    hardware.write(IoTApp.ANGLE_SENSOR_PORT, 512);
    hardware.write(IoTApp.LIGHT_SENSOR_PORT, 300);
// scheduler.run();
// 
// int i = hardware.getI2CWriteCount();
// while (i>0) {
// 
// hardware.outputLastI2CWrite(System.out,i--);
// 
// }
// need ring of commands so it can be checked.
// assertEquals(Grove_LCD_RGB.RGB_ADDRESS, backing.lastWriteAddress);
// TODO: must ask I2C LCD for its brightness.
// test application here
}
Also used : ScriptedNonThreadScheduler(com.ociweb.pronghorn.stage.scheduling.ScriptedNonThreadScheduler) TestI2CBacking(com.ociweb.iot.hardware.impl.test.TestI2CBacking) TestHardware(com.ociweb.iot.hardware.impl.test.TestHardware) FogRuntime(com.ociweb.iot.maker.FogRuntime) Test(org.junit.Test)

Example 2 with FogRuntime

use of com.ociweb.iot.maker.FogRuntime in project FogLight-Examples by oci-pronghorn.

the class AppTest method testApp.

// no longer supported use of Paho.
@Ignore
public void testApp() {
    FogRuntime runtime = FogRuntime.test(new IoTApp());
    ScriptedNonThreadScheduler scheduler = (ScriptedNonThreadScheduler) runtime.getScheduler();
    scheduler.startup();
    TestHardware hardware = (TestHardware) runtime.getHardware();
    int iterations = 10;
    while (--iterations >= 0) {
        scheduler.run();
    // test application here
    }
}
Also used : ScriptedNonThreadScheduler(com.ociweb.pronghorn.stage.scheduling.ScriptedNonThreadScheduler) TestHardware(com.ociweb.iot.hardware.impl.test.TestHardware) FogRuntime(com.ociweb.iot.maker.FogRuntime) Ignore(org.junit.Ignore)

Example 3 with FogRuntime

use of com.ociweb.iot.maker.FogRuntime in project FogLight-Examples by oci-pronghorn.

the class AppTest method testApp.

@Test
public void testApp() {
    FogRuntime runtime = FogRuntime.test(new IoTApp());
    ScriptedNonThreadScheduler scheduler = (ScriptedNonThreadScheduler) runtime.getScheduler();
    scheduler.startup();
    TestHardware hardware = (TestHardware) runtime.getHardware();
    int iterations = 10;
    while (--iterations >= 0) {
        scheduler.run();
    // test application here
    }
}
Also used : ScriptedNonThreadScheduler(com.ociweb.pronghorn.stage.scheduling.ScriptedNonThreadScheduler) TestHardware(com.ociweb.iot.hardware.impl.test.TestHardware) FogRuntime(com.ociweb.iot.maker.FogRuntime) Test(org.junit.Test)

Example 4 with FogRuntime

use of com.ociweb.iot.maker.FogRuntime in project FogLight-Examples by oci-pronghorn.

the class AppTest method testApp.

@Test
public void testApp() {
    FogRuntime runtime = FogRuntime.test(new IoTApp());
    ScriptedNonThreadScheduler scheduler = (ScriptedNonThreadScheduler) runtime.getScheduler();
    scheduler.startup();
    TestHardware hardware = (TestHardware) runtime.getHardware();
    int iterations = 10;
    while (--iterations >= 0) {
        scheduler.run();
    // test application here
    }
}
Also used : ScriptedNonThreadScheduler(com.ociweb.pronghorn.stage.scheduling.ScriptedNonThreadScheduler) TestHardware(com.ociweb.iot.hardware.impl.test.TestHardware) FogRuntime(com.ociweb.iot.maker.FogRuntime) Test(org.junit.Test)

Example 5 with FogRuntime

use of com.ociweb.iot.maker.FogRuntime in project FogLight-Examples by oci-pronghorn.

the class IoTApp method configureWebBasedColorChange.

private void configureWebBasedColorChange(FogRuntime runtime) {
    final FogCommandChannel channel = runtime.newCommandChannel(FogRuntime.PIN_WRITER | FogRuntime.I2C_WRITER | GreenCommandChannel.DYNAMIC_MESSAGING | GreenCommandChannel.NET_RESPONDER);
    runtime.addRestListener((reader) -> {
        if (reader.structured().isEqual(COLOR, RED)) {
            return channel.publishHTTPResponse(reader, turnOnRed(channel) ? 200 : 500);
        } else if (reader.structured().isEqual(COLOR, GREEN)) {
            return channel.publishHTTPResponse(reader, turnOnGreen(channel) ? 200 : 500);
        } else if (reader.structured().isEqual(COLOR, YELLOW)) {
            return channel.publishHTTPResponse(reader, turnOnYellow(channel) ? 200 : 500);
        } else {
            return channel.publishHTTPResponse(reader, 404);
        }
    }).includeRoutes(webRoute);
}
Also used : Hardware(com.ociweb.iot.maker.Hardware) Port(com.ociweb.iot.maker.Port) GreenCommandChannel(com.ociweb.gl.api.GreenCommandChannel) LED(com.ociweb.iot.grove.simple_digital.SimpleDigitalTwig.LED) FogRuntime(com.ociweb.iot.maker.FogRuntime) NetGraphBuilder(com.ociweb.pronghorn.network.NetGraphBuilder) FogApp(com.ociweb.iot.maker.FogApp) D5(com.ociweb.iot.maker.Port.D5) D6(com.ociweb.iot.maker.Port.D6) FogCommandChannel(com.ociweb.iot.maker.FogCommandChannel) D3(com.ociweb.iot.maker.Port.D3) Grove_LCD_RGB(com.ociweb.iot.grove.lcd_rgb.Grove_LCD_RGB) FogCommandChannel(com.ociweb.iot.maker.FogCommandChannel)

Aggregations

FogRuntime (com.ociweb.iot.maker.FogRuntime)14 TestHardware (com.ociweb.iot.hardware.impl.test.TestHardware)12 ScriptedNonThreadScheduler (com.ociweb.pronghorn.stage.scheduling.ScriptedNonThreadScheduler)11 Test (org.junit.Test)9 Ignore (org.junit.Ignore)3 GreenCommandChannel (com.ociweb.gl.api.GreenCommandChannel)2 Grove_LCD_RGB (com.ociweb.iot.grove.lcd_rgb.Grove_LCD_RGB)2 LED (com.ociweb.iot.grove.simple_digital.SimpleDigitalTwig.LED)2 BasicTestPortReader (com.ociweb.iot.hardware.impl.test.BasicTestPortReader)2 FogApp (com.ociweb.iot.maker.FogApp)2 FogCommandChannel (com.ociweb.iot.maker.FogCommandChannel)2 Hardware (com.ociweb.iot.maker.Hardware)2 Port (com.ociweb.iot.maker.Port)2 D3 (com.ociweb.iot.maker.Port.D3)2 D5 (com.ociweb.iot.maker.Port.D5)2 D6 (com.ociweb.iot.maker.Port.D6)2 NetGraphBuilder (com.ociweb.pronghorn.network.NetGraphBuilder)2 TestI2CBacking (com.ociweb.iot.hardware.impl.test.TestI2CBacking)1