QueueCommand.php 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  1. <?php
  2. /**
  3. * Created by PhpStorm.
  4. * User: Giancarlo
  5. * Date: 09/08/2018
  6. * Time: 14:42
  7. */
  8. namespace OpenMind\FindBox;
  9. class QueueCommand
  10. {
  11. static public $Q_BLINK_ON = 1;
  12. static public $Q_BLINK_OFF = 2;
  13. static public $Q_SAVEPRODUCT = 3;
  14. static public $Q_DISPLAY = 4;
  15. static public $Q_GETJOBS = 5;
  16. static public $Q_CLEARQUEUE = 6;
  17. public $id;
  18. public $operation;
  19. public $description;
  20. public $params;
  21. /**
  22. * QueueCommand constructor.
  23. * @param array|null $labels
  24. */
  25. public function __construct(array $labels = null)
  26. {
  27. $this->id = $labels;
  28. $this->params = null;
  29. }
  30. /**
  31. * Get custom property
  32. *
  33. * @param $name
  34. * @return mixed
  35. */
  36. public function __get($name)
  37. {
  38. return $this->{$name};
  39. }
  40. /**
  41. * Add custom property
  42. *
  43. * @param $name
  44. * @param $value
  45. */
  46. public function __set($name, $value)
  47. {
  48. $this->{$name} = $value;
  49. }
  50. public function setLeds(int $pattern, int $repeat, int $iter_time, int $iterations, int $color)
  51. {
  52. $this->operation = self::$Q_BLINK_ON;
  53. list(
  54. $this->params['pattern'],
  55. $this->params['repeat'],
  56. $this->params['iter_time'],
  57. $this->params['iterations'],
  58. $this->params['color']
  59. ) = func_get_args();
  60. }
  61. public function saveProducts(string $description, array $dataFields)
  62. {
  63. $this->operation = self::$Q_SAVEPRODUCT;
  64. $this->description = $description;
  65. $this->params['dataFields'] = $dataFields;
  66. }
  67. public function setToBlinkOff()
  68. {
  69. $this->operation = self::$Q_BLINK_OFF;
  70. }
  71. /**
  72. * Calculate blink duration in seconds for patterns_type=2
  73. *
  74. * @return int
  75. */
  76. public function getBlinkDuration(): int
  77. {
  78. return ((($this->params['iter_time'] / 1000) * ($this->params['iterations'])) * $this->params['repeat']);
  79. }
  80. /**
  81. * Set Display ID
  82. *
  83. * @param string $templateId
  84. * @param string $barcode
  85. */
  86. public function setDisplay(string $templateId, string $barcode)
  87. {
  88. $this->operation = self::$Q_DISPLAY;
  89. list(
  90. $this->params['templateId'],
  91. $this->params['barcode']
  92. ) = func_get_args();
  93. }
  94. public function getJobs()
  95. {
  96. $this->operation = self::$Q_GETJOBS;
  97. }
  98. public function clearQueue()
  99. {
  100. $this->operation = self::$Q_CLEARQUEUE;
  101. }
  102. }