//--------------------------------------------------------------------------------// //- Hemisson Serial Remote -// //- -// //- Copyright (C) Alexandre Colot, K-Team S.A. 2003 -// //- This library is free software; you can redistribute it and/or -// //- modify it under the terms of the GNU Lesser General Public -// //- License as published by the Free Software Foundation; either -// //- version 2.1 of the License, or any later version. -// //- -// //- This library is distributed in the hope that it will be useful, -// //- but WITHOUT ANY WARRANTY; without even the implied warranty of -// //- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -// //- Lesser General Public License for more details. -// //- -// //- You should have received a copy of the GNU Lesser General Public -// //- License along with this library; if not, write to the Free Software -// //- Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA -// //- -// //- -// //- __ __ ________ -// //- K-Team S.A. | |/ /|__ __|___ _____ ___ ___ -// //- Chemin de Vuasset, CP 111 | / __ | | _____|/ _ \| \/ | -// //- 1028 Preverenges | | \ | | ____|/ /_\ | | -// //- Switzerland |__|\__\ |__|______|_/ \_|__|\/|__| -// //- alexandre.colot@k-team.com tel:+41 21 802 5472 fax:+41 21 802 5471 -// //- -// //--------------------------------------------------------------------------------// help {@ @} //=============================================================================================== // Variables //=============================================================================================== variable beep variable front variable left variable right variable rear variable stop variable speed variable brightness variable proximity variable interruptor variable leds variable osversion variable tvremote variable start variable fd variable comport variable com //================================================================================================================ // Déclaration des fonctions //================================================================================================================ init (fd,beep,front,left,right,rear,stop,brightness,proximity,interruptor,leds,osversion,start,comport,com,tvremote) = Init figure "Proximity" draw drawProximity(proximity) figure "Brightness" draw drawBrightness(brightness) figure "Interruptor" draw drawInterrutpor(interruptor) figure "ComPort" draw drawComPort(comport,com,start) mousedrag (start,comport,com) = dragComPort(start,comport,com,_id,_x1) figure "Controls" draw drawControls(beep,start,leds,proximity,osversion,com,tvremote) mousedrag (beep,leds) = dragControls(fd,beep,_id, _x1,leds,start,comport,com) figure "Comments" draw drawComments() idle (brightness,proximity,_idlerate,interruptor,osversion) = Refresh(fd,brightness,proximity,interruptor,osversion,start,comport) //=================================================================================================== // Blocs des fonctions //=================================================================================================== functions {@ function (fd,beep,front,left,right,rear,stop,brightness,proximity,interruptor,leds,osversion,start,comport,com,tvremote) = Init fd = 0; beep = 0; front = 0; right = 0; rear = 0; stop = 0; left = 0; brightness = [0,0,0,0,0,0,0,0]; proximity = [0,0,0,0,0,0,0,0]; interruptor = [0,0,0,0]; leds = [0;0;0;0]; osversion = '????'; start = 0; comport = 'COM1'; com = 1; tvremote = 0; subplots('Proximity\tBrightness\tInterruptor\nComPort\tControls\tComments'); function drawProximity(proximity) scale([0,9,0,255]); label('Sensor', 'Value'); bar(proximity(1,:)); function drawBrightness(brightness) scale([0,9,0,255]); label('Sensor', 'Value'); bar(brightness(1,:)); function drawComPort(comport,com,start) plotoption('nolabel'); text(sprintf('______________________________________________')); text(sprintf('Please select your COM Port :')); settabs('X\t\boneXX\t'); button(' \tCOM1\tCOM2\tCOM3\tCOM4 ', com, 'radiobutton', '', 20); text(sprintf('______________________________________________')); settabs([5,5]); if(start == 0) text(sprintf('Click here to start communication :')); button('Start :\t ', start, 'radiobutton', '', 0); else text(sprintf('Click here to stop communication :')); button('Stop :\t ', start, 'radiobutton', '', 0); end text(sprintf('______________________________________________')); text(sprintf('')); text(sprintf('')); text(sprintf('')); text(sprintf('')); text(sprintf('')); text(sprintf('')); text(sprintf('')); function (start,comport,com) = dragComPort(start,comport,com,id,x1) switch id case 0 if(start == 0) start = x1; else start = 0; end case {20} com = x1; switch com case 1 comport = 'COM1'; case 2 comport = 'COM2'; case 3 comport = 'COM3'; case 4 comport = 'COM4'; end end function drawComments() plotoption('nolabel'); text(sprintf('______________________________________________')); text(sprintf('Hemisson Serial Remote Interface V1.0')); text(sprintf('')); text(sprintf('K-TEAM S.A. Switzerland (Alexandre Colot,2003)')); text(sprintf('')); text(sprintf('Web : www.hemisson.com')); text(sprintf('')); text(sprintf('SysQuake is a Calerga product (www.calerga.com)')); text(sprintf('______________________________________________')); text(sprintf('')); text(sprintf('')); text(sprintf('')); text(sprintf('')); text(sprintf('')); function drawControls(beep,start,leds,proximity,osversion,com,tvremote) plotoption('nolabel'); text(sprintf('______________________________________________')); text(sprintf('OS Version :')); text(sprintf('%s',osversion)); text(sprintf('______________________________________________')); text(sprintf('IR Remote Receiver :')); text(sprintf('%X',tvremote)); text(sprintf('______________________________________________')); settabs([15,5]); text(sprintf('Controls :')); button('Buzzer :\t ', beep, 'radiobutton', '', 1); button('Led On/Off :\t ', leds(1,1), 'radiobutton', '', 10); button('Led Pgm/Exec :\t ', leds(2,1), 'radiobutton', '', 11); button('Led FrontRight :\t ', leds(3,1), 'radiobutton', '', 12); button('Led FrontLeft :\t ', leds(4,1), 'radiobutton', '', 13); text(sprintf('______________________________________________')); function drawInterrutpor(interruptor) scale([0,5,0,1]); label('Sensor', 'Value'); bar(interruptor(1,:),'grouped','k'); function (beep,leds) = dragControls(fd,beep,id,x1,leds,start,comport,com) switch id case {1,10,11,12,13} if(start == 1) fd = opendevice(comport, 'b115200,t,T5000,s1'); if (id == 1) if(beep == 0) beep = x1; Hemisson_Buzzer(fd,1); else beep = 0; Hemisson_Buzzer(fd,0); end end if (id == 10) if(leds(1,1) == 0) leds(1,1) = x1; else leds(1,1) = 0; end Hemisson_Led(fd,leds(1,1),leds(2,1),leds(3,1),leds(4,1)); end if (id == 11) if(leds(2,1) == 0) leds(2,1) = x1; else leds(2,1) = 0; end Hemisson_Led(fd,leds(1,1),leds(2,1),leds(3,1),leds(4,1)); end if (id == 12) if(leds(3,1) == 0) leds(3,1) = x1; else leds(3,1) = 0; end Hemisson_Led(fd,leds(1,1),leds(2,1),leds(3,1),leds(4,1)); end if (id == 13) if(leds(4,1) == 0) leds(4,1) = x1; else leds(4,1) = 0; end Hemisson_Led(fd,leds(1,1),leds(2,1),leds(3,1),leds(4,1)); end closedevice(fd); end end function (brightness,proximity,idlerate,interruptor,osversion) = Refresh(fd,brightness,proximity,interruptor,osversion,start,comport) if(start == 1) fd = opendevice(comport, 'b115200,t,T5000,s1'); brightness = Hemisson_Brightness(fd,brightness); proximity = Hemisson_Proximity(fd,proximity); interruptor = Hemisson_Interruptor(fd,interruptor); osversion = Hemisson_OsVersion(fd); closedevice(fd); end idlerate = 0.1; //========================================= // Hemisson_OsVersion //========================================= function (reply) = Hemisson_OsVersion(fd) fprintf(fd,'B'); delay; fprintf(fd,'%c',13); delay; reply = fgetl(fd); //========================================== // Hemisson_Interruptor //========================================== function (interruptor) = Hemisson_Interruptor(fd,interruptor) fprintf(fd,'I'); delay; fprintf(fd,'%c',13); delay; reply = fgetl(fd); if(reply(1,1) == 'i' ) interruptor(1,1) = reply(1,3)-48; interruptor(1,2) = reply(1,5)-48; interruptor(1,3) = reply(1,7)-48; interruptor(1,4) = reply(1,9)-48; end //========================================== // Hemisson_Led //========================================== function Hemisson_Led(fd,led1,led2,led3,led4) fprintf(fd,'L'); delay; fprintf(fd,','); delay; fprintf(fd,'%d',led1); delay; fprintf(fd,','); fprintf(fd,'%d',led2); delay; fprintf(fd,','); fprintf(fd,'%d',led3); delay; fprintf(fd,','); fprintf(fd,'%d',led4); delay; fprintf(fd,'%c',13); delay; reply = fgetl(fd); //========================================== // Hemisson_Motor //========================================== function Hemisson_Motor(fd,valleft,valright) fprintf(fd,'D'); delay; fprintf(fd,','); delay; fprintf(fd,'%d',valleft); delay; fprintf(fd,','); delay; fprintf(fd,'%d',valright); delay; fprintf(fd,'%c',13); delay; reply = fgetl(fd); //========================================== // Hemisson_Brightness //========================================== function (brightness) = Hemisson_Brightness(fd,brightness) fprintf(fd,'O'); delay; fprintf(fd,'%c',13); delay; reply = fgetl(fd); if(reply(1,1) == 'o' ) brightness(1,1) = (reply(1,3)-48)*100+(reply(1,4)-48)*10+reply(1,5)-48; brightness(1,2) = (reply(1,7)-48)*100+(reply(1,8)-48)*10+reply(1,9)-48; brightness(1,3) = (reply(1,11)-48)*100+(reply(1,12)-48)*10+reply(1,13)-48; brightness(1,4) = (reply(1,15)-48)*100+(reply(1,16)-48)*10+reply(1,17)-48; brightness(1,5) = (reply(1,19)-48)*100+(reply(1,20)-48)*10+reply(1,21)-48; brightness(1,6) = (reply(1,23)-48)*100+(reply(1,24)-48)*10+reply(1,25)-48; brightness(1,7) = (reply(1,27)-48)*100+(reply(1,28)-48)*10+reply(1,29)-48; brightness(1,8) = (reply(1,31)-48)*100+(reply(1,32)-48)*10+reply(1,33)-48; end //========================================== // Hemisson_Proximity //========================================== function (proximity) = Hemisson_Proximity(fd,proximity) fprintf(fd,'N'); delay; fprintf(fd,'%c',13); delay; reply = fgetl(fd); if(reply(1,1) == 'n' ) proximity(1,1) = (reply(1,3)-48)*100+(reply(1,4)-48)*10+reply(1,5)-48; proximity(1,2) = (reply(1,7)-48)*100+(reply(1,8)-48)*10+reply(1,9)-48; proximity(1,3) = (reply(1,11)-48)*100+(reply(1,12)-48)*10+reply(1,13)-48; proximity(1,4) = (reply(1,15)-48)*100+(reply(1,16)-48)*10+reply(1,17)-48; proximity(1,5) = (reply(1,19)-48)*100+(reply(1,20)-48)*10+reply(1,21)-48; proximity(1,6) = (reply(1,23)-48)*100+(reply(1,24)-48)*10+reply(1,25)-48; proximity(1,7) = (reply(1,27)-48)*100+(reply(1,28)-48)*10+reply(1,29)-48; proximity(1,8) = (reply(1,31)-48)*100+(reply(1,32)-48)*10+reply(1,33)-48; end //========================================== // Hemisson_IrRemote //========================================== function Hemisson_IrRemote(fd) fprintf(fd,'T'); delay; fprintf(fd,'%c',13); delay; reply = fgetl(fd); //========================================== // Hemisson_I2C_Read //========================================== //function Hemisson_I2C_Read(fd,I2C_Add,Nb) //========================================== // Hemisson_I2C_Write //========================================== //function Hemisson_I2C_Write(fd,I2C_Add,Register,Data) //========================================== // Hemisson_Buzzer //========================================== function Hemisson_Buzzer(fd,val) fprintf(fd,'H'); delay; fprintf(fd,','); delay; fprintf(fd,'%d',val); delay; fprintf(fd,'%c',13); delay; reply = fgetl(fd); //========================================== // delay //========================================== function delay for i = 2:400 for j = 2:400 end end @}