jaycar-rgb-usb-led风扇(gh1031)协议的实现
microwave-usbfan的Python项目详细描述
微波USB风扇
这个库是jaycar rgb usb led风扇的纯python重新实现 (GH1031)协议。 使用USB HID报告作为传输进行通信。这个库使用 hidapi要在Linux、MacOS上执行此操作, FreeBSD和Windows。
安装
pip install microwave-usbfan
示例实现
两条短信
fromusbfanimportDevice,Program,TextMessage# A program is made up of a list of Messages# A "TextMessage" is a subclass of the generic Message class p=Program((TextMessage("Hello, World!"),TextMessage("How is everyone going?"),))# Open the device and programd=Device()d.program(p)
单个红点
fromusbfanimportColour,Column,Device,Message,Program# A generic "Message" is made up of 1 to 144 "Column" object# A "Column" has 11 boolean pixels and a "Colour"columns=[Column([True]+[False]*10,Colour.red)]for_inrange(7):columns.append(Column([False]*11,Colour.red))p=Program((Message(columns),))# Open the device and programd=Device()d.program(p)
彩虹消息
fromusbfanimportColour,Column,Device,Message,Program,TextMessage# We can cycle the rainbow here and fill all 144 columnsrainbow_colours=[Colour.red,Colour.yellow,Colour.green,Colour.cyan,Colour.blue,Colour.magenta]rainbow=[Column([True]*11,rainbow_colours[i%len(rainbow_colours)])foriinrange(Message.MAX_COLUMNS)]p=Program((TextMessage("Here comes the rainbow!"),Message(rainbow),))# Open the device and programd=Device()d.program(p)
模式控制
对于每条消息,您可以定义它的打开方式、显示后的功能,以及 关门时它会做什么。
fromusbfanimportColour,Column,Device,Message,Program,TextMessage, \ MessageStyle,OpenTransition,CloseTransition# We can cycle the rainbow here and fill all 144 columnsrainbow_colours=[Colour.red,Colour.yellow,Colour.green,Colour.cyan,Colour.blue,Colour.magenta]rainbow=[Column([True]*11,rainbow_colours[i%len(rainbow_colours)])foriinrange(Message.MAX_COLUMNS)]p=Program((TextMessage("Here comes the rainbow!",message_style=MessageStyle.Flash,open_transition=OpenTransition.DownUp,close_transition=CloseTransition.DownUp),Message(rainbow,message_style=MessageStyle.Clockwise,open_transition=OpenTransition.FromMiddle,close_transition=CloseTransition.ToMiddle),))# Open the device and programd=Device()d.program(p)