public FlowSensor(InterruptPort port, OutputPort light, IHttpMessageWriter httpMessageWriter, string tapId, PulseConfig pulseConfig) { _port = port; _light = light; _port.OnInterrupt += FlowDetected; _httpMessageWriter = httpMessageWriter; _tapId = tapId; _pulseConfig = pulseConfig; }
public IRouteComponent Find(Pulse pulse, float threshold, ushort samples) { if (source.attributes.length() > 4) { throw new IllegalRouteOperationException("Cannot find pulses for data longer than 4 bytes"); } if (source.attributes.length() <= 0) { throw new IllegalRouteOperationException("Cannot find pulses for null data"); } if (source.eventConfig[0] == (byte)SENSOR_FUSION) { throw new IllegalRouteOperationException("Cannot find pulses for sensor fusion data"); } var config = new PulseConfig(source.attributes.length(), (int)(threshold * source.scale(state.bridge)), samples, pulse); var next = source.transform(config, state.bridge.GetModule <IDataProcessor>() as DataProcessor); return(postCreate(next.Item2, new PulseEditorInner(config, next.Item1, state.bridge))); }
/// <summary> /// Main method runs on startup /// </summary> public static void RealMain() { Debug.EnableGCMessages(true); // START CONFIG var sf800pulseConfig = new PulseConfig() { PulsesPerOunce = PulseConfig.SF800_PULSES_PER_OUNCE, PourStoppedDelay = 250, PulsesPerStoppedExtension = 50, PulsesPerPouring = 250, }; var config = new Config { Connectivity = new ConnectivityConfig { //Wifi = new WifiConfig //{ // Enabled = true, // SSID = "Rightpoint", // Password = "******", // SecurityMode = Toolbox.NETMF.Hardware.WiFlyGSX.AuthMode.MixedWPA1_WPA2 //}, Ethernet = new EthernetConfig { Enabled = true }, BaseUrl = "http://pourcast.labs.rightpoint.com/api/Tap/", HttpLight = Pins.GPIO_PIN_D9 }, Taps = new[] { new TapConfig { Input = Pins.GPIO_PIN_D13, Light = Pins.GPIO_PIN_D11, TapId = "535c61a951aa0405287989ec", PulseConfig = sf800pulseConfig, }, new TapConfig { Input = Pins.GPIO_PIN_D12, Light = Pins.GPIO_PIN_D10, TapId = "537d28db51aa04289027cde5", PulseConfig = sf800pulseConfig, }, }, WatchdogCheckInterval = new TimeSpan(0, 15, 0) }; #if true // a configuration for testing with a local server, buttons, and even the emulator var localButtonConfig = new PulseConfig() { PulsesPerOunce = 0.1, PourStoppedDelay = 1000, PulsesPerStoppedExtension = 1, PulsesPerPouring = 5, }; config = new Config { Connectivity = new ConnectivityConfig { Wifi = new WifiConfig() { Enabled = true, SSID = "XXX", Password = "******", SecurityMode = Toolbox.NETMF.Hardware.WiFlyGSX.AuthMode.MixedWPA1_WPA2, }, BaseUrl = "http://192.168.25.107:23456/api/Tap/", #if true HttpLight = Pins.GPIO_PIN_D9, }, Taps = new[] { new TapConfig { Input = Pins.GPIO_PIN_D13, Light = Pins.GPIO_PIN_D11, TapId = "5396779faa6179467050c33a", PulseConfig = localButtonConfig, }, new TapConfig { Input = Pins.GPIO_PIN_D12, Light = Pins.GPIO_PIN_D10, TapId = "539677a4aa6179467050c33d", PulseConfig = localButtonConfig, }, #else HttpLight = Cpu.Pin.GPIO_Pin6, }, Taps = new[] { new TapConfig { Input = Cpu.Pin.GPIO_Pin2, // emulator up Light = Cpu.Pin.GPIO_Pin1, TapId = "539638b03885a838541b880c", PulseConfig = localButtonConfig, }, new TapConfig { Input = Cpu.Pin.GPIO_Pin4, // emulator down Light = Cpu.Pin.GPIO_Pin3, TapId = "539638bd3885a838541b8810", PulseConfig = localButtonConfig, }, #endif }, WatchdogCheckInterval = new TimeSpan(0, 15, 0) }; #endif // END CONFIG // turn on the tap lights on - they'll turn off as they initialize LightsOn(config.Taps); // turn the HTTP light *off*, it'll go on as it initializes LightOff(config.Connectivity.HttpLight); var sender = BuildMessageSender(config.Connectivity); sender.Initalize(); HttpMessageWriter writer = null; // first watchdog makes sure we send *something* every watchdogCheckInterval. Second reboots us 30s later if the message hasn't been sent yet (ie. if networking dies) // sending *any* message resets both watchdogs var heartbeatWatchdog = new Watchdog(config.WatchdogCheckInterval, () => writer.SendHeartbeatAsync()); var rebootWatchdog = new RebootWatchdog(config.WatchdogCheckInterval + new TimeSpan(0, 0, 30)); writer = new HttpMessageWriter(sender, config.Connectivity.BaseUrl, new OutputPort(config.Connectivity.HttpLight, true), new[] { heartbeatWatchdog, rebootWatchdog }); var sensors = new FlowSensor[config.Taps.Length]; for (var i = 0; i < config.Taps.Length; i++) { var tapConfig = config.Taps[i]; sensors[i] = new FlowSensor( new InterruptPort(tapConfig.Input, false, Port.ResistorMode.Disabled, Port.InterruptMode.InterruptEdgeHigh), new OutputPort(tapConfig.Light, false), writer, tapConfig.TapId, tapConfig.PulseConfig); } heartbeatWatchdog.Start(); rebootWatchdog.Start(); Debug.Print("Starting"); while (true) { Thread.Sleep(Timeout.Infinite); } }