{"id":20,"date":"2012-10-14T22:55:00","date_gmt":"2012-10-14T22:55:00","guid":{"rendered":""},"modified":"2021-07-18T19:40:05","modified_gmt":"2021-07-18T19:40:05","slug":"since-i-moved-to-south-florida-ive","status":"publish","type":"post","link":"http:\/\/cockfieldofdreams.com\/blog\/2012\/10\/since-i-moved-to-south-florida-ive.html","title":{"rendered":"Listen to the Radio from ANYWHERE"},"content":{"rendered":"<p>Since I moved to South Florida I&#8217;ve noticed that there aren&#8217;t any appropriate radio stations anywhere down here. They&#8217;re all mindless Clear Channel-type Top 40 or country stations. Unacceptable. There weren&#8217;t this many country stations when I lived in South Carolina or Tennessee. Anyway! I thought maybe I could build a radio that would get radio stations from far away, and it would let me listen to independently-owned and happily non-country stations&nbsp;<a href=\"http:\/\/1055thebridge.com\/\" target=\"_blank\" rel=\"noopener\">105.5 The Bridge<\/a> from Charleston and <a href=\"http:\/\/lightning100.com\/\" target=\"_blank\" rel=\"noopener\">Lightning 100<\/a> from Nashville.<\/p>\n<p>My idea was to interface a&nbsp;<a href=\"http:\/\/en.wikipedia.org\/wiki\/Parallel_port\" target=\"_blank\" rel=\"noopener\">parallel port<\/a>&nbsp;port in a computer to a set of buttons. Each button would launch Firefox which would then load the online stream of one of these stations. The computer controlling it would be headless and hidden, so the visible hardware would look and perform just like a regular radio. The only downside to this is that I can&#8217;t get <a href=\"http:\/\/www.957theride.com\/home.asp\" target=\"_blank\" rel=\"noopener\">95.7 The Ride<\/a> out of Charlotte with this build because they don&#8217;t have an online stream anymore.<\/p>\n<p>At boot, the computer executes a script that starts a C program called &#8220;launcher&#8221;. The C program is necessary to take control of the printer port, and therefore it must be run as root. To allow the computer to execute the script as root, I added the following line to the sudoer&#8217;s file with the command &#8220;sudo visudo&#8221;:<\/p>\n<pre style=\"background-color: #eeeeee; border-left-color: rgb(204, 204, 204); border-left-style: solid; border-width: 0px 0px 0px 5px; font-family: Consolas, Menlo, Monaco, 'Lucida Console', 'Liberation Mono', 'DejaVu Sans Mono', 'Bitstream Vera Sans Mono', 'Courier New', monospace, serif; font-size: 14px; line-height: 18px; margin-bottom: 10px; max-height: 600px; overflow: auto; padding: 5px 5px 5px 10px; vertical-align: baseline; width: auto; word-wrap: normal;\">ALL    ALL = (root) NOPASSWD: \/home\/bryan\/programs\/radio\/launcher<\/pre>\n<p>The script is very simple:<\/p>\n<pre style=\"background-color: #eeeeee; border-left-color: rgb(204, 204, 204); border-left-style: solid; border-width: 0px 0px 0px 5px; margin-bottom: 10px; max-height: 600px; overflow: auto; padding: 5px 5px 5px 10px; vertical-align: baseline; width: auto; word-wrap: normal;\"><span style=\"font-family: Consolas, Menlo, Monaco, Lucida Console, Liberation Mono, DejaVu Sans Mono, Bitstream Vera Sans Mono, Courier New, monospace, serif;\"><span style=\"font-size: 14px; line-height: 18px;\">#!\/bin\/bash<br \/>sudo \/home\/bryan\/programs\/radio\/launcher<\/span><\/span><\/pre>\n<p>I also ran &#8220;chmod 755 startup.sh&#8221; on the script to make it executable. Next is the C program that will actually handle the parallel port and launch the browser when a button press is detected:<\/p>\n<pre style=\"background-color: #eeeeee; border-left-color: rgb(204, 204, 204); border-left-style: solid; border-width: 0px 0px 0px 5px; margin-bottom: 10px; max-height: 600px; overflow: auto; padding: 5px 5px 5px 10px; vertical-align: baseline; width: auto; word-wrap: normal;\"><span style=\"font-family: Consolas, Menlo, Monaco, Lucida Console, Liberation Mono, DejaVu Sans Mono, Bitstream Vera Sans Mono, Courier New, monospace, serif;\"><span style=\"font-size: 14px; line-height: 18px;\">#include &lt;stdio.h&gt;<br \/>#include &lt;stdlib.h&gt;<br \/>#include &lt;unistd.h&gt;<br \/>#include &lt;sys\/io.h&gt;<br \/>#include &lt;time.h&gt;<br \/><br \/>#define base 0x378 \/\/ printer port base address<br \/>#define status 0x379 \/\/printer port status register<br \/><br \/>\/\/Define button push events. Status register default 0x78 = 0b01111000. <br \/>#define PUSH1 0x70 \/\/0x70 = 0b01110000<br \/>#define PUSH2 0x68 \/\/0x68 = 0b01101000<br \/><br \/>int A=1;<br \/>int lastA=0;<br \/>int B=1;<br \/>int lastB=0;<br \/>int regval=0;<br \/>int lastregval=1;<br \/><br \/>int main(int argc, char **argv) {<br \/>  \/\/make sure the program has access to the parallel port<br \/>  if (ioperm(base,1,1))<br \/>   fprintf(stderr, \"Couldn't get the port at %xn\", base), exit(1);<br \/>  if (ioperm(status,1,1))<br \/>   fprintf(stderr, \"Couldn't get the port at %xn\", status), exit(1);<br \/><br \/>  \/\/write 0b00000001 to the output lines to get +5V for the switches<br \/>  outb(1, base);<br \/><br \/>  while(1) { \/\/run forever<br \/>  \/\/print status register if and only if it changes<br \/>\/*    regval=inb(status);<br \/>    if(regval != lastregval) {<br \/>      printf(\"%xn\",regval);<br \/>      lastregval=regval;<br \/>    } *\/<br \/><br \/>    if (inb(status)==PUSH1 &amp;&amp; A!=lastA) {<br \/>      \/\/enable other button pushes<br \/>      B++;<br \/>\/\/      printf(\"button 1 pushed!n\");<br \/>      \/\/call script<br \/>      system(\"\/bin\/bash \/home\/bryan\/programs\/radio\/script1.sh\");<br \/>      \/\/disable a second button 1 push event to debounce and to<br \/>      \/\/prevent closing of browser and opening the same page it was on<br \/>      A=lastA; <br \/>    }<br \/><br \/>    if (inb(status)==PUSH2 &amp;&amp; B!=lastB) {<br \/>      \/\/enable other button pushes<br \/>      A++;<br \/>\/\/      printf(\"button 2 pushed!n\");<br \/>      system(\"\/bin\/bash \/home\/bryan\/programs\/radio\/script2.sh\");<br \/>      \/\/disable a second button 2 push event to debounce and to<br \/>      \/\/prevent closing of browser and opening the same page it was on<br \/>      B=lastB;<br \/>    }<br \/>  }<br \/>}<\/span><\/span><\/pre>\n<p>No problem. I complied it using &#8220;gcc -O launcher.c -o launcher&#8221;. Compiling with these options is necessary for proper functionality of the parallel port.<\/p>\n<p>This program only handles two stations now but it could be expanded for more if 95.7 WXRC ever decided to have an online stream again.&nbsp;I believe the next step is to program this on my Raspberry Pi when it gets here, and install it in the radio that I have that has been the subject of <a href=\"http:\/\/cockfieldofdreams.com\/blog\/2011\/05\/27\/5-radio-returns\/\" target=\"_blank\" rel=\"noopener\">previous posts<\/a> on this blog. I think I could rewire the memory buttons on the radio to be inputs to the Pi and have the radio display &#8220;105.5&#8221; or &#8220;100.1&#8221; on its LCD. This has some potential! If anyone has some tips on how I can be a better programmer, I am open to those suggestions. I&#8217;m an engineer, not a computer scientist.<\/p>\n<p><iframe loading=\"lazy\" allowfullscreen=\"allowfullscreen\" frameborder=\"0\" height=\"315\" src=\"http:\/\/www.youtube.com\/embed\/Gdgrby_14XM\" width=\"420\"><\/iframe> <\/p>\n<div><\/div>\n","protected":false},"excerpt":{"rendered":"<p>Since I moved to South Florida I&#8217;ve noticed that there aren&#8217;t any appropriate radio stations anywhere down here. They&#8217;re all mindless Clear Channel-type Top 40 or country stations. Unacceptable. There weren&#8217;t this many country stations when I lived in South Carolina or Tennessee. Anyway! I thought maybe I could build a radio that would get &hellip; <\/p>\n<p class=\"link-more\"><a href=\"http:\/\/cockfieldofdreams.com\/blog\/2012\/10\/since-i-moved-to-south-florida-ive.html\" class=\"more-link\">Continue reading<span class=\"screen-reader-text\"> &#8220;Listen to the Radio from ANYWHERE&#8221;<\/span><\/a><\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[1],"tags":[],"_links":{"self":[{"href":"http:\/\/cockfieldofdreams.com\/blog\/wp-json\/wp\/v2\/posts\/20"}],"collection":[{"href":"http:\/\/cockfieldofdreams.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/cockfieldofdreams.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/cockfieldofdreams.com\/blog\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"http:\/\/cockfieldofdreams.com\/blog\/wp-json\/wp\/v2\/comments?post=20"}],"version-history":[{"count":1,"href":"http:\/\/cockfieldofdreams.com\/blog\/wp-json\/wp\/v2\/posts\/20\/revisions"}],"predecessor-version":[{"id":208,"href":"http:\/\/cockfieldofdreams.com\/blog\/wp-json\/wp\/v2\/posts\/20\/revisions\/208"}],"wp:attachment":[{"href":"http:\/\/cockfieldofdreams.com\/blog\/wp-json\/wp\/v2\/media?parent=20"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/cockfieldofdreams.com\/blog\/wp-json\/wp\/v2\/categories?post=20"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/cockfieldofdreams.com\/blog\/wp-json\/wp\/v2\/tags?post=20"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}