summaryrefslogtreecommitdiff
path: root/lib/boblight_client.h
blob: aac141d430dbfea17ef922b52f2aefa97774f094 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
/*
 * boblight
 * Copyright (C) Bob  2009 
 * 
 * boblight is free software: you can redistribute it and/or modify it
 * under the terms of the GNU General Public License as published by the
 * Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 * 
 * boblight is distributed in the hope that it will be useful, but
 * WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
 * See the GNU General Public License for more details.
 * 
 * You should have received a copy of the GNU General Public License along
 * with this program.  If not, see <http://www.gnu.org/licenses/>.
 */

#ifndef CBOBLIGHT
#define CBOBLIGHT

#include <string>
#include <vector>

#include "util/tcpsocket.h"
#include "util/messagequeue.h"

namespace boblight
{
  class CLight
  {
    public:
      CLight();

      std::string SetOption(const char* option, bool& send);
      std::string GetOption(const char* option, std::string& output);

      void        SetScanRange(int width, int height);
      void        AddPixel(int* rgb);
      
      std::string m_name;
      float       m_speed;
      float       m_autospeed;
      float       m_singlechange;

      bool        m_interpolation;
      bool        m_use;

      float       m_value;
      float       m_valuerange[2];
      float       m_saturation;
      float       m_satrange[2];
      int         m_threshold;
      float       m_gamma;
      float       m_gammacurve[256];

      float       m_rgb[3];
      int         m_rgbcount;
      float       m_prevrgb[3];
      void        GetRGB(float* rgb);

      float       m_hscan[2];
      float       m_vscan[2];
      int         m_width;
      int         m_height;
      int         m_hscanscaled[2];
      int         m_vscanscaled[2];
  };  

  class CBoblight
  {
    public:
      CBoblight();

      int         Connect(const char* address, int port, int usectimeout);
      const char* GetError()                    { return m_error.c_str(); }

      int         GetNrLights()                 { return m_lights.size(); }
      const char* GetLightName    (int lightnr);

      int         SetPriority     (int priority);
      void        SetScanRange    (int width,   int height);

      int         AddPixel(int lightnr, int* rgb);
      void        AddPixel(int* rgb, int x, int y);

      int         SendRGB(int sync, int* outputused);
      int         Ping(int* outputused, bool send);

      int         GetNrOptions();
      const char* GetOptionDescription(int option);
      int         SetOption(int lightnr, const char* option);
      int         GetOption(int lightnr, const char* option, const char** output);

    private:
      CTcpClientSocket m_socket;
      std::string      m_address;
      int              m_port;
      std::string      m_error;
      CMessageQueue    m_messagequeue;
      int              m_usectimeout;

      bool             ReadDataToQueue();
      bool             WriteDataToSocket(std::string strdata);
      bool             ParseWord(CMessage& message, std::string wordtocmp);
      bool             ParseLights(CMessage& message);
      bool             CheckLightExists(int lightnr, bool printerror = true);

      std::vector<CLight> m_lights;

      std::vector<std::string> m_options;
      std::string              m_lastoption; //place to store the last option retrieved by GetOption
  };
}
#endif //CBOBLIGHT