USB Host Shield 2.0
MiniDSP.h
Go to the documentation of this file.
1 /* Copyright (C) 2021 Kristian Sloth Lauszus and Dennis Frett. All rights reserved.
2 
3  This software may be distributed and modified under the terms of the GNU
4  General Public License version 2 (GPL2) as published by the Free Software
5  Foundation and appearing in the file GPL2.TXT included in the packaging of
6  this file. Please note that GPL2 Section 2[b] requires that all works based
7  on this software must also be made publicly available under the terms of
8  the GPL2 ("Copyleft").
9 
10  Contact information
11  -------------------
12 
13  Kristian Sloth Lauszus
14  Web : https://lauszus.com
15  e-mail : lauszus@gmail.com
16 
17  Dennis Frett
18  GitHub : https://github.com/dennisfrett
19  e-mail : dennis.frett@live.com
20  */
21 
22 #pragma once
23 
24 #include "hiduniversal.h"
25 
26 #define MINIDSP_VID 0x2752 // MiniDSP
27 #define MINIDSP_PID 0x0011 // MiniDSP 2x4HD
28 
39 class MiniDSP : public HIDUniversal {
40 public:
41 
47  };
48 
53  bool connected() {
55  };
56 
62  void attachOnInit(void (*funcOnInit)(void)) {
63  pFuncOnInit = funcOnInit;
64  };
65 
72  void attachOnVolumeChange(void (*funcOnVolumeChange)(uint8_t)) {
73  pFuncOnVolumeChange = funcOnVolumeChange;
74  }
75 
82  void attachOnMutedChange(void (*funcOnMutedChange)(bool)) {
83  pFuncOnMutedChange = funcOnMutedChange;
84  }
85 
92  int getVolume() const {
93  return volume;
94  }
95 
100  float getVolumeDB() const {
101  return volume / -2.0;
102  }
103 
108  bool isMuted() const {
109  return muted;
110  }
111 
112 protected:
121  void ParseHIDData(USBHID *hid, bool is_rpt_id, uint8_t len, uint8_t *buf);
122 
129  uint8_t OnInitSuccessful();
141  virtual bool VIDPIDOK(uint16_t vid, uint16_t pid) {
142  return vid == MINIDSP_VID && pid == MINIDSP_PID;
143  };
146 private:
153  uint8_t Checksum(const uint8_t *data, uint8_t data_length) const;
154 
159  void
160  RequestStatus() const;
161 
169  void SendCommand(uint8_t *command, uint8_t command_length) const;
170 
171  // Callbacks
172 
173  // Pointer to function called in onInit().
174  void (*pFuncOnInit)(void) = nullptr;
175 
176  // Pointer to function called when volume changes.
177  void (*pFuncOnVolumeChange)(uint8_t) = nullptr;
178 
179  // Pointer to function called when muted status changes.
180  void (*pFuncOnMutedChange)(bool) = nullptr;
181 
182  // -----------------------------------------------------------------------------
183 
184  // MiniDSP state. Currently only volume and muted status are
185  // implemented, but others can be added easily if needed.
186 
187  // The volume is stored as an unsigned integer that represents twice the
188  // -dB value. Example: 19 represents -9.5dB.
189  uint8_t volume = 0;
190  bool muted = false;
191 };
#define MINIDSP_PID
Definition: MiniDSP.h:27
#define MINIDSP_VID
Definition: MiniDSP.h:26
uint16_t PID
Definition: hidcomposite.h:71
virtual bool isReady()
Definition: hidcomposite.h:99
uint16_t VID
Definition: hidcomposite.h:71
bool isMuted() const
Definition: MiniDSP.h:108
int getVolume() const
Definition: MiniDSP.h:92
void attachOnInit(void(*funcOnInit)(void))
Definition: MiniDSP.h:62
MiniDSP(USB *p)
Definition: MiniDSP.h:46
uint8_t OnInitSuccessful()
Definition: MiniDSP.cpp:57
void attachOnVolumeChange(void(*funcOnVolumeChange)(uint8_t))
Definition: MiniDSP.h:72
void attachOnMutedChange(void(*funcOnMutedChange)(bool))
Definition: MiniDSP.h:82
float getVolumeDB() const
Definition: MiniDSP.h:100
void ParseHIDData(USBHID *hid, bool is_rpt_id, uint8_t len, uint8_t *buf)
Definition: MiniDSP.cpp:24
virtual bool VIDPIDOK(uint16_t vid, uint16_t pid)
Definition: MiniDSP.h:141
bool connected()
Definition: MiniDSP.h:53
Definition: usbhid.h:143
Definition: UsbCore.h:212