demo_brightness.c
Go to the documentation of this file.
00001 /****************************************************************************
00002 * Copyright (c) Advantech Co., Ltd. All Rights Reserved
00003 *
00004 * File Name:
00005 *       demo_brightness.c
00006 *
00007 * Programmers:
00008 *       Neo Lo
00009 *
00010 ****************************************************************************/
00011 
00012 #include <stdio.h>
00013 #include <stdlib.h>
00014 
00015 #include "REL_Linux_SUSI.H"
00016 
00017 // Return 0 if platform infomation is correctly obtained.
00018 // Otherwise, return 1.
00019 int show_platform_info(void)
00020 {
00021         int result;
00022         DWORD major, minor, year, month, date;
00023         const int BUF_LENGTH = 128;
00024         TCHAR buf[BUF_LENGTH];  // Buffer length includes the null character.
00025 
00026         SusiDllGetVersion(&major, &minor);
00027     year    = minor/10000;
00028     month   = minor%10000/100;
00029     date    = minor%100;
00030         printf("Version: %li (20%02li/%02li/%02li)\n", major, year, month, date);
00031 
00032         // Get platform name.
00033         result = SusiGetPlatformName(buf, BUF_LENGTH);
00034         if (result < 0) {
00035                 printf("SusiGetPlatformName() failed\n");
00036                 return 1;
00037         }
00038         else if (result > 0) {
00039                 printf("SusiGetPlatformName(): buffer is too short\n");
00040                 return 1;
00041         }
00042         else
00043                 printf("Platform name: %s\n", buf);
00044 
00045         // Get BIOS version.
00046         result = SusiGetBIOSVersion(buf, BUF_LENGTH);
00047         if (result < 0) {
00048                 return 1;
00049         }
00050         else if (result > 0) {
00051                 printf("SusiGetBIOSVersion(): buffer is too short\n");
00052                 return 1;
00053         }
00054         else
00055                 printf("BIOS version: %s\n", buf);
00056 
00057         return 0;
00058 }
00059 
00060 void show_menu(void)
00061 {
00062         printf("\n");
00063         printf("0) Terminate this program\n");
00064         printf("1) Get brightness range\n");
00065         printf("2) Get brightness value\n");
00066         printf("3) Set brightness value\n");
00067         printf("Enter your choice: ");
00068 }
00069 
00070 // Return 0 on success and 1 on failure.
00071 int get_bright_rang(void)
00072 {
00073         int result;
00074         BYTE minimum, maximum, stepping;
00075 
00076     minimum = maximum = stepping = 0;
00077         result = SusiVCGetBrightRange(&minimum, &maximum, &stepping);
00078         if (result == FALSE) {
00079                 printf("SusiVCGetBrightRange() failed\n");
00080                 return 1;
00081         }
00082         else
00083         {
00084                 printf("(minimum, maximum, stepping) = (%i, %i, %i)\n", minimum, maximum, stepping);
00085         }
00086     
00087         return 0;
00088 }
00089 
00090 // Return 0 on success and 1 on failure.
00091 int get_bright(void)
00092 {
00093         int result;
00094     BYTE brightness = 0;
00095 
00096         result = SusiVCGetBright(&brightness);
00097         if (result == FALSE) {
00098                 printf("SusiVCGetBright() failed\n");
00099                 return 1;
00100         }
00101         else
00102                 printf("Value: %i\n", brightness);
00103         return 0;
00104 }
00105 
00106 // Return 0 on success and 1 on failure.
00107 int set_bright(void)
00108 {
00109         int result;
00110         int brightness = 0;
00111 
00112         printf("Brightness Value: ");
00113         if (scanf("%i", &brightness) <= 0)
00114                 return 1;
00115         result = SusiVCSetBright(brightness);
00116         if (result == FALSE) {
00117                 printf("SusiVCSetBright() failed\n");
00118                 return 1;
00119         }
00120         return 0;
00121 }
00122 
00123 int main(void)
00124 {
00125         int result, done, op;
00126 
00127         result = SusiDllInit();
00128         if (result == FALSE) {
00129                 printf("SusiDllInit() failed\n");
00130                 return 1;
00131         }
00132 
00133         result = SusiVCAvailable();
00134         if ((result & VC_BRIGHT_CTL_SUPPORT) == 0) {
00135                 printf("SusiVCAvailable() = %d failed\n", result);
00136                 SusiDllUnInit();
00137                 return 1;
00138         }
00139 
00140         result = show_platform_info();
00141 
00142         done = 0;
00143         while (! done) {
00144                 show_menu();
00145                 if (scanf("%i", &op) <= 0)
00146                         op = -1;
00147 
00148                 switch (op) {
00149                 case 0:
00150                         done = 1;
00151                         continue;
00152                 case 1:
00153                         result = get_bright_rang();
00154                         break;
00155                 case 2:
00156                         result = get_bright();
00157                         break;
00158                 case 3:
00159                         result = set_bright();
00160                         break;
00161                 default:
00162                         printf("\nUnknown choice!\n\n");
00163                         continue;
00164                 }
00165                 if (done != 1 && result < 0) {
00166                         SusiDllUnInit();
00167                         return 1;
00168                 }
00169         }
00170 
00171         result = SusiDllUnInit();
00172         if (result == FALSE) {
00173                 printf("SusiDllUnInit() failed\n");
00174                 return 1;
00175         }
00176 
00177         return 0;
00178 }
00179 


advantech
Author(s):
autogenerated on Fri Feb 7 2014 11:36:51