Skip to content

Commit 6b3d82d

Browse files
authored
Merge pull request #244 from brian4685380/RPi-#242
Rpi #242
2 parents ab86398 + 7b5877f commit 6b3d82d

File tree

4 files changed

+148
-143
lines changed

4 files changed

+148
-143
lines changed

README.md

+25-54
Original file line numberDiff line numberDiff line change
@@ -1,61 +1,32 @@
1-
# 2023-LightDance-RPi
1+
# 2024-LightDance-RPi
22

3-
## playloop
3+
## Develope flow
4+
Step 1. Fork a copy from the organization repo to your personal repo
45

5-
### OF
6+
Step 2. Clone the repo to your local machine
67

7-
```c++
8-
struct Status {
9-
int r;
10-
int g;
11-
int b;
12-
int a;
13-
};
8+
```shell
9+
# USERNAME – your Github user account name.
10+
# flag --recursive to completely clone repos including hardware
11+
git clone --recursive [email protected]:${USERNAME}/LightDance-RPi.git
12+
cd LightDance-RPi
13+
# set upstream
14+
git remote add upstream [email protected]:NTUEELightDance/LightDance-RPi.git
1415

15-
vector<vector<Status>> frames;
1616

17-
class OpticalFiberController {
18-
public:
19-
OpticalFiberController();
20-
int init(vector<int> map);
21-
int sendAll(vector<Status> status); // lightall, darkall
22-
};
23-
24-
// logic
25-
while(1) {
26-
status = findFrame(getTime());
27-
sendAll(status);
28-
sleep(5ms);
29-
}
17+
# Make sure don’t accidentally merge
18+
git config --add merge.ff only
19+
git config --add pull.ff only
3020
```
3121

32-
### LED
33-
34-
```c++
35-
struct Status {
36-
int r;
37-
int g;
38-
int b;
39-
int a;
40-
};
41-
42-
vector<LEDStatus> stripStatus(size);
43-
44-
class LEDStripController {
45-
public:
46-
LEDStripController();
47-
int init(vector<int> shape);
48-
int checkReady();
49-
int sendAll(vector<vector<Status>> status);
50-
};
51-
52-
// logic
53-
while(1) {
54-
while(checkReady() == 0){
55-
sleep(1ms);
56-
}
57-
status = findFrame(getTime());
58-
sendAll(status);
59-
sleep(5ms);
60-
}
61-
```
22+
Step 3. Build your local project
23+
24+
```shell
25+
cd controller/hardware/
26+
git checkout origin/local_test
27+
cd ..
28+
mkdir build
29+
cd build
30+
cmake ..
31+
make install
32+
```

controller/software/inc/player.h

+7-5
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,8 @@
1111
#include <sstream>
1212
#include <unordered_map>
1313

14-
#include "nlohmann/json.hpp"
14+
#include <boost/property_tree/json_parser.hpp>
15+
#include <boost/property_tree/ptree.hpp>
1516

1617
// serialize
1718
#include <boost/archive/text_iarchive.hpp>
@@ -22,12 +23,13 @@
2223
#include <boost/serialization/vector.hpp>
2324
#include <boost/serialization/version.hpp>
2425

26+
2527
#include "LEDPlayer.h"
2628
#include "OFPlayer.h"
2729
#include "const.h"
2830

2931
using namespace std;
30-
using json = nlohmann::json;
32+
using namespace boost;
3133

3234
struct LEDStripeSetting {
3335
LEDStripeSetting(){};
@@ -45,7 +47,7 @@ class Player {
4547
Player() : LEDloaded(false), OFloaded(false){};
4648
Player(const string &_dancerName)
4749
: dancerName(_dancerName), LEDloaded(false), OFloaded(false){};
48-
bool setDancer(const string &_dancerName, json &dancerData);
50+
bool setDancer(const string &_dancerName, property_tree::ptree &dancerData);
4951
string list() const;
5052
string getDancerName();
5153
template <class Archive>
@@ -68,8 +70,8 @@ class Player {
6870
// serialization
6971
friend class boost::serialization::access;
7072
friend ostream &operator<<(ostream &ostream, const Player &player);
71-
friend void LEDload(Player &Player, json &data_json);
72-
friend void OFload(Player &Player, json &data_json);
73+
friend void LEDload(Player &Player, property_tree::ptree &data_json);
74+
friend void OFload(Player &Player, property_tree::ptree &data_json);
7375
};
7476

7577
void savePlayer(const Player &savePlayer, const char *filename);

controller/software/src/commands/load.cpp

+18-12
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,11 @@
88
#include <fstream>
99
#include <iostream>
1010

11+
#include <boost/property_tree/json_parser.hpp>
12+
#include <boost/property_tree/ptree.hpp>
13+
1114
#include "LEDPlayer.h"
1215
#include "const.h"
13-
#include "nlohmann/json.hpp"
1416
#include "player.h"
1517

1618
/*
@@ -62,7 +64,6 @@ have a mismatch. (e.g. load LED OF.json).
6264
6365
*/
6466
using namespace std;
65-
using json = nlohmann::json;
6667

6768
int main(int argc, char *argv[]) {
6869
setuid(1000);
@@ -117,39 +118,42 @@ int main(int argc, char *argv[]) {
117118
// string dancerName = path.substr(fileNameStart, path.find_last_of(".") -
118119
// fileNameStart);
119120
string dancerName = "DANCER";
120-
json controlJsonFile;
121+
boost::property_tree::ptree controlJsonFile;
121122
if (loadControl) {
122123
ifstream infile(controlPath.c_str());
123124
if (!infile) {
124125
cerr << "Cannot open file: " << controlPath << endl;
125126
exit(1);
126127
}
127-
infile >> controlJsonFile;
128+
boost::property_tree::read_json(infile, controlJsonFile);
128129
infile.close();
129130
}
130-
json LEDJsonFile;
131+
boost::property_tree::ptree LEDJsonFile;
131132
if (loadLED) {
132133
ifstream infile(LEDpath.c_str());
133134
if (!infile) {
134135
cerr << "Cannot open file: " << LEDpath << endl;
135136
exit(1);
136137
}
137-
infile >> LEDJsonFile;
138+
boost::property_tree::read_json(infile, LEDJsonFile);
138139
infile.close();
139140
}
140-
json OFJsonFile;
141+
boost::property_tree::ptree OFJsonFile;
141142
if (loadOF) {
142143
ifstream infile(OFpath.c_str());
143144
if (!infile) {
144145
cerr << "Cannot open file: " << OFpath << endl;
145146
exit(1);
146147
}
147-
infile >> OFJsonFile;
148+
boost::property_tree::read_json(infile, OFJsonFile);
148149
infile.close();
149150
}
150151

151152
string outputFileName = basePath + "data/dancer.dat";
152153
if (loadControl) {
154+
155+
boost::property_tree::write_json(std::cout, controlJsonFile);
156+
153157
Player dancer;
154158
dancer.setDancer(dancerName, controlJsonFile);
155159
cout << "Dancer control data loaded successfully\n";
@@ -162,11 +166,12 @@ int main(int argc, char *argv[]) {
162166
}
163167

164168
Player dancerData;
165-
if (!restorePlayer(dancerData, outputFileName.c_str())) {
166-
cerr << "Please load dancer's control data first !" << endl;
167-
exit(1);
168-
};
169+
// if (!restorePlayer(dancerData, outputFileName.c_str())) {
170+
// cerr << "Please load dancer's control data first !" << endl;
171+
// exit(1);
172+
// };
169173
if (loadLED) {
174+
boost::property_tree::write_json(std::cout, LEDJsonFile);
170175
LEDload(dancerData, LEDJsonFile);
171176
cout << "LED data loaded successfully\n";
172177
cout << "Stored at: " << outputFileName << endl;
@@ -178,6 +183,7 @@ int main(int argc, char *argv[]) {
178183
// return 0;
179184
}
180185
if (loadOF) {
186+
boost::property_tree::write_json(std::cout, OFJsonFile);
181187
OFload(dancerData, OFJsonFile);
182188
cout << "OF data loaded successfully\n";
183189
cout << "Stored at: " << outputFileName << endl;

0 commit comments

Comments
 (0)