//--------------------------------------------------------------------------------// //- HemLinCam Sysquake Interface -// //- -// //- 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 fd // serial port variable comport variable com variable start variable pixels variable pixelsthresholded variable led variable threshold variable expositiontime variable refreshrate variable osversion //================================================================================================================ // Functions prototypes //================================================================================================================ init (fd,pixels,led,threshold,expositiontime,refreshrate,pixelsthresholded,comport,com,start) = Init figure "Pixels" draw drawPixels(pixels) figure "Pixels Thresholded" draw drawPixelsThresholded(pixelsthresholded) figure "ComPort" draw drawComPort(comport,com,start) mousedrag (start,comport,com) = dragComPort(start,comport,com,_id,_x1) //figure "OsVersion" //draw drawOsVersion(osversion) figure "Controls" draw drawControls(led,refreshrate,expositiontime,threshold,osversion) mousedrag (fd,led,refreshrate,threshold,expositiontime) = dragControls(fd,led,_id,_x1,refreshrate,threshold,expositiontime,start,comport) figure "Comments" draw drawComments() idle (_idlerate,pixels,pixelsthresholded,osversion) = Refresh(fd,pixels,refreshrate,pixelsthresholded,start,comport,osversion) //=================================================================================================== // Functions //=================================================================================================== functions {@ function (fd,pixels,led,threshold,expositiontime,refreshrate,pixelsthresholded,comport,com,start) = Init pixels = ones(1,102); pixelsthresholded = ones(1,102); led = 0; threshold = 0; expositiontime = 1; subplots('Pixels\tPixels Thresholded\nComPort\tControls\tComments'); refreshrate = 1 comport = 'COM1'; start = 0; comport = 'COM1'; com = 1; fd = 0; osversion = 0; 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 drawPixels(pixels) label('Sensor', 'Value'); pixel_im = pixels/255; scale([1,102,-40,270]); sc = scale; xmin = sc(1); xmax = sc(2); image(pixel_im, [xmin,xmax,-30,-10]); bar(pixels(1,:)) function drawPixelsThresholded(pixelsthresholded) label('Sensor', 'Value'); pixel_im = pixelsthresholded/255; scale([1,102,-40,270]); sc = scale; xmin = sc(1); xmax = sc(2); image(pixel_im, [xmin,xmax,-30,-10]); bar(pixelsthresholded(1,:)) function drawComments() plotoption('nolabel'); text(sprintf('______________________________________________')); text(sprintf('HemLinCam 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(led,refreshrate,expositiontime,threshold,osversion) plotoption('nolabel'); text(sprintf('________________________________________________________________')); text(sprintf('OS Version :')); text(sprintf('%s',osversion)); text(sprintf('________________________________________________________________')); settabs([20,5]); button('Led :\t ', led, 'radiobutton', '', 1); slider(sprintf('Refresh Rate [%d Hz]:', refreshrate), refreshrate, [1, 20], '', '', 2); slider(sprintf('Exposisition Time [%d]:', expositiontime), expositiontime, [1, 10], '', '', 3); slider(sprintf('Threshold [%d]:', threshold), threshold, [0, 255], '', '', 4); text(sprintf('________________________________________________________________')); text(sprintf('')); text(sprintf('')); text(sprintf('')); text(sprintf('')); text(sprintf('')); function (fd,led,refreshrate,threshold,expositiontime) = dragControls(fd,led,id,x1,refreshrate,threshold,expositiontime,start,comport) switch id case {1,3,4} if(start == 1) fd = opendevice(comport, 'b115200,t,T5000,s1'); if (id == 1) if(led == 0) led = x1; HemLinCam_Led(fd,1) else led = 0; HemLinCam_Led(fd,0) end end if (id == 3) expositiontime = round(x1); HemLinCam_Exposition(fd,expositiontime) end if (id == 4) threshold = round(x1); HemLinCam_Threshold(fd,threshold) end closedevice(fd); end case {2} if (id == 2) refreshrate = round(x1); end end function (idlerate,pixels,pixelsthresholded,osversion) = Refresh(fd,pixels,refreshrate,pixelsthresholded,start,comport,osversion) if(start == 1) fd = opendevice(comport, 'b115200,t,T5000,s1'); pixels = HemLinCam_Get_Pixels(fd,pixels); pixelsthresholded = HemLinCam_Get_Pixels_Thresholded(fd,pixelsthresholded); osversion = HemLinCam_OsVersion(fd,osversion); closedevice(fd); end idlerate = 1/refreshrate; //========================================= // HemLinCam_Led //========================================= function HemLinCam_Led(fd,state) fprintf(fd,'W'); delay fprintf(fd,','); delay fprintf(fd,'C'); delay fprintf(fd,'0'); delay fprintf(fd,','); delay fprintf(fd,'3'); delay fprintf(fd,'0'); delay fprintf(fd,','); delay fprintf(fd,'0'); delay fprintf(fd,'%d',state); delay fprintf(fd,'%c',13); delay reply = fgetl(fd) //========================================= // HemLinCam_Get_Pixels //========================================= function pixels = HemLinCam_Get_Pixels(fd,pixels) fprintf(fd,'R'); delay fprintf(fd,','); delay fprintf(fd,'C'); delay fprintf(fd,'0'); delay fprintf(fd,','); delay fprintf(fd,'1'); delay fprintf(fd,'0'); delay fprintf(fd,','); delay fprintf(fd,'6'); delay fprintf(fd,'6'); delay fprintf(fd,'%c',13); delay reply = fgetl(fd) if(reply(1,1) == 'r' ) for i=1:102; pixels(1,i) = (reply(1,(i*4)-1)-48)*100+(reply(1,i*4)-48)*10+reply(1,(i*4)+1)-48; end end //========================================= // HemLinCam_Get_Pixels_Thresholded //========================================= function pixelsthresholded = HemLinCam_Get_Pixels_Thresholded(fd,pixelsthresholded) fprintf(fd,'R'); delay fprintf(fd,','); delay fprintf(fd,'C'); delay fprintf(fd,'0'); delay fprintf(fd,','); delay fprintf(fd,'1'); delay fprintf(fd,'1'); delay fprintf(fd,','); delay fprintf(fd,'6'); delay fprintf(fd,'6'); delay fprintf(fd,'%c',13); delay reply = fgetl(fd) if(reply(1,1) == 'r' ) for i=1:102; pixelsthresholded(1,i) = (reply(1,(i*4)-1)-48)*100+(reply(1,i*4)-48)*10+reply(1,(i*4)+1)-48; end end //========================================= // HemLinCam_Threshold //========================================= function HemLinCam_Threshold(fd,value) fprintf(fd,'W'); delay fprintf(fd,','); delay fprintf(fd,'C'); delay fprintf(fd,'0'); delay fprintf(fd,','); delay fprintf(fd,'2'); delay fprintf(fd,'0'); delay fprintf(fd,','); delay fprintf(fd,'%2X',value); delay fprintf(fd,'%c',13); delay reply = fgetl(fd) //========================================= // HemLinCam_Exposition //========================================= function HemLinCam_Exposition(fd,value) fprintf(fd,'W'); delay fprintf(fd,','); delay fprintf(fd,'C'); delay fprintf(fd,'0'); delay fprintf(fd,','); delay fprintf(fd,'2'); delay fprintf(fd,'1'); delay fprintf(fd,','); delay fprintf(fd,'%2X',value); delay fprintf(fd,'%c',13); delay reply = fgetl(fd) //========================================= // HemLinCam_OsVersion //========================================= function (osversion)=HemLinCam_OsVersion(fd,osversion) fprintf(fd,'R'); delay fprintf(fd,','); delay fprintf(fd,'C'); delay fprintf(fd,'0'); delay fprintf(fd,','); delay fprintf(fd,'0'); delay fprintf(fd,'0'); delay fprintf(fd,','); delay fprintf(fd,'0'); delay fprintf(fd,'1'); delay fprintf(fd,'%c',13); delay osversion = fgetl(fd) //========================================= // delay //========================================= function delay for i = 2:350 for j = 2:400 end end @}