QueueCommand.php 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  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. define('Q_BLINK_ON', 1);
  10. define('Q_BLINK_OFF', 2);
  11. define('Q_SAVEPRODUCT', 3);
  12. define('Q_DISPLAY', 4);
  13. class QueueCommand
  14. {
  15. public $id;
  16. public $operation;
  17. public $description;
  18. public $params;
  19. public $tsFirstBlink;
  20. public $tsLastLongBlink;
  21. public function __construct(string $labelID)
  22. {
  23. $this->id = $labelID;
  24. $this->params = null;
  25. $this->tsLastLongBlink = time() - 3600;
  26. $this->tsFirstBlink = time();
  27. }
  28. public function setLeds(int $pattern, int $repeat, int $iter_time, int $iterations, int $color)
  29. {
  30. $this->operation = Q_BLINK_ON;
  31. list(
  32. $this->params['pattern'],
  33. $this->params['repeat'],
  34. $this->params['iter_time'],
  35. $this->params['iterations'],
  36. $this->params['color']
  37. ) = func_get_args();
  38. }
  39. public function saveProducts(string $description, array $dataFields)
  40. {
  41. $this->operation = Q_SAVEPRODUCT;
  42. $this->description = $description;
  43. $this->params['dataFields'] = $dataFields;
  44. }
  45. public function setToBlinkOff()
  46. {
  47. $this->operation = Q_BLINK_OFF;
  48. }
  49. /**
  50. * Calculate blink duration in seconds for patterns_type=2
  51. *
  52. * @return int
  53. */
  54. public function getBlinkDuration(): int
  55. {
  56. return (($this->params['iter_time'] / 1000) * ($this->params['iterations'] - 1)) * $this->params['repeat'];
  57. }
  58. /**
  59. * Set Display ID
  60. *
  61. * @param string $templateId
  62. * @param string $barcode
  63. */
  64. public function setDisplay(string $templateId, string $barcode)
  65. {
  66. $this->operation = Q_DISPLAY;
  67. list(
  68. $this->params['templateId'],
  69. $this->params['barcode']
  70. ) = func_get_args();
  71. }
  72. }