m3m0r7/ez-door-sign

0.0.1 2024-03-23 02:01 UTC

This package is auto-updated.

Last update: 2024-09-23 03:51:01 UTC


README

这是什么?

此项目可在任何操作系统下工作,以实现PHP的EZ Door Sign。EZ Door Sign是一种小型电子纸显示屏(EPD)。它更适合用作物联网工具。

您可以使用RaspberryPI、macOS等多种环境。例如,此项目可以自动渲染图像。因此,此项目可以用于各种场合。

注意

Santek Inc. 已要求本应用程序的用户自行决定使用。开发者不对使用本应用程序可能产生的任何不利后果承担责任,例如设备损坏,因此请自行承担风险。

关于本应用程序的使用,EZ Door Sign的发行商株式会社サンテクノロジー(Santek Japan Corporation)已要求用户自行判断使用,开发者在用户使用本应用程序时,若设备损坏等任何不利后果发生,不承担任何责任,因此请自行承担责任。

需求

  • PHP 8.3+
  • PHP FFI
  • libusb >= 1.0

开始使用

以下图像是通过此PHP代码项目渲染的。

  1. 通过composer安装此项目
$ composer require m3m0r7/ez-door-sign
  1. 将您的EZ门牌显示器连接到您的机器。
  2. 打开您的设备。

快速入门

刷新设备

<?php

use Libusb\Connector\Libusb1_0;
use Libusb\Libusb;
use Libusb\LibusbHandle;
use Libusb\Loader\AutoLoader;
use EzDoorSign\EzDoorSign;
use EzDoorSign\Manipulator;

require __DIR__ . '/vendor/autoload.php';

$libusb = new Libusb(
    new LibusbHandle(
        new Libusb1_0(
            new AutoLoader(
                '1.0',
                // Specify loading path libusb
                is_dir('/opt/homebrew/Cellar/libusb')
                    ? glob('/opt/homebrew/Cellar/libusb/1.0.*') ?: []
                    : []
            ),
        )
    ),
);

$ezDoorSign = new EzDoorSign($libusb);

/**
 * @var Manipulator $manipulator
 */
[$manipulator] = $ezDoorSign->devices();

// Run refresh command
$manipulator->refresh();

渲染文本/图像

<?php

use EzDoorSign\Command\renderImageCommand;
use EzDoorSign\EzDoorSign;
use EzDoorSign\Manipulator;
use Libusb\Connector\Libusb1_0;
use Libusb\Libusb;
use Libusb\LibusbHandle;
use Libusb\Loader\AutoLoader;
use EzDoorSign\Renderer\ImageRenderer;
use EzDoorSign\Renderer\TextRenderer;
use EzDoorSign\Renderer\Canvas;

require __DIR__ . '/vendor/autoload.php';

$libusb = new Libusb(
    new LibusbHandle(
        new Libusb1_0(
            new AutoLoader(
                '1.0',
                // Specify loading path libusb
                is_dir('/opt/homebrew/Cellar/libusb')
                    ? glob('/opt/homebrew/Cellar/libusb/1.0.*') ?: []
                    : []
            ),
        )
    ),
);

$ezDoorSign = new EzDoorSign($libusb);

/**
 * @var Manipulator $manipulator
 */
[$manipulator] = $ezDoorSign->devices();

$manipulator
    ->renderImage(

        // Specify rendering an image is here (only support image path currently)
        new Canvas(new \EzDoorSign\Renderer\ImageRenderer(__DIR__ . '/tests/example.jpg')),

        // If you want to render a text, then comment-in below code and do comment-out starting with `new Canvas(new \EzDoorSign\Renderer\ImageRenderer(...)),` in above.
        // new Canvas(new \EzDoorSign\Renderer\TextRenderer('Hello World!', '/path/to/your-fornts.ttf'))

        // Specify rendering options
        fn (renderImageCommand $renderImage) => $renderImage
            // This method means vailable to set filling color. This example is using Red color to fill.
            ->setFillColor(ColorPattern::RED)

        // Specify slot number (0-4)
        0,
    );

获取日志

// ... do something

$ezDoorSign = new EzDoorSign(
    $libusb,
    // You can specify logger in the 2nd parameter of the EzDoorSign class's constructor.
    (new Logger('log'))
        ->pushHandler(new StreamHandler(STDOUT, Level::Info)),
);

// ... do something

测试

./vendor/bin/phpunit tests

EZ Door Sign的功能

许可证

MIT