1 | |
---|
2 | |
---|
3 | #ifndef _ROBOCORE_ |
---|
4 | #define _ROBOCORE_ |
---|
5 | |
---|
6 | #include <cairo.h> |
---|
7 | #include <lgi-1.0/application.hpp> |
---|
8 | #include <lgi-1.0/x11window.hpp> |
---|
9 | #include <lgi-1.0/layer.hpp> |
---|
10 | |
---|
11 | #include "robowidgets.h" |
---|
12 | #include "rsrcmanager.h" |
---|
13 | |
---|
14 | #ifdef LOCAL |
---|
15 | #define FIRM_PATH "../rsrc/FIRM0328.lgo" |
---|
16 | #else |
---|
17 | #define FIRM_PATH "/lib/firmware/rcx/FIRM0328.lgo" |
---|
18 | #endif |
---|
19 | |
---|
20 | #define RBC_PORT_COM1 0x00 |
---|
21 | #define RBC_PORT_COM2 0x01 |
---|
22 | #define RBC_PORT_USB 0x02 |
---|
23 | |
---|
24 | #define RBC_RUN_STATUS_DOWNLOADING 0x01 |
---|
25 | #define RBC_RUN_STATUS_COMPLETED 0x02 |
---|
26 | #define RBC_RUN_STATUS_NQC_ERROR 0x03 |
---|
27 | #define RBC_RUN_STATUS_COMM_ERROR 0x04 |
---|
28 | |
---|
29 | #define RBC_TEST_STATUS_RUNNING 0x01 |
---|
30 | #define RBC_TEST_STATUS_OK 0x02 |
---|
31 | #define RBC_TEST_STATUS_ERROR 0x03 |
---|
32 | |
---|
33 | #define RBC_FIRM_STATUS_DOWNLOADING 0x01 |
---|
34 | #define RBC_FIRM_STATUS_COMPLETED 0x02 |
---|
35 | #define RBC_FIRM_STATUS_ERROR 0x03 |
---|
36 | |
---|
37 | namespace net |
---|
38 | { |
---|
39 | namespace lliurex |
---|
40 | { |
---|
41 | namespace robolliurex |
---|
42 | { |
---|
43 | |
---|
44 | class MainWindow : public lgi::X11Window |
---|
45 | { |
---|
46 | |
---|
47 | private: |
---|
48 | bool have_batt; |
---|
49 | float batt; |
---|
50 | cairo_surface_t * srf_background; |
---|
51 | |
---|
52 | public: |
---|
53 | |
---|
54 | MainWindow(); |
---|
55 | |
---|
56 | /*! |
---|
57 | overrided flip method, so we can perform custom drawing operations |
---|
58 | */ |
---|
59 | void Flip(); |
---|
60 | |
---|
61 | /*! |
---|
62 | Sets battery level |
---|
63 | */ |
---|
64 | void SetBattery(float level); |
---|
65 | |
---|
66 | }; |
---|
67 | |
---|
68 | class RoboCore : public lgi::Application |
---|
69 | { |
---|
70 | private: |
---|
71 | static RoboCore * singleton; |
---|
72 | RoboCore(); |
---|
73 | ~RoboCore(); |
---|
74 | |
---|
75 | |
---|
76 | |
---|
77 | |
---|
78 | public: |
---|
79 | static std::string comm_name[]; |
---|
80 | int comm_port; |
---|
81 | bool usb_tower; |
---|
82 | |
---|
83 | bool is_firmware_downloading; |
---|
84 | bool is_comm_testing; |
---|
85 | bool is_program_downloading; |
---|
86 | bool is_battery_requesting; |
---|
87 | |
---|
88 | |
---|
89 | |
---|
90 | std::string program_path; |
---|
91 | std::string firmware_path; |
---|
92 | |
---|
93 | MainWindow * window; |
---|
94 | RsrcManager * rsrc; |
---|
95 | |
---|
96 | /*! |
---|
97 | Initialization |
---|
98 | */ |
---|
99 | void Init(); |
---|
100 | |
---|
101 | |
---|
102 | /*! |
---|
103 | static singleton |
---|
104 | */ |
---|
105 | static RoboCore * GetCore(); |
---|
106 | |
---|
107 | /*! |
---|
108 | static singleton destructor |
---|
109 | */ |
---|
110 | static void Destroy(); |
---|
111 | |
---|
112 | /*! |
---|
113 | Performs an asynchronous firmware download |
---|
114 | */ |
---|
115 | void DownloadFirmware(); |
---|
116 | |
---|
117 | /*! |
---|
118 | Performs an asynchronous Comm test |
---|
119 | */ |
---|
120 | void TestComm(); |
---|
121 | |
---|
122 | /*! |
---|
123 | Performs an asynchronous program download |
---|
124 | */ |
---|
125 | void DownloadProgram(std::string path); |
---|
126 | |
---|
127 | /*! |
---|
128 | Performs an asynchronous battery read |
---|
129 | */ |
---|
130 | void GetBattery(); |
---|
131 | |
---|
132 | |
---|
133 | /*! |
---|
134 | Overrided custom event dispatching |
---|
135 | */ |
---|
136 | int CustomEventsDispatch(); |
---|
137 | |
---|
138 | /*! |
---|
139 | Overrided message hook |
---|
140 | */ |
---|
141 | void OnMessage(BaseWindow * window,Layer * layer, Widget * widget,MessageEvent * event); |
---|
142 | }; |
---|
143 | } |
---|
144 | } |
---|
145 | } |
---|
146 | |
---|
147 | #endif |
---|