@@ -27,7 +27,7 @@ start() ->
2727 Config = [
2828 {sta , [
2929 {ssid , esp :nvs_get_binary (atomvm , sta_ssid , <<" myssid" >>)},
30- {psk , esp :nvs_get_binary (atomvm , sta_psk , <<" mypsk" >>)},
30+ {psk , esp :nvs_get_binary (atomvm , sta_psk , <<" mypsk" >>)},
3131 {connected , fun () -> Self ! connected end },
3232 {got_ip , fun (IpInfo ) -> Self ! {ok , IpInfo } end },
3333 {disconnected , fun () -> Self ! disconnected end }
@@ -41,18 +41,20 @@ start() ->
4141 end .
4242
4343handle_req (" GET" , [], Conn ) ->
44- Body = <<" <html>
45- <body>
46- <h1>Morse Encoder</h1>
47- <form method=\" post\" >
48- <p>Text: <input type=\" text\" name=\" text\" ></p>
49- <p>GPIO: <input type=\" text\" name=\" gpio\" value=\" 2\" ></p>
50- <input type=\" submit\" value=\" Submit\" >
51- </form>
52- </body>
53- </html>" >>,
44+ Body =
45+ <<
46+ " <html>\n "
47+ " <body>\n "
48+ " <h1>Morse Encoder</h1>\n "
49+ " <form method=\" post\" >\n "
50+ " <p>Text: <input type=\" text\" name=\" text\" ></p>\n "
51+ " <p>GPIO: <input type=\" text\" name=\" gpio\" value=\" 2\" ></p>\n "
52+ " <input type=\" submit\" value=\" Submit\" >\n "
53+ " </form>\n "
54+ " </body>\n "
55+ " </html>"
56+ >>,
5457 http_server :reply (200 , Body , Conn );
55-
5658handle_req (" POST" , [], Conn ) ->
5759 ParamsBody = proplists :get_value (body_chunk , Conn ),
5860 Params = http_server :parse_query_string (ParamsBody ),
@@ -65,14 +67,21 @@ handle_req("POST", [], Conn) ->
6567
6668 spawn (fun () -> blink_led (GPIONum , MorseText ) end ),
6769
68- Body = [<<" <html>
69- <body>
70- <h1>Text Encoded</h1>" >>,
71- <<" <p>" >>, MorseText , <<" </p1>
72- </body>
73- </html>" >>],
70+ Body = [
71+ <<
72+ " <html>\n "
73+ " <body>\n "
74+ " <h1>Text Encoded</h1>"
75+ >>,
76+ <<" <p>" >>,
77+ MorseText ,
78+ <<
79+ " </p1>\n "
80+ " </body>\n "
81+ " </html>"
82+ >>
83+ ],
7484 http_server :reply (200 , Body , Conn );
75-
7685handle_req (Method , Path , Conn ) ->
7786 erlang :display (Conn ),
7887 erlang :display ({Method , Path }),
@@ -108,34 +117,29 @@ get_gpio() ->
108117 undefined ->
109118 GPIO = gpio :open (),
110119 GPIO ;
111-
112120 GPIO ->
113121 GPIO
114122 end .
115123
116124blink_led (undefined , _L ) ->
117125 ok ;
118-
119126blink_led (GPIONum , L ) ->
120127 GPIO = get_gpio (),
121128 gpio :set_direction (GPIO , GPIONum , output ),
122129 blink_led (GPIO , GPIONum , L ).
123130
124131blink_led (_GPIO , _GPIONum , []) ->
125132 ok ;
126-
127133blink_led (GPIO , GPIONum , [H | T ]) ->
128134 case H of
129135 $\s ->
130136 gpio :set_level (GPIO , GPIONum , low ),
131137 timer :sleep (120 );
132-
133138 $. ->
134139 gpio :set_level (GPIO , GPIONum , high ),
135140 timer :sleep (120 ),
136141 gpio :set_level (GPIO , GPIONum , low ),
137142 timer :sleep (120 );
138-
139143 $- ->
140144 gpio :set_level (GPIO , GPIONum , high ),
141145 timer :sleep (120 * 3 ),
@@ -149,7 +153,6 @@ morse_encode(L) ->
149153
150154morse_encode ([], Acc ) ->
151155 Acc ;
152-
153156morse_encode ([H | L ], Acc ) ->
154157 M = to_morse (string :to_upper (H )),
155158 morse_encode (L , Acc ++ M ).
@@ -167,7 +170,7 @@ to_morse(C) ->
167170 $7 -> " --... " ;
168171 $8 -> " ---.. " ;
169172 $9 -> " ----. " ;
170- $A -> " .-" ;
173+ $A -> " .-" ;
171174 $B -> " -... " ;
172175 $C -> " -.-. " ;
173176 $D -> " -.. " ;
0 commit comments