test-BeoChipQt.C
00001
00002
00003
00004
00005
00006 #include <Qt/qapplication.h>
00007 #include "Qt4/BeoChipMainForm.qt.H"
00008 #include "QtUtil/Util.H"
00009
00010
00011
00012 class MyBeoChipListener : public BeoChipListener
00013 {
00014 public:
00015 MyBeoChipListener() :
00016 itsForm(NULL)
00017 { }
00018
00019 virtual ~MyBeoChipListener()
00020 { }
00021
00022 virtual void setQtForm(BeoChipMainForm *form)
00023 { itsForm = form; }
00024
00025 virtual void event(const BeoChipEventType t, const int valint,
00026 const float valfloat)
00027 {
00028
00029
00030
00031
00032
00033 LDEBUG("Event: %d val = %d, fval = %f", int(t), valint, valfloat);
00034 switch(t)
00035 {
00036 case NONE:
00037 break;
00038
00039 case PWM0:
00040 if (itsForm) itsForm->showPWM(0, valint);
00041 break;
00042
00043 case PWM1:
00044 if (itsForm) itsForm->showPWM(1, valint);
00045 break;
00046
00047 case KBD:
00048 if (itsForm)
00049 for (int i = 0; i < 5; i ++)
00050 if (valint & (1 << i)) itsForm->showDin(i, true);
00051 else itsForm->showDin(i, false);
00052 break;
00053
00054 case ADC0:
00055 if (itsForm) itsForm->showAnalog(0, valint);
00056 break;
00057
00058 case ADC1:
00059 if (itsForm) itsForm->showAnalog(1, valint);
00060 break;
00061
00062 case RESET:
00063 if (itsForm) itsForm->beoChipReset();
00064 LERROR("BeoChip RESET occurred!");
00065 break;
00066
00067 case ECHOREP:
00068 LINFO("BeoChip Echo reply received.");
00069 break;
00070
00071 case INOVERFLOW:
00072 LERROR("BeoChip input overflow!");
00073 break;
00074
00075 case SERIALERROR:
00076 LERROR("BeoChip serial error!");
00077 break;
00078
00079 case OUTOVERFLOW:
00080 LERROR("BeoChip output overflow!");
00081 break;
00082
00083 default:
00084 LERROR("Unknown event %d received!", int(t));
00085 break;
00086 }
00087 }
00088
00089 protected:
00090 BeoChipMainForm *itsForm;
00091 };
00092
00093
00094
00095 int main( int argc, const char ** argv )
00096 {
00097
00098 ModelManager manager("test-BeoChipQt");
00099
00100
00101 nub::soft_ref<BeoChip> bc(new BeoChip(manager));
00102 manager.addSubComponent(bc);
00103
00104
00105 rutz::shared_ptr<MyBeoChipListener> lis(new MyBeoChipListener);
00106 rutz::shared_ptr<BeoChipListener> lis2; lis2.dynCastFrom(lis);
00107 bc->setListener(lis2);
00108
00109
00110 if (manager.parseCommandLine(argc, argv, "<serdev>", 1, 1) == false)
00111 return(1);
00112
00113
00114 bc->setModelParamVal("BeoChipDeviceName", manager.getExtraArg(0));
00115
00116
00117 manager.start();
00118
00119
00120 QApplication a(argc, argv2qt(argc, argv));
00121 BeoChipMainForm *w = new BeoChipMainForm;
00122
00123
00124 lis->setQtForm(w);
00125
00126
00127 w->init(&manager, bc);
00128
00129
00130 w->show();
00131 a.connect(&a, SIGNAL(lastWindowClosed()), &a, SLOT(quit()));
00132
00133
00134 int retval = a.exec();
00135
00136
00137 manager.stop();
00138
00139 return retval;
00140 }