Open Lighting Architecture  0.9.5
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
KarateLight.h
1 /*
2  * This program is free software; you can redistribute it and/or modify
3  * it under the terms of the GNU General Public License as published by
4  * the Free Software Foundation; either version 2 of the License, or
5  * (at your option) any later version.
6  *
7  * This program is distributed in the hope that it will be useful,
8  * but WITHOUT ANY WARRANTY; without even the implied warranty of
9  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10  * GNU Library General Public License for more details.
11  *
12  * You should have received a copy of the GNU General Public License
13  * along with this program; if not, write to the Free Software
14  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
15  *
16  * KarateLight.h
17  * The KarateLight communication class
18  * Copyright (C) 2013 Carsten Presser
19  */
20 #ifndef PLUGINS_KARATE_KARATELIGHT_H_
21 #define PLUGINS_KARATE_KARATELIGHT_H_
22 
23 #include <stdint.h>
24 #include <string>
25 
26 #include "ola/Constants.h"
27 #include "ola/DmxBuffer.h"
28 
29 namespace ola {
30 namespace plugin {
31 namespace karate {
32 
33 class KarateLight {
34  public:
35  explicit KarateLight(const std::string &dev);
36  ~KarateLight();
37  bool Init();
38  void Close();
39 
40  bool Blank();
41  bool SetColors(const DmxBuffer &da);
42 
43  uint16_t GetnChannels() const { return m_nChannels; }
44  uint8_t GetFWVersion() const { return m_fw_version; }
45  uint8_t GetHWVersion() const { return m_hw_version; }
46  uint16_t GetDMXOffset() const { return m_dmx_offset; }
47  bool IsActive() const { return m_active; }
48 
49  private:
50  bool ReadBack(uint8_t *rd_data, uint8_t *rd_len);
51  bool ReadByteFromEeprom(uint8_t addr, uint8_t *data);
52  bool SendCommand(uint8_t cmd, const uint8_t *output_buffer,
53  int n_bytes_to_write, uint8_t *input_buffer,
54  int n_bytes_expected);
55  bool UpdateColors();
56 
57  const std::string m_devname;
58  int m_fd;
59 
60  static const uint16_t CMD_MAX_LENGTH = 64;
61  static const uint16_t CHUNK_SIZE = 32;
62 
63  uint8_t m_fw_version;
64  uint8_t m_hw_version;
65  uint16_t m_nChannels;
66  uint16_t m_dmx_offset;
67 
68  uint8_t m_color_buffer[DMX_UNIVERSE_SIZE];
69  uint8_t m_color_buffer_old[DMX_UNIVERSE_SIZE];
70  uint8_t m_use_memcmp;
71 
72  bool m_active;
73 
74  // address
75  static const uint8_t CMD_HD_SYNC = 0x00;
76  static const uint8_t CMD_HD_COMMAND = 0x01;
77  static const uint8_t CMD_HD_CHECK = 0x02;
78  static const uint8_t CMD_HD_LEN = 0x03;
79  static const uint8_t CMD_DATA_START = 0x04;
80 
81  // sync words
82  static const uint8_t CMD_SYNC_SEND = 0xAA;
83  static const uint8_t CMD_SYNC_RECV = 0x55;
84 
85  // status
86  static const uint8_t CMD_SYS_ACK = 0x01;
87  static const uint8_t CMD_SYS_NACK = 0x02;
88  static const uint8_t CMD_SYS_NIMP = 0xFF;
89  static const uint8_t CMD_SYS_IR = 0x10;
90  static const uint8_t CMD_SYS_DATA = 0x20;
91  static const uint8_t CMD_SYS_NACK_LENGTH = 0x03;
92  static const uint8_t CMD_SYS_NACK_CHECK = 0x04;
93 
94  // commands
95  static const uint8_t CMD_GET_VERSION = 0x01;
96  static const uint8_t CMD_GET_HARDWARE = 0x02;
97 
98  static const uint8_t CMD_GET_TLC_PWM_VALUE = 0x14;
99  static const uint8_t CMD_SET_TLC_PWM_VALUE = 0x15;
100 
101  static const uint8_t CMD_SET_DATA_00 = 0x20;
102  static const uint8_t CMD_SET_DATA_01 = 0x21;
103  static const uint8_t CMD_SET_DATA_02 = 0x22;
104  static const uint8_t CMD_SET_DATA_03 = 0x23;
105  static const uint8_t CMD_SET_DATA_04 = 0x24;
106  static const uint8_t CMD_SET_DATA_05 = 0x25;
107  static const uint8_t CMD_SET_DATA_06 = 0x26;
108  static const uint8_t CMD_SET_DATA_07 = 0x27;
109  static const uint8_t CMD_SET_DATA_08 = 0x28;
110  static const uint8_t CMD_SET_DATA_09 = 0x29;
111  static const uint8_t CMD_SET_DATA_0A = 0x2A;
112  static const uint8_t CMD_SET_DATA_0B = 0x2B;
113  static const uint8_t CMD_SET_DATA_0C = 0x2C;
114  static const uint8_t CMD_SET_DATA_0D = 0x2D;
115  static const uint8_t CMD_SET_DATA_0E = 0x2E;
116  static const uint8_t CMD_SET_DATA_0F = 0x2F;
117 
118  static const uint8_t CMD_GET_N_CHANNELS = 0x30;
119 
120  static const uint8_t CMD_READ_ADC0 = 0x40;
121 
122  static const uint8_t CMD_READ_EEPROM = 0x50;
123  static const uint8_t CMD_WRITE_EEPROM = 0x51;
124 
125  static const uint8_t CMD_BOOT_REQUEST = 0x80;
126  static const uint8_t CMD_BOOT_START = 0x81;
127 
128  static const uint8_t HW_ID_KARATE = 0x01;
129  static const uint8_t HW_ID_USB2DMX = 0x02;
130 };
131 } // namespace karate
132 } // namespace plugin
133 } // namespace ola
134 
135 #endif // PLUGINS_KARATE_KARATELIGHT_H_