/* * Copyright (c) 1997, Kyle Mestery * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * * THIS SOFTWARE IS PROVIDED BY THE AUTHORS AND CONTRIBUTORS ``AS IS'' AND * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHORS OR CONTRIBUTORS BE LIABLE * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * */ #include #include #include #include #include #include #include #include #define AFC_BITS 0x07 #define AFC_FREQ_MINUS_125 0x00 #define AFC_FREQ_MINUS_62 0x01 #define AFC_FREQ_CENTERED 0x02 #define AFC_FREQ_PLUS_62 0x03 #define AFC_FREQ_PLUS_125 0x04 #define BOTTOM (unsigned long)(55.25 * 16) #define TOP (unsigned long)(655.25 * 16) void main() { int afcon = 1; unsigned long freq, freq2, status; int fd; char *nothing; extern int errno; if ((fd = open("/dev/tuner0", O_RDONLY)) == -1) { printf("Error opening file: --> %d", errno); exit(0); } if ( ioctl( fd, TVTUNER_SETAFC, &afcon ) < 0 ) { printf("Error: SETAFC1 --> %d", errno); } for ( freq = BOTTOM; freq < TOP; freq += (6.0 * 16) ) { printf( "\ntrying freq: %f", (double)((double)freq / 16.0) ); if ( ioctl( fd, TVTUNER_SETFREQ, &freq ) < 0 ) { printf("Error: SETFREQ --> %d\n", errno); } if ( ioctl( fd, TVTUNER_GETFREQ, &freq2 ) < 0 ) { printf("Error: GETFREQ --> %d\n", errno); } if ( ioctl( fd, TVTUNER_GETSTATUS, &status ) < 0 ) { printf("Error: GETSTATUS --> %d\n", errno); } if ( !(status & 0x40) ) { printf( ", no lock (?)\n" ); sleep( 1 ); continue; } /** XXX not sure about the / 16 */ printf( "\nafc picked freq: %f", (double) \ ((double)freq2 / 16.0) ); printf( ", hit return to continue..." ); nothing = (char *) malloc(sizeof(char *)); gets(nothing); } }