-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathkk_music.cpp
83 lines (65 loc) · 2.01 KB
/
kk_music.cpp
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
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <iostream>
#include <fstream>
#include <string>
#include <curl/curl.h>
#include <unistd.h>
#include "/home/pi/json.hpp"
using json = nlohmann::json;
using namespace std;
const string PATHJSON = "/home/pi/config.json";
int lastTrek = 0;
static size_t WriteCallback(void *contents, size_t size, size_t nmemb, void *userp)
{
((std::string*)userp)->append((char*)contents, size * nmemb);
return size * nmemb;
}
int main(void)
{
cout << "music programm start" << endl;
for(;;) {
CURL *curl;
CURLcode res;
string readBuffer;
curl = curl_easy_init();
if(curl) {
curl_easy_setopt(curl, CURLOPT_URL, "http://192.168.1.105/config.json");
curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, WriteCallback);
curl_easy_setopt(curl, CURLOPT_WRITEDATA, &readBuffer);
res = curl_easy_perform(curl);
curl_easy_cleanup(curl);
auto CONFIG = json::parse(readBuffer);
int trek = CONFIG["trek"];
if(trek != lastTrek && CONFIG["status"] == "playing") { // замена трека
system("killall omxplayer.bin");
lastTrek = trek;
switch (trek) {
case 1 :
cout << "TREK: main" << endl;
system("omxplayer -o local --vol 600 KK_main.mp3 &");
break;
case 2 :
cout << "TREK: 5 min" << endl;
system("omxplayer -o local --vol 800 KK_5min.mp3 &");
break;
case 3 :
cout << "TREK: win" << endl;
system("omxplayer -o local KK_win.mp3 &");
break;
case 4 :
cout << "TREK: loose" << endl;
system("omxplayer -o local --vol 800 KK_loose.mp3 &");
break;
case 8 :
cout << "TREK: legend" << endl;
system("omxplayer -o local --vol 750 KK_legend.wav &");
break;
}
}
sleep(1); // 1 секунда
}
}
return 0;
}