USB Host Shield 2.0
PSBuzz.h
Go to the documentation of this file.
1 /* Copyright (C) 2014 Kristian Lauszus, TKJ Electronics. 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 Lauszus, TKJ Electronics
14  Web : http://www.tkjelectronics.com
15  e-mail : kristianl@tkjelectronics.com
16  */
17 
18 #ifndef _psbuzz_h_
19 #define _psbuzz_h_
20 
21 #include "hiduniversal.h"
22 #include "controllerEnums.h"
23 
24 #define PSBUZZ_VID 0x054C // Sony Corporation
25 #define PSBUZZ_PID 0x1000 // PS Buzz Controller
26 
29  struct {
30  uint8_t red : 1;
31  uint8_t yellow : 1;
32  uint8_t green : 1;
33  uint8_t orange : 1;
34  uint8_t blue : 1;
35  } __attribute__((packed)) btn[4];
36  uint32_t val : 20;
37 } __attribute__((packed));
38 
43 class PSBuzz : public HIDUniversal {
44 public:
49  PSBuzz(USB *p) :
50  HIDUniversal(p) {
51  Reset();
52  };
53 
58  bool connected() {
60  };
61 
66  void attachOnInit(void (*funcOnInit)(void)) {
67  pFuncOnInit = funcOnInit;
68  };
69 
82  bool getButtonPress(ButtonEnum b, uint8_t controller = 0);
83  bool getButtonClick(ButtonEnum b, uint8_t controller = 0);
95  void setLedRaw(bool value, uint8_t controller = 0);
96 
98  void setLedOffAll() {
99  for (uint8_t i = 1; i < 4; i++) // Skip first as it will be set in setLedRaw
100  ledState[i] = false; // Just an easy way to set all four off at the same time
101  setLedRaw(false); // Turn the LED off, on all four controllers
102  };
103 
108  void setLedOff(uint8_t controller = 0) {
109  setLedRaw(false, controller);
110  };
111 
112 
114  void setLedOnAll() {
115  for (uint8_t i = 1; i < 4; i++) // Skip first as it will be set in setLedRaw
116  ledState[i] = true; // Just an easy way to set all four off at the same time
117  setLedRaw(true); // Turn the LED on, on all four controllers
118  };
119 
124  void setLedOn(uint8_t controller = 0) {
125  setLedRaw(true, controller);
126  };
127 
132  void setLedToggle(uint8_t controller = 0) {
133  setLedRaw(!ledState[controller], controller);
134  };
137 protected:
146  void ParseHIDData(USBHID *hid, bool is_rpt_id, uint8_t len, uint8_t *buf);
147 
153  uint8_t OnInitSuccessful();
157  void Reset() {
158  psbuzzButtons.val = 0;
159  oldButtonState.val = 0;
160  buttonClickState.val = 0;
161  for (uint8_t i = 0; i < sizeof(ledState); i++)
162  ledState[i] = 0;
163  };
164 
172  virtual bool VIDPIDOK(uint16_t vid, uint16_t pid) {
173  return (vid == PSBUZZ_VID && pid == PSBUZZ_PID);
174  };
177 private:
178  static int8_t getButtonIndexBuzz(ButtonEnum b);
179 
180  void (*pFuncOnInit)(void); // Pointer to function called in onInit()
181 
182  void PSBuzz_Command(uint8_t *data, uint16_t nbytes);
183 
184  PSBUZZButtons psbuzzButtons, oldButtonState, buttonClickState;
185  bool ledState[4];
186 };
187 #endif
#define PSBUZZ_PID
Definition: PSBuzz.h:25
#define PSBUZZ_VID
Definition: PSBuzz.h:24
uint16_t PID
Definition: hidcomposite.h:71
virtual bool isReady()
Definition: hidcomposite.h:99
uint16_t VID
Definition: hidcomposite.h:71
Definition: PSBuzz.h:43
void setLedOff(uint8_t controller=0)
Definition: PSBuzz.h:108
PSBuzz(USB *p)
Definition: PSBuzz.h:49
void attachOnInit(void(*funcOnInit)(void))
Definition: PSBuzz.h:66
void setLedOffAll()
Definition: PSBuzz.h:98
bool getButtonPress(ButtonEnum b, uint8_t controller=0)
Definition: PSBuzz.cpp:58
void Reset()
Definition: PSBuzz.h:157
void setLedOn(uint8_t controller=0)
Definition: PSBuzz.h:124
void ParseHIDData(USBHID *hid, bool is_rpt_id, uint8_t len, uint8_t *buf)
Definition: PSBuzz.cpp:23
bool connected()
Definition: PSBuzz.h:58
void setLedToggle(uint8_t controller=0)
Definition: PSBuzz.h:132
void setLedOnAll()
Definition: PSBuzz.h:114
bool getButtonClick(ButtonEnum b, uint8_t controller=0)
Definition: PSBuzz.cpp:63
uint8_t OnInitSuccessful()
Definition: PSBuzz.cpp:41
virtual bool VIDPIDOK(uint16_t vid, uint16_t pid)
Definition: PSBuzz.h:172
void setLedRaw(bool value, uint8_t controller=0)
Definition: PSBuzz.cpp:72
Definition: usbhid.h:143
Definition: UsbCore.h:218
ButtonEnum
uint8_t blue
Definition: PSBuzz.h:34
uint8_t yellow
Definition: PSBuzz.h:31
uint8_t orange
Definition: PSBuzz.h:33
uint8_t red
Definition: PSBuzz.h:30
struct PSBUZZButtons::@39 btn[4]
uint8_t green
Definition: PSBuzz.h:32
uint32_t val
Definition: PSBuzz.h:36