Main Page   File List   Globals  

tests/fbdb.c

00001 /***************************************************************************
00002                       fbdb.c  -  libFB debuging program for libFB library
00003                              -------------------
00004     begin                : Thu Apr 18 2002
00005     copyright            : (C) 2002 by Nathan P. Cole
00006     email                : qmagick@yahoo.com
00007  ***************************************************************************/
00008 
00009 /***************************************************************************
00010  *                                                                         *
00011  *   This program is free software; you can redistribute it and/or modify  *
00012  *   it under the terms of the GNU General Public License as published by  *
00013  *   the Free Software Foundation; version 2 of the License.               *
00014  *                                                                         *
00015  ***************************************************************************/
00016 #include "FBlib.h"
00017 #include <stdio.h>
00018 #include <stdlib.h>
00019 
00020 int main(int argc, char ** argv)
00021 {
00022         float slope;
00023         FB_pixel col;
00024         u_char r, g, b;
00025         char command[60];
00026         int sx, sy, ex, ey;
00027         int red, green, blue;
00028 
00029         printf ("\nThis is the libFB debug program. It tests using a shell various\n");
00030         printf ("libFB capabilities. For information type ? <ENT>. This program is\n");
00031         printf ("free software; you can distribute it and/or modify it under the\n");
00032         printf ("the terms of the GNU General Public License as published by the\n");
00033         printf ("Free Software Foundation; version 2 of the License.\n\n");
00034         
00035         while (1) {
00036                 printf ("[fbdb (q for quit, ? for help)] ");
00037                 scanf ("%s", command);
00038 
00039                 if (!strcmp (command, "?")) {
00040                         printf ("Currently the only command is for lines.\n");
00041                         printf ("To create a line type in the string line,\n");
00042                         printf ("vline, or hline to enter a line a\n");
00043                         printf ("verticle line or horizontal line respectfully.\n");
00044                         continue;
00045                 }
00046 
00047                 if (!strcmp (command, "q")) {
00048                         printf ("Good Bye!\n\n");
00049                         break;
00050                 }
00051                 
00052                 if (!strcmp (command, "hline")) {
00053                         printf ("line color::\n");
00054                         
00055                         printf ("red (0-255): \n");
00056                         scanf ("%i", &red);
00057                         if (red < 0 || red > 255) {
00058                                 printf ("Value must be between 0 and 255\n");
00059                                 continue;
00060                         }
00061                         r = (u_char) red;
00062 
00063                         printf ("green (0-255): \n");
00064                         scanf ("%i", &green);
00065                         if (green < 0 || green > 255) {
00066                                 printf ("Value must be between 0 and 255\n");
00067                                 continue;
00068                         }
00069                         g = (u_char) green;
00070                 
00071                         printf ("blue (0-255): \n");
00072                         scanf ("%i", &blue);
00073                         if (blue < 0 || blue > 255) {
00074                                 printf ("Value must be between 0 and 255\n");
00075                                 continue;
00076                         }
00077                         b = (u_char) blue;
00078 
00079                         printf ("y: ");
00080                         scanf ("%i", &sy);
00081                         printf ("start x: ");
00082                         scanf ("%i", &sx);
00083                         printf ("end x:   ");
00084                         scanf ("%i", &ex);
00085                 
00086                         col = FB_makecol (r, g, b, 0);
00087 
00088                         FB_initlib ("/dev/fb0");
00089                         FB_clear_screen (FB_makecol(0,0,0,0));
00090                         FB_hline(sx, ex, sy, col);
00091                         
00092                         getchar ();
00093                         getchar ();
00094                         FB_clear_screen (FB_makecol(0,0,0,0));
00095                         FB_exit ();                     
00096                 }
00097 
00098                 if (!strcmp (command, "vline")) {
00099                         printf ("line color::\n");
00100                         
00101                         printf ("red (0-255): \n");
00102                         scanf ("%i", &red);
00103                         if (red < 0 || red > 255) {
00104                                 printf ("Value must be between 0 and 255\n");
00105                                 continue;
00106                         }
00107                         r = (u_char) red;
00108 
00109                         printf ("green (0-255): \n");
00110                         scanf ("%i", &green);
00111                         if (green < 0 || green > 255) {
00112                                 printf ("Value must be between 0 and 255\n");
00113                                 continue;
00114                         }
00115                         g = (u_char) green;
00116                 
00117                         printf ("blue (0-255): \n");
00118                         scanf ("%i", &blue);
00119                         if (blue < 0 || blue > 255) {
00120                                 printf ("Value must be between 0 and 255\n");
00121                                 continue;
00122                         }
00123                         b = (u_char) blue;
00124 
00125                         printf ("x: ");
00126                         scanf ("%i", &sx);
00127                         printf ("start y: ");
00128                         scanf ("%i", &sy);
00129                         printf ("end y:   ");
00130                         scanf ("%i", &ey);
00131 
00132                         col = FB_makecol (r, g, b, 0);
00133 
00134                         FB_initlib ("/dev/fb0");
00135                         FB_clear_screen(FB_makecol(0,0,0,0));
00136                         FB_vline(sx, sy, ey, col);
00137                         
00138                         getchar ();
00139                         getchar ();
00140                         FB_clear_screen (FB_makecol(0,0,0,0));
00141                         FB_exit ();                     
00142                 }
00143                         
00144                 if (!strcmp (command, "line")) {
00145                         printf ("line color::\n");
00146 
00147                         printf ("red (0-255): \n");
00148                         scanf ("%i", &red);
00149                         if (red < 0 || red > 255) {
00150                                 printf ("Value must be between 0 and 255\n");
00151                                 continue;
00152                         }
00153                         r = (u_char) red;
00154 
00155                         printf ("green (0-255): \n");
00156                         scanf ("%i", &green);
00157                         if (green < 0 || green > 255) {
00158                                 printf ("Value must be between 0 and 255\n");
00159                                 continue;
00160                         }
00161                         g = (u_char) green;
00162                 
00163                         printf ("blue (0-255): \n");
00164                         scanf ("%i", &blue);
00165                         if (blue < 0 || blue > 255) {
00166                                 printf ("Value must be between 0 and 255\n");
00167                                 continue;
00168                         }
00169                         b = (u_char) blue;
00170 
00171                         FB_makecol (r, g, b, 0);
00172 
00173                         printf ("Line position::\n");
00174 
00175                         printf ("start x: ");
00176                         scanf ("%i", &sx);
00177 
00178                         printf ("start y: ");
00179                         scanf ("%i", &sy);
00180 
00181                         printf ("end x: ");
00182                         scanf ("%i", &ex);
00183 
00184                         printf ("end y: ");
00185                         scanf ("%i", &ey);
00186                                  
00187                         col = FB_makecol (r, g, b, 0);
00188 
00189                         FB_initlib("/dev/fb0");
00190                         FB_clear_screen(FB_makecol(0,0,0,0));
00191                         FB_line(sx, sy, ex, ey, col);
00192                         
00193                         getchar ();
00194                         getchar ();
00195                         FB_clear_screen (FB_makecol(0,0,0,0));
00196                         FB_exit ();
00197 
00198                         slope = (float) (sx - ex);
00199 
00200                         if (slope == 0.0) {
00201                                 printf ("Slope of line is Infinite.\n");
00202                                 continue;
00203                         }
00204 
00205                         slope = (float) (sy - ey) / slope;
00206                         printf ("Slope of line is %.3f.\n", slope);
00207                 }
00208         }
00209         return 0;
00210 }

Generated on Sat Jul 5 09:04:51 2003 for LibFB by doxygen1.2.18