Code Monkey home page Code Monkey logo

hidpowerdevice's Introduction

HID UPS Power Device Library for Arduino

This library allows an Arduino board with USB capabilities to act as a HID-compliant UPS according to USB HID specifications. The library is useful if you want to build a smart UPS or other power device, which can report its state to the PC host or perform power on/power off operations as necessary for your project.

For more information about USB HID specs please read https://www.usb.org/sites/default/files/pdcv11.pdf

Supported Arduinos

  • Leonardo

  • (Pro)Micro

Setup & Usage

Setup is very simple. Just clone this repository to Arduino libraries, then upload the sketch UPS.ino from the /examples folder. Once upload is completed successfully you will find HID Device Battery in your system.

Additional setup step on Linux hosts

Copy linux/98-upower-hid.rules file to the /etc/udev/rules.d/ folder , then reboot. This is required for Linux device manager (udev) to recognize the Arduino board as UPS.

Tested on Operating Systems

  • Mac OSX 10.14.6 Mojave

  • Ubuntu 18.04.05 LTS

  • Windows 10

License

Copyright (c) Alex Bratchik 2020. All right reserved.

This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation; either version 2.1 of the License, or (at your option) any later version.

This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.

You should have received a copy of the GNU Lesser General Public License along with this library; if not, write to the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA

hidpowerdevice's People

Contributors

abratchik avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

hidpowerdevice's Issues

Adapting to ATtiny85 (Digispark) and V-USB to get around CDC?

I love the concept of this project and it saves me from needing to duplicate the effort but I was wondering if you have considered using an ATtiny85 board (like a digispark) as a minimal solution with V-USB?

I think this may get around the CDC issue until the other MR's get resolved and up-streamed and into device code (like in a NAS).

Trigger shutdown via ups

Hi, thanks for the fantastic work so far!

I'm currently testing out the library to see if it can do everything I need for an upcoming project but so far I've been unable to trigger a shutdown so I was hoping for some advice on what I might be doing wrong?

I'm currently testing in windows and the battery percentage, time remaining etc is all working nicely. I have been able to trigger a shutdown by artificially setting the battery percentage below the shutdown threshold but that is relying on the settings being correct in the OS so I would rather use the inbuilt method if possible.

I've tried setting iDelayBe4ShutDown to something greater than 0. This appears to trigger the program to set the SHUTDOWNREQ and SHUTDOWNIMNT bits but then nothing happens after that. I've also tried setting the charging and AC present status to false incase that is preventing the shutdown from working so I'm not sure what else I could be missing.

The PC I'm testing on is a windows 11 desktop, so there are no other batteries present to confuse it.

hid device name

i tried compiling your project to see if you manage to rename hid device what i read somewhere
Thinking i wanned to make a fork for ArduinoJoystickLibrary being able to set device name and vendor and serial name
would be very awesome.

but i get a compilations errors.


C:\Users\Pascal\AppData\Local\Temp\ccG1kOv9.ltrans0.ltrans.o: In function `HIDPowerDevice_::setFeature(unsigned int, void const*, int) [clone .constprop.30]':
C:\Users\Pascal\Downloads\HIDPowerDevice-master\HIDPowerDevice-master\src\UPS/HIDPowerDevice.cpp:263: undefined reference to `HID()'
C:\Users\Pascal\Downloads\HIDPowerDevice-master\HIDPowerDevice-master\src\UPS/HIDPowerDevice.cpp:263: undefined reference to `HID_::SetFeature(unsigned int, void const*, int)'
C:\Users\Pascal\AppData\Local\Temp\ccG1kOv9.ltrans0.ltrans.o: In function `HIDPowerDevice_::setStringFeature(unsigned char, unsigned char const*, char const*) [clone .constprop.29]':
C:\Users\Pascal\Downloads\HIDPowerDevice-master\HIDPowerDevice-master\src\UPS/HIDPowerDevice.cpp:268: undefined reference to `HID()'
C:\Users\Pascal\Downloads\HIDPowerDevice-master\HIDPowerDevice-master\src\UPS/HIDPowerDevice.cpp:268: undefined reference to `HID_::SetFeature(unsigned int, void const*, int)'
C:\Users\Pascal\Downloads\HIDPowerDevice-master\HIDPowerDevice-master\src\UPS/HIDPowerDevice.cpp:272: undefined reference to `HID()'
C:\Users\Pascal\Downloads\HIDPowerDevice-master\HIDPowerDevice-master\src\UPS/HIDPowerDevice.cpp:272: undefined reference to `HID_::SetFeature(unsigned int, void const*, int)'
C:\Users\Pascal\AppData\Local\Temp\ccG1kOv9.ltrans0.ltrans.o: In function `global constructors keyed to 65535_0_HIDPowerDevice.cpp.o.2156':
<artificial>:(.text.startup+0x76): undefined reference to `HID()'
<artificial>:(.text.startup+0x7e): undefined reference to `HID_::AppendDescriptor(HIDSubDescriptor*)'
C:\Users\Pascal\AppData\Local\Temp\ccG1kOv9.ltrans0.ltrans.o: In function `begin':
C:\Users\Pascal\Downloads\HIDPowerDevice-master\HIDPowerDevice-master\src\UPS/HIDPowerDevice.cpp:232: undefined reference to `HID()'
C:\Users\Pascal\Downloads\HIDPowerDevice-master\HIDPowerDevice-master\src\UPS/HIDPowerDevice.cpp:232: undefined reference to `HID_::begin()'
C:\Users\Pascal\Downloads\HIDPowerDevice-master\HIDPowerDevice-master\src\UPS/HIDPowerDevice.cpp:236: undefined reference to `HID()'
C:\Users\Pascal\Downloads\HIDPowerDevice-master\HIDPowerDevice-master\src\UPS/HIDPowerDevice.cpp:236: undefined reference to `HID_::SetFeature(unsigned int, void const*, int)'
C:\Users\Pascal\Downloads\HIDPowerDevice-master\HIDPowerDevice-master\src\UPS/HIDPowerDevice.cpp:237: undefined reference to `HID()'
C:\Users\Pascal\Downloads\HIDPowerDevice-master\HIDPowerDevice-master\src\UPS/HIDPowerDevice.cpp:237: undefined reference to `HID_::SetFeature(unsigned int, void const*, int)'
C:\Users\Pascal\Downloads\HIDPowerDevice-master\HIDPowerDevice-master\src\UPS/HIDPowerDevice.cpp:238: undefined reference to `HID()'
C:\Users\Pascal\Downloads\HIDPowerDevice-master\HIDPowerDevice-master\src\UPS/HIDPowerDevice.cpp:238: undefined reference to `HID_::SetFeature(unsigned int, void const*, int)'
C:\Users\Pascal\AppData\Local\Temp\ccG1kOv9.ltrans0.ltrans.o: In function `setSerial':
C:\Users\Pascal\Downloads\HIDPowerDevice-master\HIDPowerDevice-master\src\UPS/HIDPowerDevice.cpp:247: undefined reference to `HID()'
C:\Users\Pascal\AppData\Local\Temp\ccG1kOv9.ltrans0.ltrans.o: In function `setOutput':
C:\Users\Pascal\Downloads\HIDPowerDevice-master\HIDPowerDevice-master\src\UPS/HIDPowerDevice.cpp:243: undefined reference to `HID()'
C:\Users\Pascal\AppData\Local\Temp\ccG1kOv9.ltrans0.ltrans.o: In function `sendReport':
C:\Users\Pascal\Downloads\HIDPowerDevice-master\HIDPowerDevice-master\src\UPS/HIDPowerDevice.cpp:259: undefined reference to `HID()'
C:\Users\Pascal\Downloads\HIDPowerDevice-master\HIDPowerDevice-master\src\UPS/HIDPowerDevice.cpp:259: undefined reference to `HID_::SendReport(unsigned int, void const*, int)'
C:\Users\Pascal\Downloads\HIDPowerDevice-master\HIDPowerDevice-master\src\UPS/HIDPowerDevice.cpp:259: undefined reference to `HID()'
C:\Users\Pascal\Downloads\HIDPowerDevice-master\HIDPowerDevice-master\src\UPS/HIDPowerDevice.cpp:259: undefined reference to `HID_::SendReport(unsigned int, void const*, int)'
C:\Users\Pascal\Downloads\HIDPowerDevice-master\HIDPowerDevice-master\src\UPS/HIDPowerDevice.cpp:259: undefined reference to `HID()'
C:\Users\Pascal\Downloads\HIDPowerDevice-master\HIDPowerDevice-master\src\UPS/HIDPowerDevice.cpp:259: undefined reference to `HID_::SendReport(unsigned int, void const*, int)'
collect2.exe: error: ld returned 1 exit status
exit status 1
Error compiling for board Arduino Micro.

MHeironimus/ArduinoJoystickLibrary#14

any help would be cool thnx

LIB HID GENERIC ?

Hello,

I want to make a communication between an arduino micro pro and a vive tracker in USB HID, do you think I could use your library HID.h/HID.c as a generic library to do that ?

I have to send some particular descriptor to be able to communicate.

image

regards

Linux / rPi not working with Pro Micro 3.3V 8MHz

Positive ๐Ÿ‘
Got it working on Pro Micro Clone with 3.3V @8MHz & 5V @16mhz

  • install and identify Pro Micro 3.3V @8MHz by board manager (see SparkFun Docs) to get correct bootloader
  • or as Leonardo 5V @16mhz
  • works on Win10 bare and within VM
  • works on Mac OS X Big Sur & Mac OS X Catalina on Mac Book

issue :

on linux system one has to add / change the VID & PID related to used clone / firmware
For SparkFun Pro Micro 3.3V @8MHz is as follows :

ATTRS{idVendor}=="1b4f", ATTRS{idProduct}=="9204", ENV{UPOWER_BATTERY_TYPE}="ups"

But still (Ubuntu 20) on rPI4 refuses to load usbhid-lib for NUT support.

Double checked all blacklist.rules and did find other vid/pid to be blocked, but not this one.

Any idea ?
Did anyone get it running with NUT & usbhid-ups?
Do I have to use another driver interface?
Or other SW package ?

How compile for 16.5MHz?

I use Digispark.

Error in compilation

In file included from D:\Documents\Arduino\libraries\HIDPowerDevice/HIDPowerDevice.h:29:0, from D:\Documents\Arduino\libraries\HIDPowerDevice\examples\UPS\UPS.ino:1: D:\Documents\Arduino\libraries\HIDPowerDevice/HID/HID.h:26:26: fatal error: PluggableUSB.h: No such file or directory #include <PluggableUSB.h> ^ compilation terminated. exit status 1 Error compilation for board Digispark (Default - 16.5mhz).

Adapting to RP2040

With the RP2040 having USB support and able to be used as a USB HID device elsewhere, would it be possible to adapt this to that chip? I've attempted to run it as is, but it appears to not like the pluggableusb library.

Attempting to use with NUT (Ubuntu) or Synology

Thank you for your great work, we are looking to do the same thing and I have purchased a Leonardo to match what you have done so far.

I have a goal of adding support for this to a Synology, which uses nut but with what I think are some custom wrappers around it which make it a bit confusing, so let's leave that alone for now and I am using a stock Ubuntu 22.04 install. I have added the 98-upower-hid.rules file, and I think it is reporting correctly now to the system:

$ upower -e
/org/freedesktop/UPower/devices/ups_hiddev0
/org/freedesktop/UPower/devices/DisplayDevice

$ upower -i /org/freedesktop/UPower/devices/ups_hiddev0
  native-path:          /sys/devices/pci0000:00/0000:00:14.0/usb1/1-1/1-1:1.2/usbmisc/hiddev0
  vendor:               CPS
  model:                Arduino Leonardo
  serial:               PQ8BO2000467
  power supply:         yes
  updated:              Fri 10 Nov 2023 12:39:20 PM CST (16 seconds ago)
  has history:          yes
  has statistics:       yes
  ups
    present:             yes
    state:               discharging
    warning-level:       discharging
    time to empty:       1.5 hours
    percentage:          76%
    icon-name:          'battery-full-symbolic'

However, when attempting to configure nut, it seems it isn't getting detected correctly. Have you tried to use this with nut? Here are some output showing my confusion:

$ nut-scanner -U
Neon library not found. XML search disabled.
IPMI library not found. IPMI search disabled.
Scanning USB bus.
<nothing more so I think it isn't detected>

I have attempted to setup the various files in /etc/nut/ but without the scanner detecting it I think I can't get anywhere with it. Thanks for any guidance, and thanks again for the great work!

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.