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
36 changes: 13 additions & 23 deletions .github/workflows/build-examples.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -10,32 +10,22 @@ on: ["push", "pull_request"]

jobs:
build_erlang_examples:
name: "Build Erlang Examples"
name: "Build Erlang/Elixir Examples"
runs-on: ubuntu-latest

strategy:
fail-fast: true

steps:

- uses: erlef/setup-beam@v1
with:
otp-version: "24"
elixir-version: "1.11"

- name: Checkout repo
uses: actions/checkout@v2

# - name: "APT update"
# run: sudo apt update -y

- name: "Build rebar3"
run: |
cd /tmp
git clone https://github.com/erlang/rebar3.git
cd rebar3
./bootstrap

- name: "Build Erlang Example Programs"
run: |
PATH=/tmp/rebar3:$PATH ./build.sh
- uses: erlef/setup-beam@v1
with:
otp-version: "26"
elixir-version: "1.18"
rebar3-version: "3.24.0"

- name: Checkout repo
uses: actions/checkout@v4

- name: "Build Erlang/Elixir Example Programs"
run: |
./build.sh
49 changes: 49 additions & 0 deletions .github/workflows/check-formatting.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
#
# Copyright 2022 Davide Bettio <davide@uninstall.it>
#
# SPDX-License-Identifier: Apache-2.0 OR LGPL-2.1-or-later
#

name: "Check formatting"

on:
push:
paths:
- ".github/workflows/**"
- "**/*.ex"
- "**/*.exs"
- "**/*.erl"
pull_request:
paths:
- ".github/workflows/**"
- "**/*.ex"
- "**/*.exs"
- "**/*.erl"

concurrency:
group: ${{ github.workflow }}-${{ github.ref != 'refs/heads/main' && github.ref || github.run_id }}
cancel-in-progress: true

jobs:
erlfmt-check:
runs-on: ubuntu-24.04
container: erlang:28
steps:
- uses: actions/checkout@v4
- name: "Check formatting with Erlang fmt"
run: |
cd ..
git clone --depth 1 -b v1.7.0 https://github.com/WhatsApp/erlfmt.git
cd erlfmt
rebar3 as release escriptize
cd ../atomvm_examples
find . -name *.erl | xargs ../erlfmt/_build/release/bin/erlfmt -c

mix-format-check:
runs-on: ubuntu-24.04
container: elixir:1.17.1
steps:
- uses: actions/checkout@v4
- name: "Check formatting with Elixir mix format"
run: |
mix format --check-formatted "**/*.{ex,exs}"
6 changes: 3 additions & 3 deletions .github/workflows/reuse-lint.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,6 @@ jobs:
test:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: REUSE Compliance Check
uses: fsfe/reuse-action@v1
- uses: actions/checkout@v4
- name: REUSE Compliance Check
uses: fsfe/reuse-action@v1
23 changes: 22 additions & 1 deletion build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,27 @@ for i in ${ERLANG_EXAMPLES}; do
cd $i
rm -rf _build
${REBAR} atomvm packbeam -l || exit 1
${REBAR} as check fmt -c || exit 1
cd ..
done
cd ..
cd elixir
ELIXIR_EXAMPLES="$(/bin/ls | grep -v README.md)"
for i in ${ELIXIR_EXAMPLES}; do
cd $i
rm -rf _build
mix deps.get && mix atomvm.packbeam || exit 1
cd ..
done
cd ..
cd demos
DEMO_EXAMPLES="$(/bin/ls | grep -v README.md)"
for i in ${DEMO_EXAMPLES}; do
cd $i
rm -rf _build
if [ -f mix.exs ]; then
mix deps.get && mix atomvm.packbeam || exit 1
else
${REBAR} atomvm packbeam -l || exit 1
fi
cd ..
done
2 changes: 1 addition & 1 deletion demos/lisp_faces/lib/main.ex
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ defmodule Main do
:gen_server.call(
t,
{:write,
:erlang.integer_to_list(:erlang.system_info(:process_count)) ++ ' running processes.\n'},
:erlang.integer_to_list(:erlang.system_info(:process_count)) ++ ~c" running processes.\n"},
60000
)

Expand Down
4 changes: 2 additions & 2 deletions demos/morse_server/src/morse_server.app.src
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@
{applications, [
kernel, stdlib
]},
{env,[]},
{env, []},
{modules, []},
{licenses, ["Apache 2.0"]},
{links, []}
]}.
]}.
55 changes: 29 additions & 26 deletions demos/morse_server/src/morse_server.erl
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ start() ->
Config = [
{sta, [
{ssid, esp:nvs_get_binary(atomvm, sta_ssid, <<"myssid">>)},
{psk, esp:nvs_get_binary(atomvm, sta_psk, <<"mypsk">>)},
{psk, esp:nvs_get_binary(atomvm, sta_psk, <<"mypsk">>)},
{connected, fun() -> Self ! connected end},
{got_ip, fun(IpInfo) -> Self ! {ok, IpInfo} end},
{disconnected, fun() -> Self ! disconnected end}
Expand All @@ -41,18 +41,20 @@ start() ->
end.

handle_req("GET", [], Conn) ->
Body = <<"<html>
<body>
<h1>Morse Encoder</h1>
<form method=\"post\">
<p>Text: <input type=\"text\" name=\"text\"></p>
<p>GPIO: <input type=\"text\" name=\"gpio\" value=\"2\"></p>
<input type=\"submit\" value=\"Submit\">
</form>
</body>
</html>">>,
Body =
<<
"<html>\n"
" <body>\n"
" <h1>Morse Encoder</h1>\n"
" <form method=\"post\">\n"
" <p>Text: <input type=\"text\" name=\"text\"></p>\n"
" <p>GPIO: <input type=\"text\" name=\"gpio\" value=\"2\"></p>\n"
" <input type=\"submit\" value=\"Submit\">\n"
" </form>\n"
" </body>\n"
" </html>"
>>,
http_server:reply(200, Body, Conn);

handle_req("POST", [], Conn) ->
ParamsBody = proplists:get_value(body_chunk, Conn),
Params = http_server:parse_query_string(ParamsBody),
Expand All @@ -65,14 +67,21 @@ handle_req("POST", [], Conn) ->

spawn(fun() -> blink_led(GPIONum, MorseText) end),

Body = [<<"<html>
<body>
<h1>Text Encoded</h1>">>,
<<"<p>">>, MorseText, <<"</p1>
</body>
</html>">>],
Body = [
<<
"<html>\n"
" <body>\n"
" <h1>Text Encoded</h1>"
>>,
<<"<p>">>,
MorseText,
<<
"</p1>\n"
" </body>\n"
" </html>"
>>
],
http_server:reply(200, Body, Conn);

handle_req(Method, Path, Conn) ->
erlang:display(Conn),
erlang:display({Method, Path}),
Expand Down Expand Up @@ -108,34 +117,29 @@ get_gpio() ->
undefined ->
GPIO = gpio:open(),
GPIO;

GPIO ->
GPIO
end.

blink_led(undefined, _L) ->
ok;

blink_led(GPIONum, L) ->
GPIO = get_gpio(),
gpio:set_direction(GPIO, GPIONum, output),
blink_led(GPIO, GPIONum, L).

blink_led(_GPIO, _GPIONum, []) ->
ok;

blink_led(GPIO, GPIONum, [H | T]) ->
case H of
$\s ->
gpio:set_level(GPIO, GPIONum, low),
timer:sleep(120);

$. ->
gpio:set_level(GPIO, GPIONum, high),
timer:sleep(120),
gpio:set_level(GPIO, GPIONum, low),
timer:sleep(120);

$- ->
gpio:set_level(GPIO, GPIONum, high),
timer:sleep(120 * 3),
Expand All @@ -149,7 +153,6 @@ morse_encode(L) ->

morse_encode([], Acc) ->
Acc;

morse_encode([H | L], Acc) ->
M = to_morse(string:to_upper(H)),
morse_encode(L, Acc ++ M).
Expand All @@ -167,7 +170,7 @@ to_morse(C) ->
$7 -> "--... ";
$8 -> "---.. ";
$9 -> "----. ";
$A -> ".-" ;
$A -> ".-";
$B -> "-... ";
$C -> "-.-. ";
$D -> "-.. ";
Expand Down
16 changes: 11 additions & 5 deletions elixir/Blinky/lib/Blinky.ex
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ defmodule Blinky do
end

defp loop(pin, level) do
:io.format('Setting pin ~p ~p~n', [pin, level])
:io.format(~c"Setting pin ~p ~p~n", [pin, level])
GPIO.digital_write(pin, level)
Process.sleep(1000)
loop(pin, toggle(level))
Expand All @@ -55,19 +55,25 @@ defmodule Blinky do

defp platform_gpio_setup() do
case :atomvm.platform() do
:esp32 -> GPIO.set_pin_mode(pin(), :output)
:stm32 -> GPIO.set_pin_mode(pin(), :output)
:esp32 ->
GPIO.set_pin_mode(pin(), :output)

:stm32 ->
GPIO.set_pin_mode(pin(), :output)

:pico ->
case @pin do
{:wl, 0} -> :ok
{:wl, 0} ->
:ok

pin ->
GPIO.init(pin)
GPIO.set_pin_mode(pin, :output)
end

unsupported ->
:io.format("Platform ~p is not supported.~n", [unsupported])
:erlang.exit({:error, {:unsupported_platform, unsupported}})
end
end

end
4 changes: 1 addition & 3 deletions elixir/HelloWorld/lib/HelloWorld.ex
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,7 @@
#

defmodule HelloWorld do

def start() do
:io.format('Hello World~n')
:io.format(~c"Hello World~n")
end

end
Loading