Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions haskell-arduino-p05-mood-cue/.ghcid
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
-c "stack ghci haskell-arduino-p05-mood-cue:lib"
4 changes: 4 additions & 0 deletions haskell-arduino-p05-mood-cue/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
.stack-work/
*~
*.ino
*.cabal
3 changes: 3 additions & 0 deletions haskell-arduino-p05-mood-cue/ChangeLog.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# Changelog for haskell-arduino-p05-mood-cue

## Unreleased changes
30 changes: 30 additions & 0 deletions haskell-arduino-p05-mood-cue/LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
Copyright Author name here (c) 2020

All rights reserved.

Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:

* Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.

* Redistributions in binary form must reproduce the above
copyright notice, this list of conditions and the following
disclaimer in the documentation and/or other materials provided
with the distribution.

* Neither the name of Author name here nor the names of other
contributors may be used to endorse or promote products derived
from this software without specific prior written permission.

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
1 change: 1 addition & 0 deletions haskell-arduino-p05-mood-cue/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
# haskell-arduino-p05-mood-cue
2 changes: 2 additions & 0 deletions haskell-arduino-p05-mood-cue/Setup.hs
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
import Distribution.Simple
main = defaultMain
6 changes: 6 additions & 0 deletions haskell-arduino-p05-mood-cue/app/Main.hs
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
module Main where

import Lib

main :: IO ()
main = someFunc
52 changes: 52 additions & 0 deletions haskell-arduino-p05-mood-cue/package.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
name: haskell-arduino-p05-mood-cue
version: 0.1.0.0
github: "githubuser/haskell-arduino-p05-mood-cue"
license: BSD3
author: "Author name here"
maintainer: "example@example.com"
copyright: "2020 Author name here"

extra-source-files:
- README.md
- ChangeLog.md

# Metadata used when publishing your package
# synopsis: Short description of your package
# category: Web

# To avoid duplicated efforts in documentation and dealing with the
# complications of embedding Haddock markup inside cabal files, it is
# common to point users to the README.md file.
description: Please see the README on GitHub at <https://github.com/githubuser/haskell-arduino-p05-mood-cue#readme>

dependencies:
- base >= 4.7 && < 5
- arduino-copilot
- mtl

library:
source-dirs: src
default-extensions:
- RebindableSyntax

executables:
haskell-arduino-p05-mood-cue-exe:
main: Main.hs
source-dirs: app
ghc-options:
- -threaded
- -rtsopts
- -with-rtsopts=-N
dependencies:
- haskell-arduino-p05-mood-cue

tests:
haskell-arduino-p05-mood-cue-test:
main: Spec.hs
source-dirs: test
ghc-options:
- -threaded
- -rtsopts
- -with-rtsopts=-N
dependencies:
- haskell-arduino-p05-mood-cue
27 changes: 27 additions & 0 deletions haskell-arduino-p05-mood-cue/src/Lib.hs
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
module Lib
( someFunc
) where

import Copilot.Arduino.Uno
import Servo
import qualified Copilot.Arduino.Library.Serial as Serial

someFunc :: IO ()
someFunc = arduino $ do
potVal <- cast <$> (input a0 :: Sketch (Behavior ADC)) :: Sketch (Behavior Int32)

Serial.baud 9600
Serial.device =: [ Serial.str "potVal: "
, Serial.show potVal
]
-- TODO: Figure out why do I need to map this again to values that are close to 60 and 245?
let angle = Servo.intTransform' 0 1023 60 245 potVal

Serial.device =: [ Serial.str "angle: "
, Serial.show angle
, Serial.char '\n'
]

pin9 =: pwm' angle
delay =: MilliSeconds (constant 15)

41 changes: 41 additions & 0 deletions haskell-arduino-p05-mood-cue/src/Servo.hs
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
{-# LANGUAGE DataKinds #-}
{-# LANGUAGE FlexibleInstances #-}
{-# LANGUAGE MultiParamTypeClasses #-}
{-# LANGUAGE UndecidableInstances #-}

module Servo where

import Data.Function (const)
import Control.Monad.Writer (MonadWriter(tell))
import Copilot.Arduino.Internals
import Copilot.Arduino.Uno


transform' :: Fractional a => a -> a -> a -> a -> a -> a
transform' lmin lmax rmin rmax value =
(((value - lmin) * (rmax - rmin)) / (lmax - lmin)) + rmin

transform :: Fractional a => a -> a
transform = transform' 0 1023 0 179

intTransform :: (Typed a, Integral a) => Stream a -> Stream a
-- intTransform = intTransform' 0 1023 54 250
intTransform = intTransform' 0 1023 0 179

intTransform' :: (Typed a, Integral a) => Stream a -> Stream a -> Stream a -> Stream a -> Stream a -> Stream a
intTransform' lmin lmax rmin rmax value =
(((value - lmin) * (rmax - rmin)) `div` (lmax - lmin)) + rmin


-- The library only defines pwm for Word8, so we did some hacking here to allow floats.
pwm' :: Behavior a -> TypedBehavior 'PWM a
pwm' = TypedBehavior

instance (IsPWMPin t) => Output (Pin t) (Event 'PWM (Stream Int32)) where
(Pin (PinId n)) =: (Event v c) = do
(f, triggername) <- defineTriggerAlias' ("pin_" <> show n) "analogWrite" mempty
tell [(go triggername, const f)]
where
go triggername tl =
let c' = addTriggerLimit tl c
in trigger triggername c' [arg (constant n), arg v]
77 changes: 77 additions & 0 deletions haskell-arduino-p05-mood-cue/stack.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
# This file was automatically generated by 'stack init'
#
# Some commonly used options have been documented as comments in this file.
# For advanced use and comprehensive documentation of the format, please see:
# https://docs.haskellstack.org/en/stable/yaml_configuration/

# Resolver to choose a 'specific' stackage snapshot or a compiler version.
# A snapshot resolver dictates the compiler version and the set of packages
# to be used for project dependencies. For example:
#
# resolver: lts-3.5
# resolver: nightly-2015-09-21
# resolver: ghc-7.10.2
#
# The location of a snapshot can be provided as a file or url. Stack assumes
# a snapshot provided as a file might change, whereas a url resource does not.
#
# resolver: ./custom-snapshot.yaml
# resolver: https://example.com/snapshots/2018-01-01.yaml
resolver: lts-14.27

# User packages to be built.
# Various formats can be used as shown in the example below.
#
# packages:
# - some-directory
# - https://example.com/foo/bar/baz-0.0.2.tar.gz
# subdirs:
# - auto-update
# - wai
packages:
- .
# Dependency packages to be pulled from upstream that are not in the resolver.
# These entries can reference officially published versions as well as
# forks / in-progress versions pinned to a git hash. For example:
#
extra-deps:
- arduino-copilot-1.5.1@sha256:338b23c6c016b2f8a8e79d5d16151ec1369e10c40dd9b09ae3fdb903d5ba5881,2802
- copilot-3.1@sha256:966318c27ea4e2877ffba45f455be9310426b3e4b2c8fa8041d51e451879cc2b,4001
- copilot-c99-3.1.2@sha256:8603972c549131c48294fc2b1808f599e829e7b324048d8f6ac9994fce840364,2348
- copilot-language-3.1@sha256:3ec5d98e2579e692930a47d77c30070906523f9cf9028728812633734ff9c80e,2942
- copilot-core-3.1@sha256:3c435b7edd14de8995cc9a987ebff648eb2b2ef92c2fefe748b94b9bcca6dc48,2003
- copilot-libraries-3.1@sha256:cb6597c4bc556b9e153baa3006989676c489a756f514b73666062c8a485fa672,1977
- copilot-theorem-3.1@sha256:846e58c9f4a28a5224d994aa01a74d273161852c13a42b09b9ce7ce91fe93205,4263
- language-c99-0.1.2@sha256:6c9022378c7ed57d080fe41442066a5f2657347fd02a07ad291bbf41d71ab954,1587
- language-c99-simple-0.1.2@sha256:5b522616fa22a0909250d56a0632f1f1cae1c38d585149e13eeb809103af9543,1540
- language-c99-util-0.1.1@sha256:480adee2ba3045d04305be5362be991b1814faf58cfd7af1f845d0fc9dbcf3a7,1177
- bimap-0.3.3@sha256:232518c0410990665b9c8677eb9318ee355c001d58945ddcbedec3baa30b4160,1475
# - acme-missiles-0.3
# - git: https://github.com/commercialhaskell/stack.git
# commit: e7b331f14bcffb8367cd58fbfc8b40ec7642100a
#
# extra-deps: []

# Override default flag values for local packages and extra-deps
# flags: {}

# Extra package databases containing global packages
# extra-package-dbs: []

# Control whether we use the GHC we find on the path
# system-ghc: true
#
# Require a specific version of stack, using version ranges
# require-stack-version: -any # Default
# require-stack-version: ">=2.3"
#
# Override the architecture used by stack, especially useful on Windows
# arch: i386
# arch: x86_64
#
# Extra directories used by stack for building
# extra-include-dirs: [/path/to/dir]
# extra-lib-dirs: [/path/to/dir]
#
# Allow a newer minor version of GHC than the snapshot specifies
# compiler-check: newer-minor
89 changes: 89 additions & 0 deletions haskell-arduino-p05-mood-cue/stack.yaml.lock
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
# This file was autogenerated by Stack.
# You should not edit this file by hand.
# For more information, please see the documentation at:
# https://docs.haskellstack.org/en/stable/lock_files

packages:
- completed:
hackage: arduino-copilot-1.5.1@sha256:338b23c6c016b2f8a8e79d5d16151ec1369e10c40dd9b09ae3fdb903d5ba5881,2802
pantry-tree:
size: 2946
sha256: 7155a293006ef384ca5f85965594b595956b36f20f7f231df562568f9ec67d4e
original:
hackage: arduino-copilot-1.5.1@sha256:338b23c6c016b2f8a8e79d5d16151ec1369e10c40dd9b09ae3fdb903d5ba5881,2802
- completed:
hackage: copilot-3.1@sha256:966318c27ea4e2877ffba45f455be9310426b3e4b2c8fa8041d51e451879cc2b,4001
pantry-tree:
size: 847
sha256: 02784c5d047085da3176e68f34f40f18d770511f039e7c33d8fc9bcf41f5a597
original:
hackage: copilot-3.1@sha256:966318c27ea4e2877ffba45f455be9310426b3e4b2c8fa8041d51e451879cc2b,4001
- completed:
hackage: copilot-c99-3.1.2@sha256:8603972c549131c48294fc2b1808f599e829e7b324048d8f6ac9994fce840364,2348
pantry-tree:
size: 692
sha256: d4f07c09596979c9be45283d0df03139dfb5dbbc9f61c03a1333711d2e05fe29
original:
hackage: copilot-c99-3.1.2@sha256:8603972c549131c48294fc2b1808f599e829e7b324048d8f6ac9994fce840364,2348
- completed:
hackage: copilot-language-3.1@sha256:3ec5d98e2579e692930a47d77c30070906523f9cf9028728812633734ff9c80e,2942
pantry-tree:
size: 2229
sha256: 08d9b5cc844624a977aa884c8d75390c1edc57ee0f7e5d8b514e78456446e491
original:
hackage: copilot-language-3.1@sha256:3ec5d98e2579e692930a47d77c30070906523f9cf9028728812633734ff9c80e,2942
- completed:
hackage: copilot-core-3.1@sha256:3c435b7edd14de8995cc9a987ebff648eb2b2ef92c2fefe748b94b9bcca6dc48,2003
pantry-tree:
size: 1668
sha256: db6ce9f6fc3c3472b1d3bfa007b3c9f28f80b5817efa7ba346d671975a4e9b03
original:
hackage: copilot-core-3.1@sha256:3c435b7edd14de8995cc9a987ebff648eb2b2ef92c2fefe748b94b9bcca6dc48,2003
- completed:
hackage: copilot-libraries-3.1@sha256:cb6597c4bc556b9e153baa3006989676c489a756f514b73666062c8a485fa672,1977
pantry-tree:
size: 956
sha256: 81f759cca2af5249f76e11d79024aa775b51ebc140963762078ea5ef81d07893
original:
hackage: copilot-libraries-3.1@sha256:cb6597c4bc556b9e153baa3006989676c489a756f514b73666062c8a485fa672,1977
- completed:
hackage: copilot-theorem-3.1@sha256:846e58c9f4a28a5224d994aa01a74d273161852c13a42b09b9ce7ce91fe93205,4263
pantry-tree:
size: 2672
sha256: 6a4dd0389484b413c9e3daa840b02cfd64d50df5148175626da03028eaa0fdb9
original:
hackage: copilot-theorem-3.1@sha256:846e58c9f4a28a5224d994aa01a74d273161852c13a42b09b9ce7ce91fe93205,4263
- completed:
hackage: language-c99-0.1.2@sha256:6c9022378c7ed57d080fe41442066a5f2657347fd02a07ad291bbf41d71ab954,1587
pantry-tree:
size: 399
sha256: 53d202a7489f2501c633e5c1f4d6a63deed004df1bec36d3ce29d54388c4a619
original:
hackage: language-c99-0.1.2@sha256:6c9022378c7ed57d080fe41442066a5f2657347fd02a07ad291bbf41d71ab954,1587
- completed:
hackage: language-c99-simple-0.1.2@sha256:5b522616fa22a0909250d56a0632f1f1cae1c38d585149e13eeb809103af9543,1540
pantry-tree:
size: 574
sha256: 1d297b46c78e2a498f7828bddc794d8355656273f7334f8ab27452ccfd28d5be
original:
hackage: language-c99-simple-0.1.2@sha256:5b522616fa22a0909250d56a0632f1f1cae1c38d585149e13eeb809103af9543,1540
- completed:
hackage: language-c99-util-0.1.1@sha256:480adee2ba3045d04305be5362be991b1814faf58cfd7af1f845d0fc9dbcf3a7,1177
pantry-tree:
size: 489
sha256: 3a5e1387e9b073dad4f51fa749fd4c33e2abe31566b63a120a38a7f88d809493
original:
hackage: language-c99-util-0.1.1@sha256:480adee2ba3045d04305be5362be991b1814faf58cfd7af1f845d0fc9dbcf3a7,1177
- completed:
hackage: bimap-0.3.3@sha256:232518c0410990665b9c8677eb9318ee355c001d58945ddcbedec3baa30b4160,1475
pantry-tree:
size: 414
sha256: 5c7485014c2f342d215ace99cd06361f7607169aebe8d4aca2f265fa5c3c6761
original:
hackage: bimap-0.3.3@sha256:232518c0410990665b9c8677eb9318ee355c001d58945ddcbedec3baa30b4160,1475
snapshots:
- completed:
size: 524996
url: https://raw.githubusercontent.com/commercialhaskell/stackage-snapshots/master/lts/14/27.yaml
sha256: 7ea31a280c56bf36ff591a7397cc384d0dff622e7f9e4225b47d8980f019a0f0
original: lts-14.27
2 changes: 2 additions & 0 deletions haskell-arduino-p05-mood-cue/test/Spec.hs
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
main :: IO ()
main = putStrLn "Test suite not yet implemented"