{-# LANGUAGE RebindableSyntax #-}
{-# LANGUAGE ScopedTypeVariables #-}
{-# LANGUAGE TypeApplications #-}
{-# LANGUAGE FlexibleInstances #-}
{-# LANGUAGE MultiParamTypeClasses #-}
{-# LANGUAGE GeneralizedNewtypeDeriving #-}
{-# LANGUAGE TypeFamilies #-}
module Copilot.Arduino.Library.EEPROMex (
maxAllowedWrites,
memPool,
StartAddress(..),
EndAddress(..),
EEPROMable,
alloc,
alloc',
Location,
Range,
RangeIndex,
allocRange,
sweepRange,
sweepRange',
RangeWrites(..),
scanRange,
RangeReads(..),
) where
import Copilot.Arduino
import Copilot.Arduino.Internals
import Control.Monad.Writer
import Data.Proxy
import qualified Prelude
maxAllowedWrites :: Word16 -> Sketch ()
maxAllowedWrites :: RangeIndex -> Sketch ()
maxAllowedWrites RangeIndex
n = [(TriggerLimit -> WriterT [SpecItem] Identity (),
TriggerLimit -> GenFramework Arduino)]
-> Sketch ()
forall w (m :: * -> *). MonadWriter w m => w -> m ()
tell [(\TriggerLimit
_ -> () -> WriterT [SpecItem] Identity ()
forall a. a -> WriterT [SpecItem] Identity a
forall (m :: * -> *) a. Monad m => a -> m a
return (), \TriggerLimit
_ -> GenFramework Arduino
f)]
where
f :: GenFramework Arduino
f = GenFramework Arduino
forall a. Monoid a => a
mempty
{ earlySetups = mkCChunk
[ CLine "#ifdef _EEPROMEX_DEBUG"
, CLine $ "EEPROM.setMaxAllowedWrites(" <> show n <> ");"
, CLine "#else"
, CLine "#error \"maxAllowedWrites cannot be checked because _EEPROMEX_DEBUG is not set.\""
, CLine "#endif"
]
, defines = mkCChunk [ includeCLine ]
}
newtype StartAddress = StartAddress Word16
deriving (Integer -> StartAddress
StartAddress -> StartAddress
StartAddress -> StartAddress -> StartAddress
(StartAddress -> StartAddress -> StartAddress)
-> (StartAddress -> StartAddress -> StartAddress)
-> (StartAddress -> StartAddress -> StartAddress)
-> (StartAddress -> StartAddress)
-> (StartAddress -> StartAddress)
-> (StartAddress -> StartAddress)
-> (Integer -> StartAddress)
-> Num StartAddress
forall a.
(a -> a -> a)
-> (a -> a -> a)
-> (a -> a -> a)
-> (a -> a)
-> (a -> a)
-> (a -> a)
-> (Integer -> a)
-> Num a
$c+ :: StartAddress -> StartAddress -> StartAddress
+ :: StartAddress -> StartAddress -> StartAddress
$c- :: StartAddress -> StartAddress -> StartAddress
- :: StartAddress -> StartAddress -> StartAddress
$c* :: StartAddress -> StartAddress -> StartAddress
* :: StartAddress -> StartAddress -> StartAddress
$cnegate :: StartAddress -> StartAddress
negate :: StartAddress -> StartAddress
$cabs :: StartAddress -> StartAddress
abs :: StartAddress -> StartAddress
$csignum :: StartAddress -> StartAddress
signum :: StartAddress -> StartAddress
$cfromInteger :: Integer -> StartAddress
fromInteger :: Integer -> StartAddress
Num, StartAddress -> StartAddress -> Bool
(StartAddress -> StartAddress -> Bool)
-> (StartAddress -> StartAddress -> Bool) -> Eq StartAddress
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: StartAddress -> StartAddress -> Bool
== :: StartAddress -> StartAddress -> Bool
$c/= :: StartAddress -> StartAddress -> Bool
/= :: StartAddress -> StartAddress -> Bool
Eq, Eq StartAddress
Eq StartAddress =>
(StartAddress -> StartAddress -> Ordering)
-> (StartAddress -> StartAddress -> Bool)
-> (StartAddress -> StartAddress -> Bool)
-> (StartAddress -> StartAddress -> Bool)
-> (StartAddress -> StartAddress -> Bool)
-> (StartAddress -> StartAddress -> StartAddress)
-> (StartAddress -> StartAddress -> StartAddress)
-> Ord StartAddress
StartAddress -> StartAddress -> Bool
StartAddress -> StartAddress -> Ordering
StartAddress -> StartAddress -> StartAddress
forall a.
Eq a =>
(a -> a -> Ordering)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> a)
-> (a -> a -> a)
-> Ord a
$ccompare :: StartAddress -> StartAddress -> Ordering
compare :: StartAddress -> StartAddress -> Ordering
$c< :: StartAddress -> StartAddress -> Bool
< :: StartAddress -> StartAddress -> Bool
$c<= :: StartAddress -> StartAddress -> Bool
<= :: StartAddress -> StartAddress -> Bool
$c> :: StartAddress -> StartAddress -> Bool
> :: StartAddress -> StartAddress -> Bool
$c>= :: StartAddress -> StartAddress -> Bool
>= :: StartAddress -> StartAddress -> Bool
$cmax :: StartAddress -> StartAddress -> StartAddress
max :: StartAddress -> StartAddress -> StartAddress
$cmin :: StartAddress -> StartAddress -> StartAddress
min :: StartAddress -> StartAddress -> StartAddress
Ord, Int -> StartAddress
StartAddress -> Int
StartAddress -> [StartAddress]
StartAddress -> StartAddress
StartAddress -> StartAddress -> [StartAddress]
StartAddress -> StartAddress -> StartAddress -> [StartAddress]
(StartAddress -> StartAddress)
-> (StartAddress -> StartAddress)
-> (Int -> StartAddress)
-> (StartAddress -> Int)
-> (StartAddress -> [StartAddress])
-> (StartAddress -> StartAddress -> [StartAddress])
-> (StartAddress -> StartAddress -> [StartAddress])
-> (StartAddress -> StartAddress -> StartAddress -> [StartAddress])
-> Enum StartAddress
forall a.
(a -> a)
-> (a -> a)
-> (Int -> a)
-> (a -> Int)
-> (a -> [a])
-> (a -> a -> [a])
-> (a -> a -> [a])
-> (a -> a -> a -> [a])
-> Enum a
$csucc :: StartAddress -> StartAddress
succ :: StartAddress -> StartAddress
$cpred :: StartAddress -> StartAddress
pred :: StartAddress -> StartAddress
$ctoEnum :: Int -> StartAddress
toEnum :: Int -> StartAddress
$cfromEnum :: StartAddress -> Int
fromEnum :: StartAddress -> Int
$cenumFrom :: StartAddress -> [StartAddress]
enumFrom :: StartAddress -> [StartAddress]
$cenumFromThen :: StartAddress -> StartAddress -> [StartAddress]
enumFromThen :: StartAddress -> StartAddress -> [StartAddress]
$cenumFromTo :: StartAddress -> StartAddress -> [StartAddress]
enumFromTo :: StartAddress -> StartAddress -> [StartAddress]
$cenumFromThenTo :: StartAddress -> StartAddress -> StartAddress -> [StartAddress]
enumFromThenTo :: StartAddress -> StartAddress -> StartAddress -> [StartAddress]
Enum, Int -> StartAddress -> String -> String
[StartAddress] -> String -> String
StartAddress -> String
(Int -> StartAddress -> String -> String)
-> (StartAddress -> String)
-> ([StartAddress] -> String -> String)
-> Show StartAddress
forall a.
(Int -> a -> String -> String)
-> (a -> String) -> ([a] -> String -> String) -> Show a
$cshowsPrec :: Int -> StartAddress -> String -> String
showsPrec :: Int -> StartAddress -> String -> String
$cshow :: StartAddress -> String
show :: StartAddress -> String
$cshowList :: [StartAddress] -> String -> String
showList :: [StartAddress] -> String -> String
Show, ReadPrec [StartAddress]
ReadPrec StartAddress
Int -> ReadS StartAddress
ReadS [StartAddress]
(Int -> ReadS StartAddress)
-> ReadS [StartAddress]
-> ReadPrec StartAddress
-> ReadPrec [StartAddress]
-> Read StartAddress
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
$creadsPrec :: Int -> ReadS StartAddress
readsPrec :: Int -> ReadS StartAddress
$creadList :: ReadS [StartAddress]
readList :: ReadS [StartAddress]
$creadPrec :: ReadPrec StartAddress
readPrec :: ReadPrec StartAddress
$creadListPrec :: ReadPrec [StartAddress]
readListPrec :: ReadPrec [StartAddress]
Read, StartAddress
StartAddress -> StartAddress -> Bounded StartAddress
forall a. a -> a -> Bounded a
$cminBound :: StartAddress
minBound :: StartAddress
$cmaxBound :: StartAddress
maxBound :: StartAddress
Bounded, Enum StartAddress
Real StartAddress
(Real StartAddress, Enum StartAddress) =>
(StartAddress -> StartAddress -> StartAddress)
-> (StartAddress -> StartAddress -> StartAddress)
-> (StartAddress -> StartAddress -> StartAddress)
-> (StartAddress -> StartAddress -> StartAddress)
-> (StartAddress -> StartAddress -> (StartAddress, StartAddress))
-> (StartAddress -> StartAddress -> (StartAddress, StartAddress))
-> (StartAddress -> Integer)
-> Integral StartAddress
StartAddress -> Integer
StartAddress -> StartAddress -> (StartAddress, StartAddress)
StartAddress -> StartAddress -> StartAddress
forall a.
(Real a, Enum a) =>
(a -> a -> a)
-> (a -> a -> a)
-> (a -> a -> a)
-> (a -> a -> a)
-> (a -> a -> (a, a))
-> (a -> a -> (a, a))
-> (a -> Integer)
-> Integral a
$cquot :: StartAddress -> StartAddress -> StartAddress
quot :: StartAddress -> StartAddress -> StartAddress
$crem :: StartAddress -> StartAddress -> StartAddress
rem :: StartAddress -> StartAddress -> StartAddress
$cdiv :: StartAddress -> StartAddress -> StartAddress
div :: StartAddress -> StartAddress -> StartAddress
$cmod :: StartAddress -> StartAddress -> StartAddress
mod :: StartAddress -> StartAddress -> StartAddress
$cquotRem :: StartAddress -> StartAddress -> (StartAddress, StartAddress)
quotRem :: StartAddress -> StartAddress -> (StartAddress, StartAddress)
$cdivMod :: StartAddress -> StartAddress -> (StartAddress, StartAddress)
divMod :: StartAddress -> StartAddress -> (StartAddress, StartAddress)
$ctoInteger :: StartAddress -> Integer
toInteger :: StartAddress -> Integer
Integral, Num StartAddress
Ord StartAddress
(Num StartAddress, Ord StartAddress) =>
(StartAddress -> Rational) -> Real StartAddress
StartAddress -> Rational
forall a. (Num a, Ord a) => (a -> Rational) -> Real a
$ctoRational :: StartAddress -> Rational
toRational :: StartAddress -> Rational
Real)
newtype EndAddress = EndAddress Word16
deriving (Integer -> EndAddress
EndAddress -> EndAddress
EndAddress -> EndAddress -> EndAddress
(EndAddress -> EndAddress -> EndAddress)
-> (EndAddress -> EndAddress -> EndAddress)
-> (EndAddress -> EndAddress -> EndAddress)
-> (EndAddress -> EndAddress)
-> (EndAddress -> EndAddress)
-> (EndAddress -> EndAddress)
-> (Integer -> EndAddress)
-> Num EndAddress
forall a.
(a -> a -> a)
-> (a -> a -> a)
-> (a -> a -> a)
-> (a -> a)
-> (a -> a)
-> (a -> a)
-> (Integer -> a)
-> Num a
$c+ :: EndAddress -> EndAddress -> EndAddress
+ :: EndAddress -> EndAddress -> EndAddress
$c- :: EndAddress -> EndAddress -> EndAddress
- :: EndAddress -> EndAddress -> EndAddress
$c* :: EndAddress -> EndAddress -> EndAddress
* :: EndAddress -> EndAddress -> EndAddress
$cnegate :: EndAddress -> EndAddress
negate :: EndAddress -> EndAddress
$cabs :: EndAddress -> EndAddress
abs :: EndAddress -> EndAddress
$csignum :: EndAddress -> EndAddress
signum :: EndAddress -> EndAddress
$cfromInteger :: Integer -> EndAddress
fromInteger :: Integer -> EndAddress
Num, EndAddress -> EndAddress -> Bool
(EndAddress -> EndAddress -> Bool)
-> (EndAddress -> EndAddress -> Bool) -> Eq EndAddress
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: EndAddress -> EndAddress -> Bool
== :: EndAddress -> EndAddress -> Bool
$c/= :: EndAddress -> EndAddress -> Bool
/= :: EndAddress -> EndAddress -> Bool
Eq, Eq EndAddress
Eq EndAddress =>
(EndAddress -> EndAddress -> Ordering)
-> (EndAddress -> EndAddress -> Bool)
-> (EndAddress -> EndAddress -> Bool)
-> (EndAddress -> EndAddress -> Bool)
-> (EndAddress -> EndAddress -> Bool)
-> (EndAddress -> EndAddress -> EndAddress)
-> (EndAddress -> EndAddress -> EndAddress)
-> Ord EndAddress
EndAddress -> EndAddress -> Bool
EndAddress -> EndAddress -> Ordering
EndAddress -> EndAddress -> EndAddress
forall a.
Eq a =>
(a -> a -> Ordering)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> a)
-> (a -> a -> a)
-> Ord a
$ccompare :: EndAddress -> EndAddress -> Ordering
compare :: EndAddress -> EndAddress -> Ordering
$c< :: EndAddress -> EndAddress -> Bool
< :: EndAddress -> EndAddress -> Bool
$c<= :: EndAddress -> EndAddress -> Bool
<= :: EndAddress -> EndAddress -> Bool
$c> :: EndAddress -> EndAddress -> Bool
> :: EndAddress -> EndAddress -> Bool
$c>= :: EndAddress -> EndAddress -> Bool
>= :: EndAddress -> EndAddress -> Bool
$cmax :: EndAddress -> EndAddress -> EndAddress
max :: EndAddress -> EndAddress -> EndAddress
$cmin :: EndAddress -> EndAddress -> EndAddress
min :: EndAddress -> EndAddress -> EndAddress
Ord, Int -> EndAddress
EndAddress -> Int
EndAddress -> [EndAddress]
EndAddress -> EndAddress
EndAddress -> EndAddress -> [EndAddress]
EndAddress -> EndAddress -> EndAddress -> [EndAddress]
(EndAddress -> EndAddress)
-> (EndAddress -> EndAddress)
-> (Int -> EndAddress)
-> (EndAddress -> Int)
-> (EndAddress -> [EndAddress])
-> (EndAddress -> EndAddress -> [EndAddress])
-> (EndAddress -> EndAddress -> [EndAddress])
-> (EndAddress -> EndAddress -> EndAddress -> [EndAddress])
-> Enum EndAddress
forall a.
(a -> a)
-> (a -> a)
-> (Int -> a)
-> (a -> Int)
-> (a -> [a])
-> (a -> a -> [a])
-> (a -> a -> [a])
-> (a -> a -> a -> [a])
-> Enum a
$csucc :: EndAddress -> EndAddress
succ :: EndAddress -> EndAddress
$cpred :: EndAddress -> EndAddress
pred :: EndAddress -> EndAddress
$ctoEnum :: Int -> EndAddress
toEnum :: Int -> EndAddress
$cfromEnum :: EndAddress -> Int
fromEnum :: EndAddress -> Int
$cenumFrom :: EndAddress -> [EndAddress]
enumFrom :: EndAddress -> [EndAddress]
$cenumFromThen :: EndAddress -> EndAddress -> [EndAddress]
enumFromThen :: EndAddress -> EndAddress -> [EndAddress]
$cenumFromTo :: EndAddress -> EndAddress -> [EndAddress]
enumFromTo :: EndAddress -> EndAddress -> [EndAddress]
$cenumFromThenTo :: EndAddress -> EndAddress -> EndAddress -> [EndAddress]
enumFromThenTo :: EndAddress -> EndAddress -> EndAddress -> [EndAddress]
Enum, Int -> EndAddress -> String -> String
[EndAddress] -> String -> String
EndAddress -> String
(Int -> EndAddress -> String -> String)
-> (EndAddress -> String)
-> ([EndAddress] -> String -> String)
-> Show EndAddress
forall a.
(Int -> a -> String -> String)
-> (a -> String) -> ([a] -> String -> String) -> Show a
$cshowsPrec :: Int -> EndAddress -> String -> String
showsPrec :: Int -> EndAddress -> String -> String
$cshow :: EndAddress -> String
show :: EndAddress -> String
$cshowList :: [EndAddress] -> String -> String
showList :: [EndAddress] -> String -> String
Show, ReadPrec [EndAddress]
ReadPrec EndAddress
Int -> ReadS EndAddress
ReadS [EndAddress]
(Int -> ReadS EndAddress)
-> ReadS [EndAddress]
-> ReadPrec EndAddress
-> ReadPrec [EndAddress]
-> Read EndAddress
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
$creadsPrec :: Int -> ReadS EndAddress
readsPrec :: Int -> ReadS EndAddress
$creadList :: ReadS [EndAddress]
readList :: ReadS [EndAddress]
$creadPrec :: ReadPrec EndAddress
readPrec :: ReadPrec EndAddress
$creadListPrec :: ReadPrec [EndAddress]
readListPrec :: ReadPrec [EndAddress]
Read, EndAddress
EndAddress -> EndAddress -> Bounded EndAddress
forall a. a -> a -> Bounded a
$cminBound :: EndAddress
minBound :: EndAddress
$cmaxBound :: EndAddress
maxBound :: EndAddress
Bounded, Enum EndAddress
Real EndAddress
(Real EndAddress, Enum EndAddress) =>
(EndAddress -> EndAddress -> EndAddress)
-> (EndAddress -> EndAddress -> EndAddress)
-> (EndAddress -> EndAddress -> EndAddress)
-> (EndAddress -> EndAddress -> EndAddress)
-> (EndAddress -> EndAddress -> (EndAddress, EndAddress))
-> (EndAddress -> EndAddress -> (EndAddress, EndAddress))
-> (EndAddress -> Integer)
-> Integral EndAddress
EndAddress -> Integer
EndAddress -> EndAddress -> (EndAddress, EndAddress)
EndAddress -> EndAddress -> EndAddress
forall a.
(Real a, Enum a) =>
(a -> a -> a)
-> (a -> a -> a)
-> (a -> a -> a)
-> (a -> a -> a)
-> (a -> a -> (a, a))
-> (a -> a -> (a, a))
-> (a -> Integer)
-> Integral a
$cquot :: EndAddress -> EndAddress -> EndAddress
quot :: EndAddress -> EndAddress -> EndAddress
$crem :: EndAddress -> EndAddress -> EndAddress
rem :: EndAddress -> EndAddress -> EndAddress
$cdiv :: EndAddress -> EndAddress -> EndAddress
div :: EndAddress -> EndAddress -> EndAddress
$cmod :: EndAddress -> EndAddress -> EndAddress
mod :: EndAddress -> EndAddress -> EndAddress
$cquotRem :: EndAddress -> EndAddress -> (EndAddress, EndAddress)
quotRem :: EndAddress -> EndAddress -> (EndAddress, EndAddress)
$cdivMod :: EndAddress -> EndAddress -> (EndAddress, EndAddress)
divMod :: EndAddress -> EndAddress -> (EndAddress, EndAddress)
$ctoInteger :: EndAddress -> Integer
toInteger :: EndAddress -> Integer
Integral, Num EndAddress
Ord EndAddress
(Num EndAddress, Ord EndAddress) =>
(EndAddress -> Rational) -> Real EndAddress
EndAddress -> Rational
forall a. (Num a, Ord a) => (a -> Rational) -> Real a
$ctoRational :: EndAddress -> Rational
toRational :: EndAddress -> Rational
Real)
memPool :: StartAddress -> EndAddress -> Sketch ()
memPool :: StartAddress -> EndAddress -> Sketch ()
memPool (StartAddress RangeIndex
start) (EndAddress RangeIndex
end) =
[(TriggerLimit -> WriterT [SpecItem] Identity (),
TriggerLimit -> GenFramework Arduino)]
-> Sketch ()
forall w (m :: * -> *). MonadWriter w m => w -> m ()
tell [(\TriggerLimit
_ -> () -> WriterT [SpecItem] Identity ()
forall a. a -> WriterT [SpecItem] Identity a
forall (m :: * -> *) a. Monad m => a -> m a
return (), \TriggerLimit
_ -> GenFramework Arduino
f)]
where
f :: GenFramework Arduino
f = GenFramework Arduino
forall a. Monoid a => a
mempty
{ earlySetups = mkCChunk
[ CLine $ "EEPROM.setMemPool("
<> show start
<> ", "
<> show end
<> ");"
]
, defines = mkCChunk [ includeCLine ]
}
alloc :: forall t. (EEPROMable t) => Sketch (Behavior t, Location t)
alloc :: forall t. EEPROMable t => Sketch (Behavior t, Location t)
alloc = t -> Sketch (Behavior t, Location t)
forall t. EEPROMable t => t -> Sketch (Behavior t, Location t)
alloc' (Proxy t -> t
forall t. EEPROMable t => Proxy t -> t
factoryValue (forall t. Proxy t
forall {k} (t :: k). Proxy t
Proxy @t))
alloc' :: forall t. (EEPROMable t) => t -> Sketch (Behavior t, Location t)
alloc' :: forall t. EEPROMable t => t -> Sketch (Behavior t, Location t)
alloc' t
interpretval = do
UniqueId
i <- String -> GenSketch Arduino UniqueId
forall ctx. String -> GenSketch ctx UniqueId
getUniqueId String
"eeprom"
let addrvarname :: String
addrvarname = String -> UniqueId -> String
uniqueName String
"eeprom_address" UniqueId
i
let bootvarname :: String
bootvarname = String -> UniqueId -> String
uniqueName String
"eeprom_boot_val" UniqueId
i
let proxy :: Proxy t
proxy = forall t. Proxy t
forall {k} (t :: k). Proxy t
Proxy @t
Behavior t
bootval <- MkInputSource Arduino t -> GenSketch Arduino (Behavior t)
forall ctx t. MkInputSource ctx t -> GenSketch ctx (Behavior t)
mkInput (MkInputSource Arduino t -> GenSketch Arduino (Behavior t))
-> MkInputSource Arduino t -> GenSketch Arduino (Behavior t)
forall a b. (a -> b) -> a -> b
$ InputSource
{ defineVar :: [CChunk]
defineVar =
[ [CLine] -> CChunk
CChunk [CLine
includeCLine]
, [CLine] -> CChunk
CChunk
[ String -> CLine
CLine (String -> CLine) -> String -> CLine
forall a b. (a -> b) -> a -> b
$ String
"int " String -> String -> String
forall a. Semigroup a => a -> a -> a
<> String
addrvarname String -> String -> String
forall a. Semigroup a => a -> a -> a
<> String
";"
, String -> CLine
CLine (String -> CLine) -> String -> CLine
forall a b. (a -> b) -> a -> b
$ Proxy t -> String
forall {k} (t :: k). ShowCType t => Proxy t -> String
showCType Proxy t
proxy String -> String -> String
forall a. Semigroup a => a -> a -> a
<> String
" " String -> String -> String
forall a. Semigroup a => a -> a -> a
<> String
bootvarname String -> String -> String
forall a. Semigroup a => a -> a -> a
<> String
";"
, String -> CLine
CLine (String -> CLine) -> String -> CLine
forall a b. (a -> b) -> a -> b
$ String
"void " String -> String -> String
forall a. Semigroup a => a -> a -> a
<> UniqueId -> String
eepromWriterName UniqueId
i
String -> String -> String
forall a. Semigroup a => a -> a -> a
<> String
"(" String -> String -> String
forall a. Semigroup a => a -> a -> a
<> Proxy t -> String
forall {k} (t :: k). ShowCType t => Proxy t -> String
showCType Proxy t
proxy String -> String -> String
forall a. Semigroup a => a -> a -> a
<> String
" value) {"
, String -> CLine
CLine (String -> CLine) -> String -> CLine
forall a b. (a -> b) -> a -> b
$ String
" EEPROM." String -> String -> String
forall a. Semigroup a => a -> a -> a
<> Proxy t -> String
forall t. EEPROMable t => Proxy t -> String
writeValue Proxy t
proxy
String -> String -> String
forall a. Semigroup a => a -> a -> a
<> String
"(" String -> String -> String
forall a. Semigroup a => a -> a -> a
<> String
addrvarname String -> String -> String
forall a. Semigroup a => a -> a -> a
<> String
", value);"
, String -> CLine
CLine String
"}"
]
]
, setupInput :: [CChunk]
setupInput = [CLine] -> [CChunk]
mkCChunk
[ String -> CLine
CLine (String -> CLine) -> String -> CLine
forall a b. (a -> b) -> a -> b
$ String
addrvarname String -> String -> String
forall a. Semigroup a => a -> a -> a
<>
String
" = EEPROM.getAddress(sizeof("
String -> String -> String
forall a. Semigroup a => a -> a -> a
<> Proxy t -> String
forall {k} (t :: k). ShowCType t => Proxy t -> String
showCType Proxy t
proxy String -> String -> String
forall a. Semigroup a => a -> a -> a
<> String
"));"
, String -> CLine
CLine (String -> CLine) -> String -> CLine
forall a b. (a -> b) -> a -> b
$ String
bootvarname String -> String -> String
forall a. Semigroup a => a -> a -> a
<>
String
" = EEPROM."
String -> String -> String
forall a. Semigroup a => a -> a -> a
<> Proxy t -> String
forall t. EEPROMable t => Proxy t -> String
readValue Proxy t
proxy String -> String -> String
forall a. Semigroup a => a -> a -> a
<> String
"(" String -> String -> String
forall a. Semigroup a => a -> a -> a
<> String
addrvarname String -> String -> String
forall a. Semigroup a => a -> a -> a
<> String
");"
]
, readInput :: [CChunk]
readInput = []
, inputStream :: Behavior t
inputStream = String -> Maybe [t] -> Behavior t
forall a. Typed a => String -> Maybe [a] -> Stream a
extern String
bootvarname ([t] -> Maybe [t]
forall a. a -> Maybe a
Just (t -> [t]
forall a. a -> [a]
repeat t
interpretval))
, inputPinmode :: Map Arduino PinMode
inputPinmode = Map Arduino PinMode
forall a. Monoid a => a
mempty
}
(Behavior t, Location t) -> Sketch (Behavior t, Location t)
forall a. a -> GenSketch Arduino a
forall (m :: * -> *) a. Monad m => a -> m a
return (Behavior t
bootval, UniqueId -> Location t
forall t. UniqueId -> Location t
Location UniqueId
i)
eepromWriterName :: UniqueId -> String
eepromWriterName :: UniqueId -> String
eepromWriterName = String -> UniqueId -> String
uniqueName' String
"eeprom_write"
data Location t = Location UniqueId
instance EEPROMable t => Output Arduino (Location t) (Event () (Stream t)) where
Location UniqueId
i =: :: Location t -> Event () (Stream t) -> Sketch ()
=: (Event Stream t
v Stream Bool
c) = do
(GenFramework Arduino
f, String
triggername) <- String
-> GenFramework Arduino
-> GenSketch Arduino (GenFramework Arduino, String)
forall ctx.
String
-> GenFramework ctx -> GenSketch ctx (GenFramework ctx, String)
defineTriggerAlias (UniqueId -> String
eepromWriterName UniqueId
i) GenFramework Arduino
forall a. Monoid a => a
mempty
[(TriggerLimit -> WriterT [SpecItem] Identity (),
TriggerLimit -> GenFramework Arduino)]
-> Sketch ()
forall w (m :: * -> *). MonadWriter w m => w -> m ()
tell [(String -> TriggerLimit -> WriterT [SpecItem] Identity ()
go String
triggername, \TriggerLimit
_ -> GenFramework Arduino
f)]
where
go :: String -> TriggerLimit -> WriterT [SpecItem] Identity ()
go String
triggername TriggerLimit
tl =
let c' :: Stream Bool
c' = TriggerLimit -> Stream Bool -> Stream Bool
addTriggerLimit TriggerLimit
tl Stream Bool
c
in String -> Stream Bool -> [Arg] -> WriterT [SpecItem] Identity ()
trigger String
triggername Stream Bool
c' [Stream t -> Arg
forall a. Typed a => Stream a -> Arg
arg Stream t
v]
data Range t = Range
{ forall t. Range t -> Location (Range t)
rangeLocation :: Location (Range t)
, forall t. Range t -> RangeIndex
rangeSize :: Word16
}
allocRange :: (EEPROMable t) => Word16 -> Sketch (Range t)
allocRange :: forall t. EEPROMable t => RangeIndex -> Sketch (Range t)
allocRange RangeIndex
sz = do
UniqueId
i <- String -> GenSketch Arduino UniqueId
forall ctx. String -> GenSketch ctx UniqueId
getUniqueId String
"eeprom"
Range t -> Sketch (Range t)
forall a. a -> GenSketch Arduino a
forall (m :: * -> *) a. Monad m => a -> m a
return (Location (Range t) -> RangeIndex -> Range t
forall t. Location (Range t) -> RangeIndex -> Range t
Range (UniqueId -> Location (Range t)
forall t. UniqueId -> Location t
Location UniqueId
i) RangeIndex
sz)
data RangeWrites t = RangeWrites
(Behavior Bool -> Behavior RangeIndex)
(Behavior t)
type RangeIndex = Word16
instance EEPROMable t => Output Arduino (Range t) (RangeWrites t) where
=: :: Range t -> RangeWrites t -> Sketch ()
(=:) = Stream Bool -> Range t -> RangeWrites t -> Sketch ()
forall t.
EEPROMable t =>
Stream Bool -> Range t -> RangeWrites t -> Sketch ()
writeRange Stream Bool
true
instance EEPROMable t => Output Arduino (Range t) (Event () (RangeWrites t)) where
Range t
range =: :: Range t -> Event () (RangeWrites t) -> Sketch ()
=: Event RangeWrites t
ws Stream Bool
c =
Stream Bool -> Range t -> RangeWrites t -> Sketch ()
forall t.
EEPROMable t =>
Stream Bool -> Range t -> RangeWrites t -> Sketch ()
writeRange Stream Bool
c Range t
range RangeWrites t
ws
instance EEPROMable t => IsBehavior (RangeWrites t) where
@: :: RangeWrites t -> Stream Bool -> BehaviorToEvent (RangeWrites t)
(@:) = RangeWrites t -> Stream Bool -> BehaviorToEvent (RangeWrites t)
RangeWrites t -> Stream Bool -> Event () (RangeWrites t)
forall {k} (p :: k) v. v -> Stream Bool -> Event p v
Event
type instance BehaviorToEvent (RangeWrites t) = Event () (RangeWrites t)
writeRange :: forall t. EEPROMable t => Behavior Bool -> Range t -> RangeWrites t -> Sketch()
writeRange :: forall t.
EEPROMable t =>
Stream Bool -> Range t -> RangeWrites t -> Sketch ()
writeRange Stream Bool
c Range t
range (RangeWrites Stream Bool -> Stream RangeIndex
idx Behavior t
v) = do
(GenFramework Arduino
f', String
triggername) <- String
-> GenFramework Arduino
-> GenSketch Arduino (GenFramework Arduino, String)
forall ctx.
String
-> GenFramework ctx -> GenSketch ctx (GenFramework ctx, String)
defineTriggerAlias String
writername GenFramework Arduino
f
[(TriggerLimit -> WriterT [SpecItem] Identity (),
TriggerLimit -> GenFramework Arduino)]
-> Sketch ()
forall w (m :: * -> *). MonadWriter w m => w -> m ()
tell [(String -> TriggerLimit -> WriterT [SpecItem] Identity ()
spec String
triggername, \TriggerLimit
_ -> GenFramework Arduino
f')]
where
Location UniqueId
i = Range t -> Location (Range t)
forall t. Range t -> Location (Range t)
rangeLocation Range t
range
idx' :: Stream RangeIndex
idx' = Stream Bool -> Stream RangeIndex
idx Stream Bool
c Stream RangeIndex -> Stream RangeIndex -> Stream RangeIndex
forall a. (Typed a, Integral a) => Stream a -> Stream a -> Stream a
`mod` RangeIndex -> Stream RangeIndex
forall a. Typed a => a -> Stream a
constant (Range t -> RangeIndex
forall t. Range t -> RangeIndex
rangeSize Range t
range)
startaddrvarname :: String
startaddrvarname = UniqueId -> String
eepromRangeStartAddrName UniqueId
i
writername :: String
writername = String -> UniqueId -> String
uniqueName String
"eeprom_range_write" UniqueId
i
proxy :: Proxy t
proxy = forall t. Proxy t
forall {k} (t :: k). Proxy t
Proxy @t
f :: GenFramework Arduino
f = Framework
{ defines :: [CChunk]
defines =
[ [CLine] -> CChunk
CChunk [CLine
includeCLine]
, [CLine] -> CChunk
CChunk
[ String -> CLine
CLine (String -> CLine) -> String -> CLine
forall a b. (a -> b) -> a -> b
$ String
"int " String -> String -> String
forall a. Semigroup a => a -> a -> a
<> String
startaddrvarname String -> String -> String
forall a. Semigroup a => a -> a -> a
<> String
";"
, String -> CLine
CLine (String -> CLine) -> String -> CLine
forall a b. (a -> b) -> a -> b
$ String
"void " String -> String -> String
forall a. Semigroup a => a -> a -> a
<> String
writername
String -> String -> String
forall a. Semigroup a => a -> a -> a
<> String
"(" String -> String -> String
forall a. Semigroup a => a -> a -> a
<> Proxy t -> String
forall {k} (t :: k). ShowCType t => Proxy t -> String
showCType Proxy t
proxy String -> String -> String
forall a. Semigroup a => a -> a -> a
<> String
" value"
String -> String -> String
forall a. Semigroup a => a -> a -> a
<> String
", " String -> String -> String
forall a. Semigroup a => a -> a -> a
<> Proxy RangeIndex -> String
forall {k} (t :: k). ShowCType t => Proxy t -> String
showCType (forall t. Proxy t
forall {k} (t :: k). Proxy t
Proxy @Word16) String -> String -> String
forall a. Semigroup a => a -> a -> a
<> String
" offset"
String -> String -> String
forall a. Semigroup a => a -> a -> a
<> String
") {"
, String -> CLine
CLine (String -> CLine) -> String -> CLine
forall a b. (a -> b) -> a -> b
$ String
" EEPROM." String -> String -> String
forall a. Semigroup a => a -> a -> a
<> Proxy t -> String
forall t. EEPROMable t => Proxy t -> String
writeValue Proxy t
proxy
String -> String -> String
forall a. Semigroup a => a -> a -> a
<> String
"(" String -> String -> String
forall a. Semigroup a => a -> a -> a
<> String
startaddrvarname
String -> String -> String
forall a. Semigroup a => a -> a -> a
<> String
" + offset*sizeof("
String -> String -> String
forall a. Semigroup a => a -> a -> a
<> Proxy t -> String
forall {k} (t :: k). ShowCType t => Proxy t -> String
showCType Proxy t
proxy
String -> String -> String
forall a. Semigroup a => a -> a -> a
<> String
")"
String -> String -> String
forall a. Semigroup a => a -> a -> a
<> String
", value);"
, String -> CLine
CLine String
"}"
]
]
, setups :: [CChunk]
setups = [CLine] -> [CChunk]
mkCChunk
[ String -> CLine
CLine (String -> CLine) -> String -> CLine
forall a b. (a -> b) -> a -> b
$ String
startaddrvarname String -> String -> String
forall a. Semigroup a => a -> a -> a
<> String
" = EEPROM.getAddress"
String -> String -> String
forall a. Semigroup a => a -> a -> a
<> String
"(sizeof(" String -> String -> String
forall a. Semigroup a => a -> a -> a
<> Proxy t -> String
forall {k} (t :: k). ShowCType t => Proxy t -> String
showCType Proxy t
proxy String -> String -> String
forall a. Semigroup a => a -> a -> a
<> String
")"
String -> String -> String
forall a. Semigroup a => a -> a -> a
<> String
" * " String -> String -> String
forall a. Semigroup a => a -> a -> a
<> RangeIndex -> String
forall a. Show a => a -> String
show (Range t -> RangeIndex
forall t. Range t -> RangeIndex
rangeSize Range t
range)
String -> String -> String
forall a. Semigroup a => a -> a -> a
<> String
");"
]
, earlySetups :: [CChunk]
earlySetups = []
, pinmodes :: Map Arduino (Set PinMode)
pinmodes = Map Arduino (Set PinMode)
forall a. Monoid a => a
mempty
, loops :: [CChunk]
loops = [CChunk]
forall a. Monoid a => a
mempty
}
spec :: String -> TriggerLimit -> WriterT [SpecItem] Identity ()
spec String
triggername TriggerLimit
tl =
let c' :: Stream Bool
c' = TriggerLimit -> Stream Bool -> Stream Bool
addTriggerLimit TriggerLimit
tl Stream Bool
c
in String -> Stream Bool -> [Arg] -> WriterT [SpecItem] Identity ()
trigger String
triggername Stream Bool
c' [Stream RangeIndex -> Arg
forall a. Typed a => Stream a -> Arg
arg Stream RangeIndex
idx', Behavior t -> Arg
forall a. Typed a => Stream a -> Arg
arg Behavior t
v]
eepromRangeStartAddrName :: UniqueId -> String
eepromRangeStartAddrName :: UniqueId -> String
eepromRangeStartAddrName = String -> UniqueId -> String
uniqueName String
"eeprom_range_address"
sweepRange :: RangeIndex -> Behavior t -> RangeWrites t
sweepRange :: forall t. RangeIndex -> Behavior t -> RangeWrites t
sweepRange RangeIndex
start = (Stream Bool -> Stream RangeIndex) -> Behavior t -> RangeWrites t
forall t.
(Stream Bool -> Stream RangeIndex) -> Behavior t -> RangeWrites t
RangeWrites (RangeIndex -> Stream Bool -> Stream RangeIndex
sweepRange' RangeIndex
start)
sweepRange' :: RangeIndex -> Behavior Bool -> Behavior RangeIndex
sweepRange' :: RangeIndex -> Stream Bool -> Stream RangeIndex
sweepRange' RangeIndex
start Stream Bool
c = Stream RangeIndex
cnt
where
cnt :: Stream RangeIndex
cnt = [RangeIndex
start] [RangeIndex] -> Stream RangeIndex -> Stream RangeIndex
forall a. Typed a => [a] -> Stream a -> Stream a
++ Stream RangeIndex
rest
rest :: Stream RangeIndex
rest = if Stream Bool
c then Stream RangeIndex
cnt Stream RangeIndex -> Stream RangeIndex -> Stream RangeIndex
forall a. Num a => a -> a -> a
+ Stream RangeIndex
1 else Stream RangeIndex
cnt
data RangeReads t = RangeReads (Range t) RangeIndex (Behavior RangeIndex)
scanRange :: Range t -> RangeIndex -> RangeReads t
scanRange :: forall t. Range t -> RangeIndex -> RangeReads t
scanRange Range t
r RangeIndex
startidx = Range t -> RangeIndex -> Stream RangeIndex -> RangeReads t
forall t.
Range t -> RangeIndex -> Stream RangeIndex -> RangeReads t
RangeReads Range t
r RangeIndex
startidx Stream RangeIndex
cnt
where
cnt :: Stream RangeIndex
cnt = [RangeIndex
startidxRangeIndex -> RangeIndex -> RangeIndex
forall a. Num a => a -> a -> a
+RangeIndex
1] [RangeIndex] -> Stream RangeIndex -> Stream RangeIndex
forall a. Typed a => [a] -> Stream a -> Stream a
++ Stream RangeIndex
rest
rest :: Stream RangeIndex
rest = Stream RangeIndex
cnt Stream RangeIndex -> Stream RangeIndex -> Stream RangeIndex
forall a. Num a => a -> a -> a
+ Stream RangeIndex
1
instance (ShowCType t, EEPROMable t) => Input Arduino (RangeReads t) t where
input' :: RangeReads t -> [t] -> GenSketch Arduino (Behavior t)
input' (RangeReads Range t
range RangeIndex
startidx Stream RangeIndex
idx) [t]
interpretvalues = do
(GenFramework Arduino
f, String
triggername) <- String
-> GenFramework Arduino
-> GenSketch Arduino (GenFramework Arduino, String)
forall ctx.
String
-> GenFramework ctx -> GenSketch ctx (GenFramework ctx, String)
defineTriggerAlias String
indexvarupdatername GenFramework Arduino
forall a. Monoid a => a
mempty
let t :: TriggerLimit -> WriterT [SpecItem] Identity ()
t TriggerLimit
tl =
let c :: Stream Bool
c = TriggerLimit -> Stream Bool
getTriggerLimit TriggerLimit
tl
in String -> Stream Bool -> [Arg] -> WriterT [SpecItem] Identity ()
trigger String
triggername Stream Bool
c [Stream RangeIndex -> Arg
forall a. Typed a => Stream a -> Arg
arg Stream RangeIndex
idx']
[(TriggerLimit -> WriterT [SpecItem] Identity (),
TriggerLimit -> GenFramework Arduino)]
-> Sketch ()
forall w (m :: * -> *). MonadWriter w m => w -> m ()
tell [(TriggerLimit -> WriterT [SpecItem] Identity ()
t, \TriggerLimit
_ -> GenFramework Arduino
f)]
MkInputSource Arduino t -> GenSketch Arduino (Behavior t)
forall ctx t. MkInputSource ctx t -> GenSketch ctx (Behavior t)
mkInput (MkInputSource Arduino t -> GenSketch Arduino (Behavior t))
-> MkInputSource Arduino t -> GenSketch Arduino (Behavior t)
forall a b. (a -> b) -> a -> b
$ InputSource
{ defineVar :: [CChunk]
defineVar = [CLine] -> [CChunk]
mkCChunk
[ String -> CLine
CLine (String -> CLine) -> String -> CLine
forall a b. (a -> b) -> a -> b
$ Proxy t -> String
forall {k} (t :: k). ShowCType t => Proxy t -> String
showCType Proxy t
proxy String -> String -> String
forall a. Semigroup a => a -> a -> a
<> String
" " String -> String -> String
forall a. Semigroup a => a -> a -> a
<> String
valname String -> String -> String
forall a. Semigroup a => a -> a -> a
<> String
";"
, String -> CLine
CLine (String -> CLine) -> String -> CLine
forall a b. (a -> b) -> a -> b
$ String
"int " String -> String -> String
forall a. Semigroup a => a -> a -> a
<> String
indexvarname String -> String -> String
forall a. Semigroup a => a -> a -> a
<> String
";"
, String -> CLine
CLine (String -> CLine) -> String -> CLine
forall a b. (a -> b) -> a -> b
$ String
"void " String -> String -> String
forall a. Semigroup a => a -> a -> a
<> String
indexvarupdatername String -> String -> String
forall a. Semigroup a => a -> a -> a
<> String
" (int idx) {"
, String -> CLine
CLine (String -> CLine) -> String -> CLine
forall a b. (a -> b) -> a -> b
$ String
" " String -> String -> String
forall a. Semigroup a => a -> a -> a
<> String
indexvarname String -> String -> String
forall a. Semigroup a => a -> a -> a
<> String
" = idx;"
, String -> CLine
CLine (String -> CLine) -> String -> CLine
forall a b. (a -> b) -> a -> b
$ String
"}"
]
, setupInput :: [CChunk]
setupInput = [CLine] -> [CChunk]
mkCChunk
[ String -> CLine
CLine (String -> CLine) -> String -> CLine
forall a b. (a -> b) -> a -> b
$ String
indexvarname String -> String -> String
forall a. Semigroup a => a -> a -> a
<> String
" = " String -> String -> String
forall a. Semigroup a => a -> a -> a
<> RangeIndex -> String
forall a. Show a => a -> String
show RangeIndex
startidx' String -> String -> String
forall a. Semigroup a => a -> a -> a
<> String
";" ]
, readInput :: [CChunk]
readInput = [CLine] -> [CChunk]
mkCChunk
[ String -> CLine
CLine (String -> CLine) -> String -> CLine
forall a b. (a -> b) -> a -> b
$ String
valname String -> String -> String
forall a. Semigroup a => a -> a -> a
<> String
" = EEPROM." String -> String -> String
forall a. Semigroup a => a -> a -> a
<> Proxy t -> String
forall t. EEPROMable t => Proxy t -> String
readValue Proxy t
proxy
String -> String -> String
forall a. Semigroup a => a -> a -> a
<> String
"("
String -> String -> String
forall a. Semigroup a => a -> a -> a
<> UniqueId -> String
eepromRangeStartAddrName UniqueId
i
String -> String -> String
forall a. Semigroup a => a -> a -> a
<> String
" + " String -> String -> String
forall a. Semigroup a => a -> a -> a
<> String
indexvarname
String -> String -> String
forall a. Semigroup a => a -> a -> a
<> String
"*sizeof("
String -> String -> String
forall a. Semigroup a => a -> a -> a
<> Proxy t -> String
forall {k} (t :: k). ShowCType t => Proxy t -> String
showCType Proxy t
proxy
String -> String -> String
forall a. Semigroup a => a -> a -> a
<> String
")"
String -> String -> String
forall a. Semigroup a => a -> a -> a
<> String
");"
]
, inputStream :: Behavior t
inputStream = String -> Maybe [t] -> Behavior t
forall a. Typed a => String -> Maybe [a] -> Stream a
extern String
valname Maybe [t]
interpretvalues'
, inputPinmode :: Map Arduino PinMode
inputPinmode = Map Arduino PinMode
forall a. Monoid a => a
mempty
}
where
Location UniqueId
i = Range t -> Location (Range t)
forall t. Range t -> Location (Range t)
rangeLocation Range t
range
idx' :: Stream RangeIndex
idx' = Stream RangeIndex
idx Stream RangeIndex -> Stream RangeIndex -> Stream RangeIndex
forall a. (Typed a, Integral a) => Stream a -> Stream a -> Stream a
`mod` RangeIndex -> Stream RangeIndex
forall a. Typed a => a -> Stream a
constant (Range t -> RangeIndex
forall t. Range t -> RangeIndex
rangeSize Range t
range)
startidx' :: RangeIndex
startidx' = RangeIndex
startidx RangeIndex -> RangeIndex -> RangeIndex
forall a. Integral a => a -> a -> a
`Prelude.mod` Range t -> RangeIndex
forall t. Range t -> RangeIndex
rangeSize Range t
range
proxy :: Proxy t
proxy = forall t. Proxy t
forall {k} (t :: k). Proxy t
Proxy @t
indexvarname :: String
indexvarname = String -> UniqueId -> String
uniqueName String
"eeprom_range_read_index" UniqueId
i
indexvarupdatername :: String
indexvarupdatername = String -> UniqueId -> String
uniqueName String
"eeprom_range_read" UniqueId
i
valname :: String
valname = String -> UniqueId -> String
uniqueName String
"eeprom_range_val" UniqueId
i
interpretvalues' :: Maybe [t]
interpretvalues'
| [t] -> Bool
forall a. [a] -> Bool
forall (t :: * -> *) a. Foldable t => t a -> Bool
null [t]
interpretvalues = Maybe [t]
forall a. Maybe a
Nothing
| Bool
otherwise = [t] -> Maybe [t]
forall a. a -> Maybe a
Just [t]
interpretvalues
class (ShowCType t, Typed t) => EEPROMable t where
readValue :: Proxy t -> String
writeValue :: Proxy t -> String
factoryValue :: Proxy t -> t
instance EEPROMable Bool where
readValue :: Proxy Bool -> String
readValue Proxy Bool
_ = String
"readByte"
writeValue :: Proxy Bool -> String
writeValue Proxy Bool
_ = String
"updateByte"
factoryValue :: Proxy Bool -> Bool
factoryValue Proxy Bool
_ = Bool
True
instance EEPROMable Int8 where
readValue :: Proxy Int8 -> String
readValue Proxy Int8
_ = String
"readByte"
writeValue :: Proxy Int8 -> String
writeValue Proxy Int8
_ = String
"updateByte"
factoryValue :: Proxy Int8 -> Int8
factoryValue Proxy Int8
_ = Int8
forall a. Bounded a => a
minBound
instance EEPROMable Int16 where
readValue :: Proxy Int16 -> String
readValue Proxy Int16
_ = String
"readInt"
writeValue :: Proxy Int16 -> String
writeValue Proxy Int16
_ = String
"updateInt"
factoryValue :: Proxy Int16 -> Int16
factoryValue Proxy Int16
_= Int16
forall a. Bounded a => a
minBound
instance EEPROMable Int32 where
readValue :: Proxy Int32 -> String
readValue Proxy Int32
_ = String
"readLong"
writeValue :: Proxy Int32 -> String
writeValue Proxy Int32
_ = String
"updateLong"
factoryValue :: Proxy Int32 -> Int32
factoryValue Proxy Int32
_= Int32
forall a. Bounded a => a
minBound
instance EEPROMable Word8 where
readValue :: Proxy Word8 -> String
readValue Proxy Word8
_ = String
"readByte"
writeValue :: Proxy Word8 -> String
writeValue Proxy Word8
_ = String
"updateByte"
factoryValue :: Proxy Word8 -> Word8
factoryValue Proxy Word8
_ = Word8
forall a. Bounded a => a
maxBound
instance EEPROMable Word16 where
readValue :: Proxy RangeIndex -> String
readValue Proxy RangeIndex
_ = String
"readInt"
writeValue :: Proxy RangeIndex -> String
writeValue Proxy RangeIndex
_ = String
"updateInt"
factoryValue :: Proxy RangeIndex -> RangeIndex
factoryValue Proxy RangeIndex
_ = RangeIndex
forall a. Bounded a => a
maxBound
instance EEPROMable Word32 where
readValue :: Proxy Word32 -> String
readValue Proxy Word32
_ = String
"readLong"
writeValue :: Proxy Word32 -> String
writeValue Proxy Word32
_ = String
"updateLong"
factoryValue :: Proxy Word32 -> Word32
factoryValue Proxy Word32
_ = Word32
forall a. Bounded a => a
maxBound
instance EEPROMable Float where
readValue :: Proxy Float -> String
readValue Proxy Float
_ = String
"readFloat"
writeValue :: Proxy Float -> String
writeValue Proxy Float
_ = String
"updateFloat"
factoryValue :: Proxy Float -> Float
factoryValue Proxy Float
_ = Float
0Float -> Float -> Float
forall a. Fractional a => a -> a -> a
/Float
0
instance EEPROMable Double where
readValue :: Proxy Double -> String
readValue Proxy Double
_ = String
"readDouble"
writeValue :: Proxy Double -> String
writeValue Proxy Double
_ = String
"updateDOuble"
factoryValue :: Proxy Double -> Double
factoryValue Proxy Double
_ = Double
0Double -> Double -> Double
forall a. Fractional a => a -> a -> a
/Double
0
includeCLine :: CLine
includeCLine :: CLine
includeCLine = String -> CLine
CLine String
"#include <EEPROMex.h>"