Main Page | Modules | Class Hierarchy | Alphabetical List | Class List | File List | Class Members | Examples

client.cpp

00001 #include "LCDHeaders.h"
00002 #include <iostream>
00003 #include <signal.h>
00004 
00005 using namespace std;
00006 
00007 
00008 LCD_CALLBACK_FUNCTION_BEGIN(forA)
00009 {
00010   cout << " I got " << lcdKey << endl;
00011 }
00012 LCD_CALLBACK_FUNCTION_END(forA)
00013 
00014 class TitleSwitcher: public LCDCallback
00015 {
00016  private:
00017   LCDTitle *_title;
00018   string _firstText, _secondText;
00019  public:
00020   TitleSwitcher(LCDTitle *title, string secondText)
00021   {
00022     _title = title;
00023     _firstText = _title->get();
00024     _secondText = secondText;
00025   }
00026   void operator()(KeyEvent key)
00027   {
00028     if (_title->get() == _firstText)
00029     {
00030       _title->set(_secondText);
00031     }
00032     else
00033     {
00034       _title->set(_firstText);
00035     }
00036   }
00037 };
00038 
00039 bool thisIsTheEnd;
00040 void intHandler(int sig)
00041 {
00042   thisIsTheEnd = true;
00043 }
00044 
00045 int main(char **argv, int argc)
00046 {
00047   try
00048   {
00049 
00050     LCDClient client("localhost", 13666);
00051 
00052     cout << "Server information" << endl
00053          << "  Version :\t" << client.getServerVersion() << endl
00054          << "  Protocol :\t" << client.getProtocolVersion() << endl
00055          << "  Width :\t" << client.getWidth() << endl
00056          << "  Height :\t" << client.getHeight() << endl
00057          << "  Char Width :\t" << client.getCharWidth() << endl
00058          << "  Char Height :\t" << client.getCharHeight() << endl;
00059 
00060     client.setBackLight(LCD_BACKLIGHT_ON);
00061 
00062     /* First screen */
00063 
00064     LCDScreen screen1(&client);
00065     screen1.setDuration(32);
00066 
00067     LCDTitle title("Current Song");
00068     screen1.add(&title);
00069 
00070     LCDScroller scroll(&screen1);
00071     scroll.setWidth(20);
00072     scroll.setSpeed(3);
00073     scroll.move(1, 3);
00074 
00075     LCDKdeMultimediaSensor myMM("No title");
00076     myMM.addOnChangeWidget(&scroll);
00077 
00078     /* Second screen */
00079 
00080     LCDScreen screen2(&client);
00081     screen2.setDuration(32);
00082 
00083     LCDBigNumber num1(&screen2);
00084     num1.set(0,1);
00085     num1.setNumberPosition(5);
00086     LCDBigNumber num2(&screen2);
00087     num2.set(0,5);
00088     num2.setNumberPosition(4);
00089     LCDBigNumber num3(&screen2);
00090     num3.set(0,13);
00091     num3.setNumberPosition(2);
00092     LCDBigNumber num4(&screen2);
00093     num4.set(0,17);
00094     num4.setNumberPosition(1);
00095 
00096 
00097     LCDTimeSensor myTime;
00098     myTime.addOnChangeWidget(&num1);
00099     myTime.addOnChangeWidget(&num2);
00100     myTime.addOnChangeWidget(&num3);
00101     myTime.addOnChangeWidget(&num4);
00102 
00103     /* Third screen */
00104 
00105     LCDText title2("CPU usage");
00106 
00107     LCDCpuSensor myCpu;
00108 
00109     LCDHorizontalBar bar;
00110     bar.move(1,3);
00111     bar.setPercentageMax(client.getWidth() * client.getCharWidth());
00112 
00113     LCDText cpuText;
00114     cpuText.move(16,4);
00115     LCDText percent("%", 19, 4);
00116  
00117     myCpu.addOnChangeWidget(&bar);
00118     myCpu.addOnChangeWidget(&cpuText);
00119 
00120     LCDScreen screen3(&client);
00121     screen3.add(&bar);
00122     screen3.add(&title2);
00123     screen3.add(&cpuText);
00124     screen3.add(&percent);
00125     screen3.setDuration(32);
00126 
00127     client.assignKey('A', &forA);
00128 
00129     TitleSwitcher ts(&title, "Titre courant");
00130     client.assignKey('B', &ts);
00131 
00132     thisIsTheEnd = false;
00133 
00134     signal(SIGINT, intHandler);
00135 
00136     while (!thisIsTheEnd)
00137     {
00138       sleep(10);
00139     }
00140     
00141     cout << "Ending" << endl;
00142 
00143   }
00144   catch (LCDException e)
00145   {
00146     cerr << e.what() << endl;
00147   }
00148 }

Generated on Wed Aug 4 19:39:09 2004 for LCDApi by doxygen 1.3.6