示例#1
0
 public Outputs Create(Inputs inputs) 
 {
     EventLoop<Fuel> eStart = new EventLoop<Fuel>();
     Fill fi = new Fill(
                       inputs.EClearSale.Map(u => Unit.UNIT),
                       inputs.EFuelPulses, inputs.Calibration,
                       inputs.Price1, inputs.Price2, inputs.Price3,
                       eStart);
     NotifyPointOfSale np = new NotifyPointOfSale(
             new LifeCycle(inputs.ENozzle1,
                           inputs.ENozzle2,
                           inputs.ENozzle3),
             inputs.EClearSale,
             fi);
     eStart.Loop(np.EStart);
     return new Outputs()
         .SetDelivery(np.FuelFlowing.Map(
             of =>
                 of.Equals(Optional<Fuel>.Of(Fuel.ONE))   ? Delivery.FAST1 :
                 of.Equals(Optional<Fuel>.Of(Fuel.TWO))   ? Delivery.FAST2 :
                 of.Equals(Optional<Fuel>.Of(Fuel.THREE)) ? Delivery.FAST3 : 
                                                      Delivery.OFF))
         .SetSaleCostLcd(fi.DollarsDelivered.Map(
                 q => Formatters.FormatSaleCost(q)))
         .SetSaleQuantityLcd(fi.LitersDelivered.Map(
                 q => Formatters.FormatSaleQuantity(q)))
         .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.EBeep)
         .SetSaleComplete(np.ESaleComplete);
 }
 public Outputs Create(Inputs inputs) {
     LifeCycle lc = new LifeCycle(inputs.ENozzle1,
                                  inputs.ENozzle2,
                                  inputs.ENozzle3);
     Fill fi = new Fill(lc.EStart.Map(u => Unit.UNIT),
                        inputs.EFuelPulses, inputs.Calibration,
                        inputs.Price1, inputs.Price2, inputs.Price3,
                        lc.EStart);
     return new Outputs()
         .SetDelivery(lc.FillActive.Map(
             of =>
                 of.Equals(Optional<Fuel>.Of(Fuel.ONE))   ? Delivery.FAST1 :
                 of.Equals(Optional<Fuel>.Of(Fuel.TWO)) ? Delivery.FAST2 :
                 of.Equals(Optional<Fuel>.Of(Fuel.THREE)) ? Delivery.FAST3 : 
                                                      Delivery.OFF))
         .SetSaleCostLcd(fi.DollarsDelivered.Map(
             q => Formatters.FormatSaleCost(q)))
         .SetSaleQuantityLcd(fi.LitersDelivered.Map(
             q => Formatters.FormatSaleQuantity(q)))
         .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 Outputs Create(Inputs inputs) 
 {
     EventLoop<Fuel> eStart = new EventLoop<Fuel>();
     Fill fi = new Fill(inputs.EClearSale.Map(u => Unit.UNIT),
                        inputs.EFuelPulses, inputs.Calibration,
                        inputs.Price1, inputs.Price2, inputs.Price3,
                        eStart);
     NotifyPointOfSale np = new NotifyPointOfSale(
             new LifeCycle(inputs.ENozzle1,
                           inputs.ENozzle2,
                           inputs.ENozzle3),
             inputs.EClearSale,
             fi);
     eStart.Loop(np.EStart);
     BehaviorLoop<bool> keypadActive = new BehaviorLoop<bool>();
     Keypad ke = new Keypad(inputs.EKeypad,
                            inputs.EClearSale,
                            keypadActive);
     Preset pr = new Preset(ke.Value,
                            fi,
                            np.FuelFlowing,
                            np.FillActive.Map(o => o.IsPresent));
     keypadActive.Loop(pr.KeypadActive);
     return new Outputs()
         .SetDelivery(pr.Delivery)
         .SetSaleCostLcd(fi.DollarsDelivered.Map(q => Formatters.FormatSaleCost(q)))
         .SetSaleQuantityLcd(fi.LitersDelivered.Map(q => Formatters.FormatSaleQuantity(q)))
         .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.ESaleComplete)
         .SetPresetLcd(ke.Value.Map(v => Formatters.FormatSaleCost((double)v)))
         .SetBeep(np.EBeep.Merge(ke.EBeep));
 }
示例#4
0
 public Preset(
   Behavior<int> presetDollars,
   Fill fi,
   Behavior<Optional<Fuel>> fuelFlowing,
   Behavior<Boolean> fillActive)
 {
   Behavior<Speed> speed = Behavior<Speed>.Lift(
     (presetDollars_, price, dollarsDelivered, litersDelivered) =>
     {
       if (presetDollars_ == 0)
         return Speed.FAST;
       else
       {
         if (dollarsDelivered >= (double)presetDollars_)
           return Speed.STOPPED;
         double slowLiters =
           (double)presetDollars_ / price - 0.10;
         if (litersDelivered >= slowLiters)
           return Speed.SLOW;
         else
           return Speed.FAST;
       }
     },
     presetDollars,
     fi.Price,
     fi.DollarsDelivered,
     fi.LitersDelivered);
   Delivery = Behavior<Delivery>.Lift(
     (of, speed_) =>
       speed_ == Speed.FAST
         ? (
           of.Equals(Optional<Fuel>.Of(Fuel.ONE))
             ? Pump.Delivery.FAST1
             : of.Equals(Optional<Fuel>.Of(Fuel.TWO))
               ? Pump.Delivery.FAST2
               : of.Equals(Optional<Fuel>.Of(Fuel.THREE))
                 ? Pump.Delivery.FAST3
                 : Pump.Delivery.OFF
           )
         : speed_ == Speed.SLOW
           ? (
             of.Equals(Optional<Fuel>.Of(Fuel.ONE))
               ? Pump.Delivery.SLOW1
               : of.Equals(Optional<Fuel>.Of(Fuel.TWO))
                 ? Pump.Delivery.SLOW2
                 : of.Equals(Optional<Fuel>.Of(Fuel.THREE))
                   ? Pump.Delivery.SLOW3
                   : Pump.Delivery.OFF
             )
           : Pump.Delivery.OFF,
     fuelFlowing,
     speed);
   KeypadActive = Behavior<bool>.Lift(
     (of, speed_) =>
       !of.IsPresent || speed_ == Speed.FAST,
     fuelFlowing,
     speed);
 }
 public NotifyPointOfSale(
   LifeCycle lc,
   Event<Unit> eClearSale,
   Fill fi)
 {
   Behavior<Boolean> locked = lc.EStart.Map(u => true).Merge(eClearSale.Map(u => false)).Hold(false);
   EStart = lc.EStart.Gate(locked.Map(l => !l));
   EEnd = lc.EEnd.Gate(locked);
   FuelFlowing = EStart.Map(f => Optional<Fuel>.Of(f))
     .Merge(EEnd.Map(f => Optional<Fuel>.Empty())).Hold(Optional<Fuel>.Empty());
   FillActive = EStart.Map(f => Optional<Fuel>.Of(f))
     .Merge(eClearSale.Map(f => Optional<Fuel>.Empty())).Hold(Optional<Fuel>.Empty());
   EBeep = eClearSale;
   ESaleComplete = Event<Sale>.FilterOptional(
     EEnd.Snapshot(
       Behavior<Sale>.Lift(
         (oFuel, price_, dollars, liters) => oFuel.IsPresent ? Optional<Sale>.Of(new Sale(oFuel.Get(), price_, dollars, liters)) : Optional<Sale>.Empty(),
         FuelFlowing,
         fi.Price,
         fi.DollarsDelivered,
         fi.LitersDelivered)));
 }