| Safe Haskell | None |
|---|---|
| Language | Haskell2010 |
Copilot.FRPSketch.Internals
Synopsis
- type Behavior t = Stream t
- data TypedBehavior p t = TypedBehavior (Behavior t)
- data Event p v = Event v (Stream Bool)
- newtype GenSketch pinid t = Sketch (WriterT [(TriggerLimit -> Spec, TriggerLimit -> GenFramework pinid)] (State UniqueIds) t)
- newtype UniqueIds = UniqueIds (Map String Integer)
- newtype UniqueId = UniqueId Integer
- data TriggerLimit
- getTriggerLimit :: TriggerLimit -> Behavior Bool
- addTriggerLimit :: TriggerLimit -> Behavior Bool -> Behavior Bool
- evalSketch :: Ord pinid => GenSketch pinid a -> (Maybe Spec, GenFramework pinid)
- whenB :: Ord pinid => Behavior Bool -> GenSketch pinid t -> GenSketch pinid t
- getUniqueId :: String -> GenSketch pinid UniqueId
- uniqueName :: String -> UniqueId -> String
- uniqueName' :: String -> UniqueId -> String
- data GenFramework pinid = Framework {}
- newtype CLine = CLine {}
- newtype CChunk = CChunk [CLine]
- mkCChunk :: [CLine] -> [CChunk]
- defineTriggerAlias :: String -> GenFramework pinid -> GenSketch pinid (GenFramework pinid, String)
- defineTriggerAlias' :: String -> String -> GenFramework pinid -> GenSketch pinid (GenFramework pinid, String)
- data MkInputSource pinid t = InputSource {
- defineVar :: [CChunk]
- setupInput :: [CChunk]
- inputPinmode :: Map pinid PinMode
- readInput :: [CChunk]
- inputStream :: Stream t
- mkInput :: MkInputSource pinid t -> GenSketch pinid (Behavior t)
- data PinCapabilities
- = DigitalIO
- | AnalogInput
- | PWM
- type family IsDigitalIOPin t where ...
- type family IsAnalogInputPin t where ...
- type family IsPWMPin t where ...
- type family HasPinCapability (c :: t) (list :: [t]) :: Bool where ...
- type family SameCapability a b :: Bool where ...
- data PinMode
- class Output o t where
- type family BehaviorToEvent a
- class IsBehavior behavior where
- (@:) :: behavior -> Behavior Bool -> BehaviorToEvent behavior
- class Input o t where
- input :: Input o t => o -> GenSketch pinid (Behavior t)
Documentation
type Behavior t = Stream t Source #
A value that changes over time.
This is implemented as a Stream in the Copilot DSL.
Copilot provides many operations on streams, for example
&& to combine two streams of Bools.
For documentation on using the Copilot DSL, see https://copilot-language.github.io/
data TypedBehavior p t Source #
A Behavior with an additional phantom type p.
The Compilot DSL only lets a Stream contain basic C types,
a limitation that Behavior also has. When more type safely
is needed, this can be used.
Constructors
| TypedBehavior (Behavior t) |
Instances
| Output o (Event p (Stream v)) => Output o (TypedBehavior p v) Source # | |
Defined in Copilot.FRPSketch.Internals Methods (=:) :: o -> TypedBehavior p v -> GenSketch pinid () Source # | |
| Typed a => IfThenElse (TypedBehavior p) a Source # | |
Defined in Copilot.FRPSketch Methods ifThenElse :: Behavior Bool -> TypedBehavior p a -> TypedBehavior p a -> TypedBehavior p a Source # | |
| IsBehavior (TypedBehavior p v) Source # | |
Defined in Copilot.FRPSketch.Internals Methods (@:) :: TypedBehavior p v -> Behavior Bool -> BehaviorToEvent (TypedBehavior p v) Source # | |
| type BehaviorToEvent (TypedBehavior p v) Source # | |
Defined in Copilot.FRPSketch.Internals | |
A discrete event, that occurs at particular points in time.
newtype GenSketch pinid t Source #
A sketch, implemented using Copilot.
It's best to think of the Sketch as a description of the state of the
board at any point in time.
Under the hood, the Sketch is run in a loop. On each iteration, it first
reads inputs and then updates outputs as needed.
While it is a monad, a Sketch's outputs are not updated in any particular order, because Copilot does not guarantee any order.
This is a generalized Sketch that can operate on any type of pinid.
Constructors
| Sketch (WriterT [(TriggerLimit -> Spec, TriggerLimit -> GenFramework pinid)] (State UniqueIds) t) |
Instances
data TriggerLimit Source #
Constructors
| TriggerLimit (Behavior Bool) | |
| NoTriggerLimit |
Instances
addTriggerLimit :: TriggerLimit -> Behavior Bool -> Behavior Bool Source #
evalSketch :: Ord pinid => GenSketch pinid a -> (Maybe Spec, GenFramework pinid) Source #
whenB :: Ord pinid => Behavior Bool -> GenSketch pinid t -> GenSketch pinid t Source #
Limit the effects of a Sketch to times when a Behavior Bool is True.
When applied to =:, this does the same thing as @: but without
the FRP style conversion the input Behavior into an Event. So @:
is generally better to use than this.
But, this can also be applied to input, to limit how often input
gets read. Useful to avoid performing slow input operations on every
iteration of a Sketch.
v <- whenB (frequency 10) $ input pin12
(It's best to think of the value returned by that as an Event, but it's currently represented as a Behavior, since the Copilot DSL cannot operate on Events.)
data GenFramework pinid Source #
The framework of a sketch.
This is a generalized Framework that can operate on any type of pinid.
Constructors
| Framework | |
Fields
| |
Instances
A chunk of C code. Identical chunks get deduplicated.
defineTriggerAlias :: String -> GenFramework pinid -> GenSketch pinid (GenFramework pinid, String) Source #
Copilot only supports calling a trigger with a given name once per Spec; the generated C code will fail to build if the same name is used in two triggers. This generates a unique alias that can be used in a trigger.
defineTriggerAlias' :: String -> String -> GenFramework pinid -> GenSketch pinid (GenFramework pinid, String) Source #
data MkInputSource pinid t Source #
Constructors
| InputSource | |
Fields
| |
data PinCapabilities Source #
Constructors
| DigitalIO | |
| AnalogInput | |
| PWM |
Instances
| Eq PinCapabilities Source # | |
Defined in Copilot.FRPSketch.Internals Methods (==) :: PinCapabilities -> PinCapabilities -> Bool # (/=) :: PinCapabilities -> PinCapabilities -> Bool # | |
| Ord PinCapabilities Source # | |
Defined in Copilot.FRPSketch.Internals Methods compare :: PinCapabilities -> PinCapabilities -> Ordering # (<) :: PinCapabilities -> PinCapabilities -> Bool # (<=) :: PinCapabilities -> PinCapabilities -> Bool # (>) :: PinCapabilities -> PinCapabilities -> Bool # (>=) :: PinCapabilities -> PinCapabilities -> Bool # max :: PinCapabilities -> PinCapabilities -> PinCapabilities # min :: PinCapabilities -> PinCapabilities -> PinCapabilities # | |
| Show PinCapabilities Source # | |
Defined in Copilot.FRPSketch.Internals Methods showsPrec :: Int -> PinCapabilities -> ShowS # show :: PinCapabilities -> String # showList :: [PinCapabilities] -> ShowS # | |
type family IsDigitalIOPin t where ... Source #
Equations
| IsDigitalIOPin t = 'True ~ If (HasPinCapability 'DigitalIO t) 'True (TypeError ('Text "This Pin does not support digital IO")) |
type family IsAnalogInputPin t where ... Source #
Equations
| IsAnalogInputPin t = 'True ~ If (HasPinCapability 'AnalogInput t) 'True (TypeError ('Text "This Pin does not support analog input")) |
type family HasPinCapability (c :: t) (list :: [t]) :: Bool where ... Source #
Equations
| HasPinCapability c '[] = 'False | |
| HasPinCapability c (x ': xs) = SameCapability c x || HasPinCapability c xs |
type family SameCapability a b :: Bool where ... Source #
Equations
| SameCapability 'DigitalIO 'DigitalIO = 'True | |
| SameCapability 'AnalogInput 'AnalogInput = 'True | |
| SameCapability 'PWM 'PWM = 'True | |
| SameCapability _ _ = 'False |
Constructors
| InputMode | |
| InputPullupMode | |
| OutputMode |
class Output o t where Source #
Methods
(=:) :: o -> t -> GenSketch pinid () infixr 1 Source #
Connect a Behavior or Event to an Output
led =: blinking
When a Behavior is used, its current value is written on each
iteration of the Sketch.
For example, this constantly turns on the LED, even though it will
already be on after the first iteration, because true
is a Behavior (that is always True).
led =: true
To avoid unncessary work being done, you can use an Event
instead. Then the write only happens at the points in time
when the Event occurs. To turn a Behavior into an Event,
use @:
So to make the LED only be turned on in the first iteration, and allow it to remain on thereafter without doing extra work:
led =: true @: firstIteration
type family BehaviorToEvent a Source #
This type family is open, so it can be extended when adding other data types to the IsBehavior class.
Instances
| type BehaviorToEvent (Behavior v) Source # | |
Defined in Copilot.FRPSketch.Internals | |
| type BehaviorToEvent (TypedBehavior p v) Source # | |
Defined in Copilot.FRPSketch.Internals | |
class IsBehavior behavior where Source #
Methods
(@:) :: behavior -> Behavior Bool -> BehaviorToEvent behavior Source #
Generate an Event, from some type of behavior,
that only occurs when the Behavior Bool is True.
Instances
| IsBehavior (Behavior v) Source # | |
Defined in Copilot.FRPSketch.Internals | |
| IsBehavior (TypedBehavior p v) Source # | |
Defined in Copilot.FRPSketch.Internals Methods (@:) :: TypedBehavior p v -> Behavior Bool -> BehaviorToEvent (TypedBehavior p v) Source # | |
input :: Input o t => o -> GenSketch pinid (Behavior t) Source #
Use this to read a value from a component of the board.
For example, to read a digital value from pin12 and turn on the led when the pin is high:
buttonpressed <- input pin12 led =: buttonpressed
Some pins support multiple types of reads, for example a pin may
support a digital read (Bool), and an analog to digital converter
read (ADC). In such cases you may need to specify the type of
data to read:
v <- input a0 :: Sketch (Behavior ADC)