public Outputs Create(Inputs inputs) { StreamLoop<Fuel> sStart = new StreamLoop<Fuel>(); Fill fi = new Fill(inputs.SClearSale, inputs.SFuelPulses, inputs.Calibration, inputs.Price1, inputs.Price2, inputs.Price3, sStart); NotifyPointOfSale np = new NotifyPointOfSale( new LifeCycle(inputs.SNozzle1, inputs.SNozzle2, inputs.SNozzle3), inputs.SClearSale, fi); sStart.Loop(np.SStart); CellLoop<bool> keypadActive = new CellLoop<bool>(); Keypad ke = new Keypad(inputs.SKeypad, inputs.SClearSale, keypadActive); Preset pr = new Preset(ke.Value, fi, np.FuelFlowing); keypadActive.Loop(pr.KeypadActive); return new Outputs() .SetDelivery(pr.Delivery) .SetSaleCostLcd(fi.DollarsDelivered.Map(Formatters.FormatSaleCost)) .SetSaleQuantityLcd(fi.LitersDelivered.Map(Formatters.FormatSaleQuantity)) .SetPriceLcd1(ShowDollarsPump.PriceLcd(np.FillActive, fi.Price, Fuel.One, inputs)) .SetPriceLcd2(ShowDollarsPump.PriceLcd(np.FillActive, fi.Price, Fuel.Two, inputs)) .SetPriceLcd3(ShowDollarsPump.PriceLcd(np.FillActive, fi.Price, Fuel.Three, inputs)) .SetSaleComplete(np.SSaleComplete) .SetPresetLcd(ke.Value.Map(Formatters.FormatPresetAmount)) .SetBeep(np.SBeep.OrElse(ke.SBeep)); }
public Preset(Cell<int> presetDollars, Fill fi, Cell<IMaybe<Fuel>> fuelFlowing) { Cell<Speed> speed = presetDollars.Lift( fi.Price, fi.DollarsDelivered, fi.LitersDelivered, (presetDollarsLocal, price, dollarsDelivered, litersDelivered) => { if (presetDollarsLocal == 0) { return Speed.Fast; } if (dollarsDelivered >= presetDollarsLocal) { return Speed.Stopped; } double slowLiters = presetDollarsLocal / price - 0.10; return litersDelivered >= slowLiters ? Speed.Slow : Speed.Fast; }); this.Delivery = fuelFlowing.Lift(speed, (m, speedLocal) => speedLocal == Speed.Fast ? ( m.Equals(Maybe.Just(Fuel.One)) ? PetrolPump.Delivery.Fast1 : m.Equals(Maybe.Just(Fuel.Two)) ? PetrolPump.Delivery.Fast2 : m.Equals(Maybe.Just(Fuel.Three)) ? PetrolPump.Delivery.Fast3 : PetrolPump.Delivery.Off ) : speedLocal == Speed.Slow ? ( m.Equals(Maybe.Just(Fuel.One)) ? PetrolPump.Delivery.Slow1 : m.Equals(Maybe.Just(Fuel.Two)) ? PetrolPump.Delivery.Slow2 : m.Equals(Maybe.Just(Fuel.Three)) ? PetrolPump.Delivery.Slow3 : PetrolPump.Delivery.Off ) : PetrolPump.Delivery.Off); this.KeypadActive = fuelFlowing.Lift(speed, (m, speedLocal) => m.Match(_ => speedLocal == Speed.Fast, () => true)); }
public Outputs Create(Inputs inputs) { StreamLoop<Fuel> sStart = new StreamLoop<Fuel>(); Fill fi = new Fill( inputs.SClearSale, inputs.SFuelPulses, inputs.Calibration, inputs.Price1, inputs.Price2, inputs.Price3, sStart); NotifyPointOfSale np = new NotifyPointOfSale( new LifeCycle(inputs.SNozzle1, inputs.SNozzle2, inputs.SNozzle3), inputs.SClearSale, fi); sStart.Loop(np.SStart); return new Outputs() .SetDelivery(np.FuelFlowing.Map( m => m.Equals(Maybe.Just(Fuel.One)) ? Delivery.Fast1 : m.Equals(Maybe.Just(Fuel.Two)) ? Delivery.Fast2 : m.Equals(Maybe.Just(Fuel.Three)) ? Delivery.Fast3 : Delivery.Off)) .SetSaleCostLcd(fi.DollarsDelivered.Map(Formatters.FormatSaleCost)) .SetSaleQuantityLcd(fi.LitersDelivered.Map(Formatters.FormatSaleQuantity)) .SetPriceLcd1(ShowDollarsPump.PriceLcd(np.FillActive, fi.Price, Fuel.One, inputs)) .SetPriceLcd2(ShowDollarsPump.PriceLcd(np.FillActive, fi.Price, Fuel.Two, inputs)) .SetPriceLcd3(ShowDollarsPump.PriceLcd(np.FillActive, fi.Price, Fuel.Three, inputs)) .SetBeep(np.SBeep) .SetSaleComplete(np.SSaleComplete); }
public Outputs Create(Inputs inputs) { LifeCycle lc = new LifeCycle(inputs.SNozzle1, inputs.SNozzle2, inputs.SNozzle3); Fill fi = new Fill(lc.SStart.Map(_ => Unit.Value), inputs.SFuelPulses, inputs.Calibration, inputs.Price1, inputs.Price2, inputs.Price3, lc.SStart); return new Outputs() .SetDelivery(lc.FillActive.Map( m => m.Equals(Maybe.Just(Fuel.One)) ? Delivery.Fast1 : m.Equals(Maybe.Just(Fuel.Two)) ? Delivery.Fast2 : m.Equals(Maybe.Just(Fuel.Three)) ? Delivery.Fast3 : Delivery.Off)) .SetSaleCostLcd(fi.DollarsDelivered.Map(Formatters.FormatSaleCost)) .SetSaleQuantityLcd(fi.LitersDelivered.Map(Formatters.FormatSaleQuantity)) .SetPriceLcd1(PriceLcd(lc.FillActive, fi.Price, Fuel.One, inputs)) .SetPriceLcd2(PriceLcd(lc.FillActive, fi.Price, Fuel.Two, inputs)) .SetPriceLcd3(PriceLcd(lc.FillActive, fi.Price, Fuel.Three, inputs)); }
public NotifyPointOfSale( LifeCycle lc, Stream<Unit> sClearSale, Fill fi) { Cell<bool> locked = lc.SStart.Map(u => true).OrElse(sClearSale.Map(u => false)).Hold(false); this.SStart = lc.SStart.Gate(locked.Map(l => !l)); this.SEnd = lc.SEnd.Gate(locked); this.FuelFlowing = this.SStart.Map(Maybe.Just).OrElse( this.SEnd.Map(f => Maybe.Nothing<Fuel>())).Hold(Maybe.Nothing<Fuel>()); this.FillActive = this.SStart.Map(Maybe.Just).OrElse( sClearSale.Map(f => Maybe.Nothing<Fuel>())).Hold(Maybe.Nothing<Fuel>()); this.SBeep = sClearSale; this.SSaleComplete = this.SEnd.Snapshot( this.FuelFlowing.Lift( fi.Price, fi.DollarsDelivered, fi.LitersDelivered, (oFuel, price, dollars, liters) => oFuel.Match(v => Maybe.Just( new Sale(v, price, dollars, liters)), Maybe.Nothing<Sale>))).FilterMaybe(); }