morse.c
Go to the documentation of this file.
00001 /*
00002         Aseba - an event-based framework for distributed robot control
00003         Copyright (C) 2007--2010:
00004                 Stephane Magnenat <stephane at magnenat dot net>
00005                 (http://stephane.magnenat.net)
00006                 and other contributors, see authors.txt for details
00007         
00008         This program is free software: you can redistribute it and/or modify
00009         it under the terms of the GNU Lesser General Public License as published
00010         by the Free Software Foundation, version 3 of the License.
00011         
00012         This program is distributed in the hope that it will be useful,
00013         but WITHOUT ANY WARRANTY; without even the implied warranty of
00014         MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00015         GNU Lesser General Public License for more details.
00016         
00017         You should have received a copy of the GNU Lesser General Public License
00018         along with this program. If not, see <http://www.gnu.org/licenses/>.
00019 */
00020 
00021 #include <gpio/gpio.h>
00022 #include <error/error.h>
00023 #include <types/types.h>
00024 #include <clock/clock.h>
00025 
00026 // One dot is 0.5 sec
00027 // One dash is 3 dots
00028 // a space between two letter is three dots
00029 // a space between two words is seven dots
00030 
00031 static void wait_dot(void) {
00032         int i;
00033         for(i = 0; i < 50; i++)
00034                 clock_delay_us(10000);
00035 }       
00036         
00037         
00038 static void wait_dash(void) {
00039         int i;
00040         for(i = 0; i < 3; i++)
00041                 wait_dot();
00042 }
00043 
00044 static void wait_morse_letter(void) {
00045         int i;
00046         for(i = 0; i < 3; i++)
00047                 wait_dot();
00048 }
00049 
00050 static void wait_morse_word(void) {
00051         int i;
00052         for(i = 0; i < 7; i++)
00053                 wait_dot();
00054 }
00055 
00056 static void morse_dash(gpio led, int on, int off) {
00057         gpio_write(led, on);
00058         wait_dash();
00059         gpio_write(led, off);
00060         wait_dot();
00061 }
00062 
00063 static void morse_dot(gpio led, int on, int off) {
00064         gpio_write(led, on);
00065         wait_dot();
00066         gpio_write(led, off);
00067         wait_dot();
00068 }
00069 
00070 static void morse_number(unsigned int disp, gpio led, int on, int off) {
00071         switch(disp) {
00072                 case 0:
00073                         morse_dash(led, on, off);
00074                         morse_dash(led, on, off);
00075                         morse_dash(led, on, off);
00076                         morse_dash(led, on, off);
00077                         morse_dash(led, on, off);
00078                         break;
00079                 case 1:
00080                         morse_dot(led, on, off);
00081                         morse_dash(led, on, off);
00082                         morse_dash(led, on, off);
00083                         morse_dash(led, on, off);
00084                         morse_dash(led, on, off);
00085                         break;
00086                 case 2:
00087                         morse_dot(led, on, off);
00088                         morse_dot(led, on, off);
00089                         morse_dash(led, on, off);
00090                         morse_dash(led, on, off);
00091                         morse_dash(led, on, off);
00092                         break;
00093                 case 3:
00094                         morse_dot(led, on, off);
00095                         morse_dot(led, on, off);
00096                         morse_dot(led, on, off);
00097                         morse_dash(led, on, off);
00098                         morse_dash(led, on, off);
00099                         break;
00100                 case 4:
00101                         morse_dot(led, on, off);
00102                         morse_dot(led, on, off);
00103                         morse_dot(led, on, off);
00104                         morse_dot(led, on, off);
00105                         morse_dash(led, on, off);
00106                         break;
00107                 case 5:
00108                         morse_dot(led, on, off);
00109                         morse_dot(led, on, off);
00110                         morse_dot(led, on, off);
00111                         morse_dot(led, on, off);
00112                         morse_dot(led, on, off);
00113                         break;
00114                 case 6:
00115                         morse_dash(led, on, off);
00116                         morse_dot(led, on, off);
00117                         morse_dot(led, on, off);
00118                         morse_dot(led, on, off);
00119                         morse_dot(led, on, off);
00120                         break;
00121                 case 7:
00122                         morse_dash(led, on, off);
00123                         morse_dash(led, on, off);
00124                         morse_dot(led, on, off);
00125                         morse_dot(led, on, off);
00126                         morse_dot(led, on, off);
00127                         break;
00128                 case 8:
00129                         morse_dash(led, on, off);
00130                         morse_dash(led, on, off);
00131                         morse_dash(led, on, off);
00132                         morse_dot(led, on, off);
00133                         morse_dot(led, on, off);
00134                         break;
00135                 case 9:
00136                         morse_dash(led, on, off);
00137                         morse_dash(led, on, off);
00138                         morse_dash(led, on, off);
00139                         morse_dash(led, on, off);
00140                         morse_dot(led, on, off);
00141                         break;
00142                 case 0xa:
00143                         morse_dot(led, on, off);
00144                         morse_dash(led, on, off);
00145                         break;
00146                 case 0xb:
00147                         morse_dash(led, on, off);
00148                         morse_dot(led, on, off);
00149                         morse_dot(led, on, off);
00150                         morse_dot(led, on, off);
00151                         break;
00152                 case 0xc:
00153                         morse_dash(led, on, off);
00154                         morse_dot(led, on, off);
00155                         morse_dash(led, on, off);
00156                         morse_dot(led, on, off);
00157                         break;
00158                 case 0xd:
00159                         morse_dash(led, on, off);
00160                         morse_dot(led, on, off);
00161                         morse_dot(led, on, off);
00162                         break;
00163                 case 0xe:
00164                         morse_dot(led, on, off);
00165                         break;
00166                 case 0xf:
00167                         morse_dot(led, on, off);
00168                         morse_dot(led, on, off);
00169                         morse_dash(led, on, off);
00170                         morse_dot(led, on, off);
00171                         break;
00172         }
00173 }
00174 
00175 void output_error(unsigned int value, gpio led, int on, int off) {
00176         int shift;
00177         bool hasSent = false;
00178         for (shift = 12; shift >= 0; shift -= 4)
00179         {
00180                 unsigned disp = ((value & (0xF << shift)) >> shift);
00181 
00182                 if ((disp != 0) || (hasSent) || (shift == 0))
00183                 {
00184                         hasSent = true;
00185                         morse_number(disp, led, on, off);
00186                         wait_morse_letter();
00187                 }
00188         }
00189         wait_morse_word();
00190 }
00191 


aseba
Author(s): Stéphane Magnenat
autogenerated on Sun Oct 5 2014 23:46:38