1////////////////////////////////////////////////////////////////////////////////
2// //
3// This software is supplied under the terms of a license agreement or //
4// nondisclosure agreement with Mitov Software and may not be copied //
5// or disclosed except in accordance with the terms of that agreement. //
6// Copyright(c) 2002-2016 Mitov Software. All Rights Reserved. //
7// //
8////////////////////////////////////////////////////////////////////////////////
9
10#ifndef _MITOV_PS2_CONTROLLER_h
11#define _MITOV_PS2_CONTROLLER_h
12
13#include <Mitov.h>
14#include <Mitov_PS2_Controller_Basic.h>
15#include <PS2X_lib.h>
16
17namespace Mitov
18{
19 class PS2BasicControllerDirect : public Mitov::PS2BasicController
20 {
21 typedef Mitov::PS2BasicController inherited;
22
23 protected:
24 PS2X Fps2x;
25
26 public:
27 virtual bool ReadDigital( unsigned int AIndex )
28 {
29 return Fps2x.Button( AIndex );
30 }
31
32 virtual float ReadAnalog( unsigned int AIndex )
33 {
34 return ((float)Fps2x.Analog( AIndex )) / 255;
35 }
36
37 public:
38 PS2BasicControllerDirect( int ADataPinNumber, int ACommandPinNumber, int AAttentionPinNumber, int AClockPinNumber )
39 {
40 Fps2x.config_gamepad( AClockPinNumber, ACommandPinNumber, AAttentionPinNumber, ADataPinNumber, true, true );
41 }
42
43 };
44//---------------------------------------------------------------------------
45 class PS2Controller : public PS2BasicControllerDirect
46 {
47 typedef PS2BasicControllerDirect inherited;
48
49 public:
50 OpenWire::SinkPin SmallVibrateMotorInputPin;
51 OpenWire::SinkPin LargeVibrateMotorInputPin;
52
53 protected:
54 bool FSmallMotor = false;
55 int8_t FLargeMotor = 0;
56
57 protected:
58 void DoSmallVibrateMotorReceive( void *_Data )
59 {
60 FSmallMotor = *(bool *)_Data;
61 }
62
63 void DoLargeVibrateMotorReceive( void *_Data )
64 {
65 FLargeMotor = (int8_t)( constrain( *(float *)_Data, 0, 1 ) * 255 + 0.5 );
66 }
67
68 virtual void ReadController() override
69 {
70 Fps2x.read_gamepad( FSmallMotor, FLargeMotor );
71 }
72
73 public:
74 PS2Controller( int ADataPinNumber, int ACommandPinNumber, int AAttentionPinNumber, int AClockPinNumber ) :
75 inherited( ADataPinNumber, ACommandPinNumber, AAttentionPinNumber, AClockPinNumber )
76 {
77 SmallVibrateMotorInputPin.SetCallback( MAKE_CALLBACK( PS2Controller::DoSmallVibrateMotorReceive ));
78 LargeVibrateMotorInputPin.SetCallback( MAKE_CALLBACK( PS2Controller::DoLargeVibrateMotorReceive ));
79 }
80
81 };
82//---------------------------------------------------------------------------
83 class PS2Guitar : public PS2BasicControllerDirect
84 {
85 typedef PS2BasicControllerDirect inherited;
86
87 virtual void ReadController() override
88 {
89 Fps2x.read_gamepad( false, 0 );
90 }
91
92 public:
93 using inherited::inherited;
94
95 };
96//---------------------------------------------------------------------------
97}
98
99#endif