SmartESL.php 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  1. <?php
  2. /**
  3. * @author Open Mind
  4. * @date 28/03/2018
  5. * @time 09:09
  6. */
  7. namespace OpenMind\Labeling;
  8. class SmartESL
  9. {
  10. private $core;
  11. private $labels;
  12. private $labelProperties;
  13. public function __construct(FindBoxCoreSystem $coreL, array $LabelID)
  14. {
  15. $this->core = $coreL;
  16. $this->labels = $LabelID;
  17. $this->labelProperties = $this->GetStatus();
  18. }
  19. /**
  20. * Retrieve cached label properties
  21. *
  22. * @return null|object
  23. */
  24. public function getDetails()
  25. {
  26. return $this->labelProperties;
  27. }
  28. /**
  29. * Get label version splitted into the three components major, minor, patch
  30. *
  31. * @return array
  32. */
  33. public function GetVersion()
  34. {
  35. $softVersion = $this->labelProperties[array_keys($this->labelProperties)[0]]['status'];
  36. return array_values(array_filter_keys($softVersion, ['soft_major', 'soft_minor', 'soft_patch']));
  37. }
  38. /**
  39. * Blink the label. If old version found, skip automatically useless parameter
  40. *
  41. * @param int $pattern
  42. * @param int $repeat
  43. * @param int $iter_time
  44. * @param int $iterations
  45. * @param int|null $ledColor
  46. */
  47. public function BlinkSpecial(int $pattern, int $repeat, int $iter_time, int $iterations, int $ledColor = null)
  48. {
  49. $firmwareStringVersion = array(
  50. '3' => '1.0.0',
  51. '4' => '1.1.0',
  52. '6' => '2.0.0'
  53. );
  54. $params = array(
  55. '3' => array($pattern, $repeat, $iter_time, $iterations, 1),
  56. '4' => array($pattern, $repeat, $iter_time, $iterations, 1),
  57. '6' => array($pattern, $ledColor, $repeat, $iter_time, $iterations, 1)
  58. );
  59. // TODO #NODISPLAY da sistemare
  60. $strFWVer = $firmwareStringVersion[4];
  61. $uriParams = json_encode(array_merge(
  62. array($this->labels),
  63. $params[4]));
  64. $URI = "/1.0.0/index.php/smartesl.blink_special/{$strFWVer}/";
  65. $this->core->CallAPI($URI, $uriParams, true);
  66. }
  67. /**
  68. * Turn off led(s)
  69. */
  70. public function BlinkOff()
  71. {
  72. $URI = "/1.0.0/index.php/smartesl.blink_special/1.1.0/";
  73. $this->core->CallAPI($URI, "[[\"{$this->labels[0]}\"],3,1,500,1,1]", true);
  74. // $URI = "/1.0.0/index.php/smartesl.blink_special/2.0.0/";
  75. // $this->core->CallAPI($URI, "[[\"{$this->labels[0]}\"],0,1,1,500,1,1]", true);
  76. }
  77. /**
  78. * Request to label(s) its properties
  79. * @return null|object Details
  80. */
  81. public function GetStatus()
  82. {
  83. $labels = json_encode(array($this->labels));
  84. $URI = "/1.0.0/index.php/smartesl.getstatus/3.1.0/";
  85. $ret = $this->core->CallAPI($URI, $labels);
  86. if ($ret['err'] == 0 && $ret['value']['code'] == 0) {
  87. return $ret['value']['value'];
  88. }
  89. return null;
  90. }
  91. public function Display(string $templateId, string $barcode)
  92. {
  93. $URI = "/1.0.0/index.php/smartesl.display/2.3.0/";
  94. $params = json_encode(array(
  95. $this->labels[0],
  96. $barcode,
  97. [],
  98. $templateId,
  99. 1, 1));
  100. return $this->core->CallAPI($URI, $params);
  101. }
  102. public function GetLabelMatch()
  103. {
  104. $URI = "/1.0.0/index.php/smartesl.getlabelmatch/1.2.0/";
  105. return $this->core->CallAPI($URI, json_encode(array($this->labels)));
  106. }
  107. }