e08aeb3189c67c19a6988057e0f007c3cafa7036.svn-base 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. #include "beepthread.h"
  2. #include "../ytCore/yt_unit_shm.h"
  3. YT_UNIT_SHM *ytShm;
  4. bool load_shm()
  5. {
  6. int shmid;
  7. key_t key;
  8. if((key = ftok(SHM_PATH,(int)SHM_PORT))==-1)
  9. return false;
  10. if((shmid = shmget(key,sizeof(YT_UNIT_SHM),IPC_CREAT|0666))==-1)
  11. return false;
  12. ytShm = (YT_UNIT_SHM *)shmat(shmid,NULL,0);
  13. return true;
  14. }
  15. BeepThread::BeepThread(QObject *parent, Ycapi *api) :
  16. QThread(parent)
  17. {
  18. this->api = api;
  19. load_shm();
  20. }
  21. void BeepThread::setBeep(int type)
  22. {
  23. // this->type = type;
  24. }
  25. void BeepThread::run()
  26. {
  27. while(1)
  28. {
  29. if(ytShm->dogTimeList.dogTime[63].LASTFEED!=0x00){
  30. type = BtnBeep;
  31. ytShm->dogTimeList.dogTime[63].LASTFEED=0x00;
  32. // printf("Btn Beep\n");
  33. emit btn_click();
  34. }
  35. switch(type)
  36. {
  37. case NoBeep:
  38. break;
  39. case OkBeep:
  40. api->BeepOn(true);
  41. usleep(50000);
  42. api->BeepOn(false);
  43. usleep(50000);
  44. api->BeepOn(true);
  45. usleep(150000);
  46. api->BeepOn(false);
  47. break;
  48. case BtnBeep:
  49. api->BeepOn(true);
  50. usleep(100000);
  51. api->BeepOn(false);
  52. break;
  53. case WrongBeep:
  54. api->BeepOn(true);
  55. usleep(150000);
  56. api->BeepOn(false);
  57. usleep(50000);
  58. api->BeepOn(true);
  59. usleep(50000);
  60. api->BeepOn(false);
  61. break;
  62. }
  63. type = NoBeep;
  64. usleep(500000);
  65. }
  66. }