Subversion Repositories Projects

Rev

Rev 213 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
230 dhylands 1
/****************************************************************************
2
*
3
*   Copyright (c) 2009 Dave Hylands     <dhylands@gmail.com>
4
*
5
*   This program is free software; you can redistribute it and/or modify
6
*   it under the terms of the GNU General Public License version 2 as
7
*   published by the Free Software Foundation.
8
*
9
*   Alternatively, this software may be distributed under the terms of BSD
10
*   license.
11
*
12
*   See README and COPYING for more details.
13
*
14
****************************************************************************/
15
/**
16
*
17
*   @file   BioloidDevice.h
18
*
19
*   @brief  Contains definitions for the bioloid generic command interface.
20
*
21
****************************************************************************/
22
 
23
#if !defined( BIOLOIDDEVICE_H )
24
#define BIOLOIDDEVICE_H       /**< Include Guard                             */
25
 
26
// ---- Include Files -------------------------------------------------------
27
 
28
#include <stdint.h>
29
 
30
#include "Bioloid.h"
31
#include "BioloidBus.h"
32
 
33
/**
34
 * @addtogroup bioloid
35
 * @{
36
 */
37
 
38
class BioloidDevice
39
{
40
public:
41
    //------------------------------------------------------------------------
42
    // Default constructor
43
 
44
    BioloidDevice();
45
 
46
    //------------------------------------------------------------------------
47
    // Normal constructor
48
 
49
    BioloidDevice( BioloidBus *bus, Bioloid::ID_t id );
50
 
51
    //------------------------------------------------------------------------
52
    // Destructor
53
 
54
    virtual ~BioloidDevice();
55
 
56
    //------------------------------------------------------------------------
57
    // Returns the ID of this device.
58
 
59
    Bioloid::ID_t ID() const { return m_id; }
60
 
61
    //------------------------------------------------------------------------
62
    // Pings the device and waits for a status packet.
63
 
64
    Bioloid::Error Ping();
65
 
66
    //------------------------------------------------------------------------
67
    // Reads data from the devices control table.
68
 
69
    Bioloid::Error Read( uint8_t offset, void *data, uint8_t numBytes );
70
 
71
    //------------------------------------------------------------------------
72
    // Reads an 8 bit data register
73
 
74
    Bioloid::Error Read( uint8_t offset, uint8_t *val );
75
    Bioloid::Error Read( uint8_t offset, uint16_t *val );
76
 
77
    //------------------------------------------------------------------------
78
    // Resets the control table to factory defaults.
79
 
80
    Bioloid::Error Reset();
81
 
82
    //------------------------------------------------------------------------
83
    // Sends a ping packet to this device
84
 
85
    void SendPing();
86
 
87
    //------------------------------------------------------------------------
88
    // Sends a request to read data from the devices control table
89
 
90
    void SendRead( uint8_t offset, uint8_t numBytes );
91
 
92
    //------------------------------------------------------------------------
93
    // Sends some data to write into the control table.
94
 
95
    void SendWrite( uint8_t offset, const void *data, uint8_t numBytes );
96
 
97
    //------------------------------------------------------------------------
98
    // Sends some data to write into the control table. The write into the
99
    // control table will be deferred until the ACTION command is sent.
100
 
101
    void SendDeferredWrite( uint8_t offset, const void *data, uint8_t numBytes );
102
 
103
    //------------------------------------------------------------------------
104
    // Sends a commands to reset the control table to factory defaults.
105
 
106
    void SendReset();
107
 
108
    //------------------------------------------------------------------------
109
    // Sets the Bus and ID
110
 
111
    void SetBusAndID( BioloidBus *bus, Bioloid::ID_t id )
112
    {
113
        m_bus = bus;
114
        m_id = id;
115
    }
116
 
117
    //------------------------------------------------------------------------
118
    // Writes some data into the control table, and returns the result.
119
 
120
    Bioloid::Error Write( uint8_t offset, const void *data, uint8_t numBytes );
121
 
122
protected:
123
 
124
    //------------------------------------------------------------------------
125
 
126
    BioloidBus     *m_bus;
127
    Bioloid::ID_t   m_id;   // The ID of this device
128
 
129
private:
130
 
131
    //------------------------------------------------------------------------
132
    // The copy constructor and assignment operator are not need for this
133
    // class so we declare them private and don't provide an implementation.
134
 
135
    BioloidDevice( const BioloidDevice & copy );
136
    BioloidDevice &operator =( const BioloidDevice &rhs );
137
};
138
 
139
// ---- Inline Functions ----------------------------------------------------
140
 
141
/** @} */
142
 
143
#endif /* BIOLOIDDEVICE_H */
144