| Safe Haskell | None |
|---|---|
| Language | Haskell2010 |
Copilot.Arduino.Internals
Description
You should not need to import this module unless you're adding support for a new model of Arduino, or an Arduino library.
Synopsis
- type Sketch = GenSketch Arduino
- newtype Pin (t :: k) = Pin Arduino
- newtype Arduino = Arduino Int16
- type ADC = Int16
- type Framework = GenFramework Arduino
- class ShowCType (t :: k) where
- type Behavior t = Stream t
- data TypedBehavior (p :: k) t = TypedBehavior (Behavior t)
- data Event (p :: k) v = Event v (Stream Bool)
- class IsBehavior behavior where
- (@:) :: behavior -> Behavior Bool -> BehaviorToEvent behavior
- class Input ctx o t where
- input :: Input ctx o t => o -> GenSketch ctx (Behavior t)
- class Output ctx o t where
- delay :: Delay
- data MilliSeconds = MilliSeconds (Stream Word32)
- data MicroSeconds = MicroSeconds (Stream Word32)
- type family IsDigitalIOPin (t :: [PinCapabilities]) where ...
- type family IsAnalogInputPin (t :: [PinCapabilities]) where ...
- type family IsPWMPin (t :: [PinCapabilities]) where ...
- blinking :: Behavior Bool
- firstIteration :: Behavior Bool
- frequency :: Integer -> Behavior Bool
- sketchSpec :: Context ctx => GenSketch ctx a -> Spec
- liftB :: (Behavior a -> Behavior r) -> TypedBehavior t a -> Behavior r
- liftB2 :: (Behavior a -> Behavior b -> Behavior r) -> TypedBehavior t a -> TypedBehavior t b -> Behavior r
- whenB :: Context ctx => Behavior Bool -> GenSketch ctx t -> GenSketch ctx t
- scheduleB :: (Typed t, Eq t, Context ctx) => Behavior t -> [(t, GenSketch ctx ())] -> GenSketch ctx ()
- class IfThenElse (t :: Type -> Type) a where
- ifThenElse :: Behavior Bool -> t a -> t a -> t a
- newtype GenSketch ctx t = GenSketch (WriterT [(TriggerLimit -> Spec, TriggerLimit -> GenFramework ctx)] (State UniqueIds) t)
- data GenFramework ctx = Framework {}
- class Ord ctx => Context ctx
- defineTriggerAlias' :: String -> String -> GenFramework ctx -> GenSketch ctx (GenFramework ctx, String)
- emptyFramework :: Context ctx => GenFramework ctx
- data PinMode
- addTriggerLimit :: TriggerLimit -> Behavior Bool -> Behavior Bool
- data PinCapabilities
- = DigitalIO
- | AnalogInput
- | PWM
- mkInput :: MkInputSource ctx t -> GenSketch ctx (Behavior t)
- data MkInputSource ctx t = InputSource {
- defineVar :: [CChunk]
- setupInput :: [CChunk]
- inputPinmode :: Map ctx PinMode
- readInput :: [CChunk]
- inputStream :: Stream t
- mkCChunk :: [CLine] -> [CChunk]
- newtype CLine = CLine {}
- data Delay = Delay
- defineTriggerAlias :: String -> GenFramework ctx -> GenSketch ctx (GenFramework ctx, String)
- getTriggerLimit :: TriggerLimit -> Behavior Bool
- data TriggerLimit
- newtype UniqueIds = UniqueIds (Map String Integer)
- newtype CChunk = CChunk [CLine]
- type family BehaviorToEvent a
- type family HasPinCapability (c :: t) (list :: [t]) :: Bool where ...
- type family SameCapability (a :: PinCapabilities) (b :: PinCapabilities) :: Bool where ...
- newtype UniqueId = UniqueId Integer
- evalSketch :: Context ctx => GenSketch ctx a -> (Maybe Spec, GenFramework ctx)
- getUniqueId :: String -> GenSketch ctx UniqueId
- uniqueName :: String -> UniqueId -> String
- uniqueName' :: String -> UniqueId -> String
Documentation
type Sketch = GenSketch Arduino Source #
An Arduino 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.
A pin on the Arduino board.
For definitions of pins like pin12,
load a module such as Copilot.Arduino.Uno, which provides the pins of a
particular board.
A type-level list indicates how a Pin can be used, so the haskell compiler will detect impossible uses of pins.
Instances
| IsAnalogInputPin t => Input Arduino (Pin t) ADC Source # | |
| IsDigitalIOPin t => Input Arduino (Pin t) Bool Source # | |
| IsPWMPin t => Output Arduino (Pin t) (Event 'PWM (Stream Word8)) Source # | |
| IsDigitalIOPin t => Output Arduino (Pin t) (Event () (Stream Bool)) Source # | |
| Show (Pin t) Source # | |
| Eq (Pin t) Source # | |
| Ord (Pin t) Source # | |
Indicates that you're programming an arduino, and not some other kind of hardware. The similar library zephyr-copilot allows programming other embedded boards in a very similar style to this one.
Instances
type Framework = GenFramework Arduino Source #
The framework of a sketch.
data TypedBehavior (p :: k) t #
Constructors
| TypedBehavior (Behavior t) |
Instances
| Output ctx o (Event p (Stream v)) => Output ctx o (TypedBehavior p v) | |
Defined in Sketch.FRP.Copilot.Types Methods (=:) :: o -> TypedBehavior p v -> GenSketch ctx () # | |
| Typed a => IfThenElse (TypedBehavior p) a | |
Defined in Sketch.FRP.Copilot Methods ifThenElse :: Behavior Bool -> TypedBehavior p a -> TypedBehavior p a -> TypedBehavior p a # | |
| IsBehavior (TypedBehavior p v) | |
Defined in Sketch.FRP.Copilot.Types Methods (@:) :: TypedBehavior p v -> Behavior Bool -> BehaviorToEvent (TypedBehavior p v) # | |
| type BehaviorToEvent (TypedBehavior p v) | |
Defined in Sketch.FRP.Copilot.Types | |
Instances
| Output Arduino RandomSeed (Event () (Stream ADC)) Source # | |
Defined in Copilot.Arduino.Library.Random | |
| Output Arduino RandomSeed (Event () (Stream Word8)) Source # | |
Defined in Copilot.Arduino.Library.Random | |
| Output Arduino SerialDevice (Event () [FormatOutput]) Source # | |
Defined in Copilot.Arduino.Library.Serial.Device Methods (=:) :: SerialDevice -> Event () [FormatOutput] -> GenSketch Arduino () # | |
| EEPROMable t => Output Arduino (Location t) (Event () (Stream t)) Source # | |
| EEPROMable t => Output Arduino (Range t) (Event () (RangeWrites t)) Source # | |
Defined in Copilot.Arduino.Library.EEPROMex | |
| IsPWMPin t => Output Arduino (Pin t) (Event 'PWM (Stream Word8)) Source # | |
| IsDigitalIOPin t => Output Arduino (Pin t) (Event () (Stream Bool)) Source # | |
class IsBehavior behavior where #
Methods
(@:) :: behavior -> Behavior Bool -> BehaviorToEvent behavior #
Instances
| EEPROMable t => IsBehavior (RangeWrites t) Source # | |
Defined in Copilot.Arduino.Library.EEPROMex Methods (@:) :: RangeWrites t -> Behavior Bool -> BehaviorToEvent (RangeWrites t) # | |
| IsBehavior (Behavior v) | |
Defined in Sketch.FRP.Copilot.Types | |
| IsBehavior [FormatOutput] Source # | |
Defined in Copilot.Arduino.Library.Serial.Device Methods (@:) :: [FormatOutput] -> Behavior Bool -> BehaviorToEvent [FormatOutput] # | |
| IsBehavior (TypedBehavior p v) | |
Defined in Sketch.FRP.Copilot.Types Methods (@:) :: TypedBehavior p v -> Behavior Bool -> BehaviorToEvent (TypedBehavior p v) # | |
Instances
| Input Arduino ClockMicros Word32 Source # | |
Defined in Copilot.Arduino | |
| Input Arduino ClockMillis Word32 Source # | |
Defined in Copilot.Arduino | |
| Input Arduino RandomInput Word32 Source # | |
Defined in Copilot.Arduino.Library.Random | |
| Input Arduino SerialDevice Int8 Source # | |
Defined in Copilot.Arduino.Library.Serial.Device | |
| (ShowCType t, EEPROMable t) => Input Arduino (RangeReads t) t Source # | |
Defined in Copilot.Arduino.Library.EEPROMex | |
| IsAnalogInputPin t => Input Arduino (Pin t) ADC Source # | |
| IsDigitalIOPin t => Input Arduino (Pin t) Bool Source # | |
Instances
data MilliSeconds #
Constructors
| MilliSeconds (Stream Word32) |
Instances
| Output Arduino Delay MilliSeconds Source # | |
Defined in Copilot.Arduino.Internals | |
data MicroSeconds #
Constructors
| MicroSeconds (Stream Word32) |
Instances
| Output Arduino Delay MicroSeconds Source # | |
Defined in Copilot.Arduino.Internals | |
type family IsDigitalIOPin (t :: [PinCapabilities]) where ... #
Equations
| IsDigitalIOPin t = 'True ~ If (HasPinCapability 'DigitalIO t) 'True (TypeError ('Text "This Pin does not support digital IO") :: Bool) |
type family IsAnalogInputPin (t :: [PinCapabilities]) where ... #
Equations
| IsAnalogInputPin t = 'True ~ If (HasPinCapability 'AnalogInput t) 'True (TypeError ('Text "This Pin does not support analog input") :: Bool) |
type family IsPWMPin (t :: [PinCapabilities]) where ... #
sketchSpec :: Context ctx => GenSketch ctx a -> Spec #
liftB2 :: (Behavior a -> Behavior b -> Behavior r) -> TypedBehavior t a -> TypedBehavior t b -> Behavior r #
scheduleB :: (Typed t, Eq t, Context ctx) => Behavior t -> [(t, GenSketch ctx ())] -> GenSketch ctx () #
class IfThenElse (t :: Type -> Type) a where #
Methods
ifThenElse :: Behavior Bool -> t a -> t a -> t a #
Instances
| Typed a => IfThenElse Stream a | |
Defined in Sketch.FRP.Copilot | |
| Context ctx => IfThenElse (GenSketch ctx) () | |
Defined in Sketch.FRP.Copilot | |
| (Context ctx, Typed a) => IfThenElse (GenSketch ctx) (Behavior a) | |
| Typed a => IfThenElse (TypedBehavior p) a | |
Defined in Sketch.FRP.Copilot Methods ifThenElse :: Behavior Bool -> TypedBehavior p a -> TypedBehavior p a -> TypedBehavior p a # | |
Constructors
| GenSketch (WriterT [(TriggerLimit -> Spec, TriggerLimit -> GenFramework ctx)] (State UniqueIds) t) |
Instances
data GenFramework ctx #
Constructors
| Framework | |
Instances
class Ord ctx => Context ctx #
Instances
| Context Arduino Source # | |
Defined in Copilot.Arduino.Internals | |
defineTriggerAlias' :: String -> String -> GenFramework ctx -> GenSketch ctx (GenFramework ctx, String) #
emptyFramework :: Context ctx => GenFramework ctx #
Constructors
| InputMode | |
| InputPullupMode | |
| OutputMode |
addTriggerLimit :: TriggerLimit -> Behavior Bool -> Behavior Bool #
data PinCapabilities #
Constructors
| DigitalIO | |
| AnalogInput | |
| PWM |
Instances
mkInput :: MkInputSource ctx t -> GenSketch ctx (Behavior t) #
data MkInputSource ctx t #
Constructors
| InputSource | |
Fields
| |
Constructors
| Delay |
Instances
| Output Arduino Delay MicroSeconds Source # | |
Defined in Copilot.Arduino.Internals | |
| Output Arduino Delay MilliSeconds Source # | |
Defined in Copilot.Arduino.Internals | |
defineTriggerAlias :: String -> GenFramework ctx -> GenSketch ctx (GenFramework ctx, String) #
getTriggerLimit :: TriggerLimit -> Behavior Bool #
data TriggerLimit #
Constructors
| TriggerLimit (Behavior Bool) | |
| NoTriggerLimit |
Instances
| Monoid TriggerLimit | |
Defined in Sketch.FRP.Copilot.Types Methods mempty :: TriggerLimit # mappend :: TriggerLimit -> TriggerLimit -> TriggerLimit # mconcat :: [TriggerLimit] -> TriggerLimit # | |
| Semigroup TriggerLimit | |
Defined in Sketch.FRP.Copilot.Types Methods (<>) :: TriggerLimit -> TriggerLimit -> TriggerLimit # sconcat :: NonEmpty TriggerLimit -> TriggerLimit stimes :: Integral b => b -> TriggerLimit -> TriggerLimit | |
| MonadWriter [(TriggerLimit -> Spec, TriggerLimit -> GenFramework ctx)] (GenSketch ctx) | |
Defined in Sketch.FRP.Copilot.Types Methods writer :: (a, [(TriggerLimit -> Spec, TriggerLimit -> GenFramework ctx)]) -> GenSketch ctx a tell :: [(TriggerLimit -> Spec, TriggerLimit -> GenFramework ctx)] -> GenSketch ctx () listen :: GenSketch ctx a -> GenSketch ctx (a, [(TriggerLimit -> Spec, TriggerLimit -> GenFramework ctx)]) pass :: GenSketch ctx (a, [(TriggerLimit -> Spec, TriggerLimit -> GenFramework ctx)] -> [(TriggerLimit -> Spec, TriggerLimit -> GenFramework ctx)]) -> GenSketch ctx a | |
type family BehaviorToEvent a #
Instances
| type BehaviorToEvent (RangeWrites t) Source # | |
Defined in Copilot.Arduino.Library.EEPROMex | |
| type BehaviorToEvent (Behavior v) | |
Defined in Sketch.FRP.Copilot.Types | |
| type BehaviorToEvent [FormatOutput] Source # | |
Defined in Copilot.Arduino.Library.Serial.Device | |
| type BehaviorToEvent (TypedBehavior p v) | |
Defined in Sketch.FRP.Copilot.Types | |
type family HasPinCapability (c :: t) (list :: [t]) :: Bool where ... #
Equations
| HasPinCapability (c :: t) ('[] :: [t]) = 'False | |
| HasPinCapability (c :: PinCapabilities) (x ': xs :: [PinCapabilities]) = SameCapability c x || HasPinCapability c xs |
type family SameCapability (a :: PinCapabilities) (b :: PinCapabilities) :: Bool where ... #
Equations
| SameCapability 'DigitalIO 'DigitalIO = 'True | |
| SameCapability 'AnalogInput 'AnalogInput = 'True | |
| SameCapability 'PWM 'PWM = 'True | |
| SameCapability _1 _2 = 'False |
evalSketch :: Context ctx => GenSketch ctx a -> (Maybe Spec, GenFramework ctx) #
getUniqueId :: String -> GenSketch ctx UniqueId #
uniqueName :: String -> UniqueId -> String #
uniqueName' :: String -> UniqueId -> String #