00001 00015 /* 00016 Barcode Sampling - Copyright (C) 2009 John Dybowski - All rights reserved 00017 V1.0.0 00018 00019 barcode_sample.c is part of the ESE Auto-ID software distribution. 00020 00021 Redistribution and use in source and binary forms, with or without modification, is 00022 permitted provided that the following conditions are met: 00023 00024 Redistributions of source code must retain the above copyright notice, this list of 00025 conditions and the following disclaimer. Redistributions in binary form must reproduce 00026 the above copyright notice, this list of conditions and the following disclaimer in the 00027 documentation and/or other materials provided with the distribution. 00028 00029 The end-user documentation included with the redistribution, if any, must include the 00030 following acknowledgment: 'This product includes software developed by John Dybowski.' 00031 Alternately, this acknowledgment may appear in the software itself, if and wherever such 00032 third-party acknowledgments normally appear. 00033 00034 The name 'John Dybowski' must not be used to endorse or promote products derived from 00035 this software without prior written permission. 00036 00037 barcode_sample.c is free software; you can redistribute it and/or modify it under the terms 00038 of the GNU General Public License as published by the Free Software Foundation; either 00039 version 2 of the License, or (at your option) any later version. See the GNU General 00040 Public License for more details. 00041 00042 You should have received a copy of the GNU General Public License along with this software; 00043 if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, 00044 MA 02111-1307 USA 00045 00046 A special exception to the GPL can be applied should you wish to distribute a combined work 00047 that includes barcode_sample.c, without being obliged to provide the source code for any proprietary 00048 components. See the licensing section at http://embeddedsoftwareengineering.com/license.html 00049 for full details of how and when the exception can be applied. 00050 00051 THIS SOFTWARE IS PROVIDED 'AS IS' AND ANY EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT 00052 NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 00053 PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL JOHN DYBOWSKI OR ITS CONTRIBUTORS BE LIABLE 00054 FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, 00055 BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; 00056 OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 00057 STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE 00058 USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 00059 */ 00060 00061 #include "reader.h" 00062 00063 /*----------------------------------------------------------------------------*/ 00071 void 00072 barcodeSample(struct BC_STRUCT *p, unsigned int count) 00073 { 00074 // Leave if sample is already available 00075 if(p->sample_state == READY){ 00076 return; 00077 } 00078 00079 // Arm overflow counter 00080 p->overflow_ctr = BARCODE_OVERFLOW_TIME; 00081 00082 // Initialize if just starting 00083 if(p->sample_state != BUSY){ 00084 p->sample_ctr = 0; 00085 p->sample_ptr = p->sample_buffer; 00086 p->sample_state = BUSY; 00087 return; 00088 } 00089 00090 // Already Sampling 00091 00092 // Buffer full? 00093 if(p->sample_ctr++ >= (sizeof p->sample_buffer / 2) - 1){ 00094 00095 // Kill the sampling 00096 p->sample_ctr = 0; 00097 p->overflow_ctr = 1; 00098 p->sample_state = WAITING; 00099 return; 00100 } 00101 00102 // Store the count 00103 *p->sample_ptr++ = count; 00104 } 00105 00106 /*----------------------------------------------------------------------------*/ 00113 void barcodeOverflow(struct BC_STRUCT *p){ 00114 00115 // Abort if less than the minimum required samples 00116 if(p->sample_ctr < MIN_BARCODE_SAMPLES){ 00117 p->sample_state = WAITING; 00118 } 00119 00120 // Store the overflow count and flag as ready 00121 else{ 00122 *p->sample_ptr++ = 0; 00123 p->sample_state = READY; 00124 } 00125 }