package Ġsh re ck ye . iot smart car . device Ċ Ċ import Ġcom . pi 4 j . io . gpio . Gpio Factory Ċ import Ġcom . pi 4 j . io . gpio . R as pi Pin Ċ import Ġsh re ck ye . iot smart car . codec . proto . I ot Smart Car Proto . Wheel s Control Ċ import Ġsh re ck ye . iot smart car . data . GO _ BACK Ċ import Ġsh re ck ye . iot smart car . data . GO _ FORWARD Ċ import Ġsh re ck ye . iot smart car . data . T URN _ LEFT Ċ import Ġsh re ck ye . iot smart car . data . T URN _ RIGHT Ċ Ċ class ĠW heel s Ġ: ĠOutput Device < Wheel s Control >, ĠClose able Device Ġ{ ĊĠĠĠ Ġoverride Ġval Ġtype : ĠString Ġ= Ġ" wheel s " ĊĠĠĠ Ġval Ġgpio Controller Ġ= ĠG pio Factory . getInstance () ĊĠĠĠ Ġoverride Ġfun Ġclose () Ġ{ ĊĠĠĠĠĠĠĠ Ġgpio Controller . shutdown () ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġcompanion Ġobject Ġ{ ĊĠĠĠĠĠĠĠ Ġprivate Ġval Ġleft Wheel s Forward Pin Ġ= ĠR as pi Pin . GPIO _ 2 6 ĊĠĠĠĠĠĠĠ Ġprivate Ġval Ġleft Wheel s Backward Pin Ġ= ĠR as pi Pin . GPIO _ 2 4 ĊĠĠĠĠĠĠĠ Ġprivate Ġval Ġright Wheel s Forward Pin Ġ= ĠR as pi Pin . GPIO _ 0 1 ĊĠĠĠĠĠĠĠ Ġprivate Ġval Ġright Wheel s Backward Pin Ġ= ĠR as pi Pin . GPIO _ 2 3 ĊĊĠĠĠĠĠĠĠ Ġ// val ĠPWM _ MAX Ġ= Ġ 1 0 2 4 ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġval Ġleft Wheel s Forward Ġ= Ġgpio Controller . provision Digital Output Pin ( left Wheel s Forward Pin ) ĊĠĠĠ Ġval Ġleft Wheel s Backward Ġ= Ġgpio Controller . provision Digital Output Pin ( left Wheel s Backward Pin ) ĊĠĠĠ Ġval Ġright Wheel s Forward Ġ= Ġgpio Controller . provision Digital Output Pin ( right Wheel s Forward Pin ) ĊĠĠĠ Ġval Ġright Wheel s Backward Ġ= Ġgpio Controller . provision Digital Output Pin ( right Wheel s Backward Pin ) ĊĠĠĠ Ġval Ġall Wheel P ins Ġ= ĠarrayOf ( left Wheel s Forward , Ġleft Wheel s Backward , Ġright Wheel s Forward , Ġright Wheel s Backward ) ĊĠĠĠ Ġ/* val Ġleft Wheel s Ġ= ĠarrayOf ( lf Wheel , Ġlb Wheel ) ĊĠĠĠ Ġval Ġright Wheel s Ġ= ĠarrayOf ( rf Wheel , Ġrb Wheel ) ĊĠĠĠ Ġval Ġall Wheel s Ġ= Ġleft Wheel s Ġ+ Ġright Wheel s */ ĊĊĠĠĠ Ġoverride Ġfun Ġsend Data ( output Data : ĠW heel s Control ) Ġ{ ĊĠĠĠĠĠĠĠ Ġprint (" Direction Ġreceived : Ġ${ output Data . direction }") ĊĠĠĠĠĠĠĠ Ġval Ġduration Ġ= Ġ 1 0 0 L ĊĠĠĠĠĠĠĠ Ġwhen Ġ( output Data . direction . to Byte ()) Ġ{ ĊĠĠĠĠĠĠĠĠĠĠĠ ĠGO _ FORWARD Ġ-> Ġgo Forward ( duration ) ĊĠĠĠĠĠĠĠĠĠĠĠ ĠGO _ BACK Ġ-> Ġgo Back ( duration ) ĊĠĠĠĠĠĠĠĠĠĠĠ ĠT URN _ LEFT Ġ-> Ġturn Left ( duration ) ĊĠĠĠĠĠĠĠĠĠĠĠ ĠT URN _ RIGHT Ġ-> Ġturn Right ( duration ) ĊĠĠĠĠĠĠĠĠĠĠĠ Ġelse Ġ-> Ġthrow ĠIllegalArgumentException (" il legal Ġdirection Ġ${ output Data . direction . to Byte () }") ĊĠĠĠĠĠĠĠ Ġ} ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġfun Ġmove ( wheel s Control : ĠW heel s Control ) Ġ= Ġsend Data ( wheel s Control ) ĊĊĠĠĠ Ġfun Ġgo Forward ( duration : ĠLong ) Ġ{ ĊĠĠĠĠĠĠĠ Ġleft Wheel s Forward . pulse ( duration ) ĊĠĠĠĠĠĠĠ Ġright Wheel s Forward . pulse ( duration ) ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġfun Ġgo Back ( duration : ĠLong ) Ġ{ ĊĠĠĠĠĠĠĠ Ġleft Wheel s Backward . pulse ( duration ) ĊĠĠĠĠĠĠĠ Ġright Wheel s Backward . pulse ( duration ) ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġfun Ġturn Left ( duration : ĠLong ) Ġ{ ĊĠĠĠĠĠĠĠ Ġleft Wheel s Backward . pulse ( duration ) ĊĠĠĠĠĠĠĠ Ġright Wheel s Forward . pulse ( duration ) ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġfun Ġturn Right ( duration : ĠLong ) Ġ{ ĊĠĠĠĠĠĠĠ Ġleft Wheel s Forward . pulse ( duration ) ĊĠĠĠĠĠĠĠ Ġright Wheel s Backward . pulse ( duration ) ĊĠĠĠ Ġ} Ċ }