Open Lighting Architecture
 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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, 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/BaseTypes.h"
27 #include "ola/DmxBuffer.h"
28 
29 using std::string;
30 
31 namespace ola {
32 namespace plugin {
33 namespace karate {
34 
35 class KarateLight {
36  public:
37  explicit KarateLight(const string &dev);
38  ~KarateLight();
39  bool Init();
40  void Close();
41 
42  bool Blank();
43  bool SetColors(const DmxBuffer &da);
44 
45  uint16_t GetnChannels() const { return m_nChannels; }
46  uint8_t GetFWVersion() const { return m_fw_version; }
47  uint8_t GetHWVersion() const { return m_hw_version; }
48  uint16_t GetDMXOffset() const { return m_dmx_offset; }
49  bool IsActive() const { return m_active; }
50 
51  private:
52  bool ReadBack(uint8_t *rd_data, uint8_t *rd_len);
53  bool ReadByteFromEeprom(uint8_t addr, uint8_t *data);
54  bool SendCommand(uint8_t cmd, const uint8_t *output_buffer,
55  int n_bytes_to_write, uint8_t *input_buffer,
56  int n_bytes_expected);
57  bool UpdateColors();
58 
59  const string m_devname;
60  int m_fd;
61 
62  static const uint16_t CMD_MAX_LENGTH = 64;
63  static const uint16_t CHUNK_SIZE = 32;
64 
65  uint8_t m_fw_version;
66  uint8_t m_hw_version;
67  uint16_t m_nChannels;
68  uint16_t m_dmx_offset;
69 
70  uint8_t m_color_buffer[DMX_UNIVERSE_SIZE];
71  uint8_t m_color_buffer_old[DMX_UNIVERSE_SIZE];
72  uint8_t m_use_memcmp;
73 
74  bool m_active;
75 
76  // address
77  static const uint8_t CMD_HD_SYNC = 0x00;
78  static const uint8_t CMD_HD_COMMAND = 0x01;
79  static const uint8_t CMD_HD_CHECK = 0x02;
80  static const uint8_t CMD_HD_LEN = 0x03;
81  static const uint8_t CMD_DATA_START = 0x04;
82 
83  // sync words
84  static const uint8_t CMD_SYNC_SEND = 0xAA;
85  static const uint8_t CMD_SYNC_RECV = 0x55;
86 
87  // status
88  static const uint8_t CMD_SYS_ACK = 0x01;
89  static const uint8_t CMD_SYS_NACK = 0x02;
90  static const uint8_t CMD_SYS_NIMP = 0xFF;
91  static const uint8_t CMD_SYS_IR = 0x10;
92  static const uint8_t CMD_SYS_DATA = 0x20;
93  static const uint8_t CMD_SYS_NACK_LENGTH = 0x03;
94  static const uint8_t CMD_SYS_NACK_CHECK = 0x04;
95 
96  // commands
97  static const uint8_t CMD_GET_VERSION = 0x01;
98  static const uint8_t CMD_GET_HARDWARE = 0x02;
99 
100  static const uint8_t CMD_GET_TLC_PWM_VALUE = 0x14;
101  static const uint8_t CMD_SET_TLC_PWM_VALUE = 0x15;
102 
103  static const uint8_t CMD_SET_DATA_00 = 0x20;
104  static const uint8_t CMD_SET_DATA_01 = 0x21;
105  static const uint8_t CMD_SET_DATA_02 = 0x22;
106  static const uint8_t CMD_SET_DATA_03 = 0x23;
107  static const uint8_t CMD_SET_DATA_04 = 0x24;
108  static const uint8_t CMD_SET_DATA_05 = 0x25;
109  static const uint8_t CMD_SET_DATA_06 = 0x26;
110  static const uint8_t CMD_SET_DATA_07 = 0x27;
111  static const uint8_t CMD_SET_DATA_08 = 0x28;
112  static const uint8_t CMD_SET_DATA_09 = 0x29;
113  static const uint8_t CMD_SET_DATA_0A = 0x2A;
114  static const uint8_t CMD_SET_DATA_0B = 0x2B;
115  static const uint8_t CMD_SET_DATA_0C = 0x2C;
116  static const uint8_t CMD_SET_DATA_0D = 0x2D;
117  static const uint8_t CMD_SET_DATA_0E = 0x2E;
118  static const uint8_t CMD_SET_DATA_0F = 0x2F;
119 
120  static const uint8_t CMD_GET_N_CHANNELS = 0x30;
121 
122  static const uint8_t CMD_READ_ADC0 = 0x40;
123 
124  static const uint8_t CMD_READ_EEPROM = 0x50;
125  static const uint8_t CMD_WRITE_EEPROM = 0x51;
126 
127  static const uint8_t CMD_BOOT_REQUEST = 0x80;
128  static const uint8_t CMD_BOOT_START = 0x81;
129 
130  static const uint8_t HW_ID_KARATE = 0x01;
131  static const uint8_t HW_ID_USB2DMX = 0x02;
132 };
133 } // namespace karate
134 } // namespace plugin
135 } // namespace ola
136 
137 #endif // PLUGINS_KARATE_KARATELIGHT_H_