-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbootstrap.cpp
92 lines (80 loc) · 2.06 KB
/
bootstrap.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
84
85
86
87
88
89
90
91
92
/* Bootstrap implementation */
#include "bootstrap.h"
void
bootstrap(char* dbuffer, int sizeofdbuffer)
{
int cstat, ctr, tohost;
char gamename[100];
char tmp[500], myhost[50], *ptr;
Serial.begin(115200);
maintft.init();
randomSeed(analogRead(0));
tftrotation(1);
pinMode(16, INPUT_PULLUP);
pinMode(5, INPUT_PULLUP);
tftfill(0x000);
if(!mainimu.setupIMU(1)){
Serial.println("IMU not reachable.");
ESP.restart(); // restart the ESP (proper way)
}
tftprint("Hello\nConnecting to Wifi...\n");
cstat = 0;
WiFi.begin(WIFISSID, PASSPHRASE);
for(ctr = 0; ctr <= 20; ctr++){
if(WiFi.isConnected()){
cstat = 1;
break;
}
delay(500);
}
if(!cstat){
Serial.println("Connection failed");
ESP.restart();
}
gethostname(myhost, 50);
Serial.println(myhost);
tftprint("Getting game info...\n");
httpget("what=whatever", REMOTE, tmp, 500);
*gamename = '\0';
if((ptr = strstr(tmp, myhost)) == NULL){
Serial.println("Couldn't find any hosted games!");
while(1);
}
ptr += strlen(myhost) + 4;
while(*ptr != '\''){
Serial.print(*ptr);
printchr(*ptr, gamename, 100, 2);
ptr++;
}
tftprint("\n\nWelcome to P O N G 9 0 0 0\n\nSmashing stacks since 2020\n");
tftprint("--------------------------\n\n");
tftprint("You're currently playing: \n");
tftprint(gamename);
tftprint("\n\n\nPress A to JIT this game\nPress B to browse around\n");
while(1){
if(!buttonread(16)){
tohost = 1; break;
}
else if(!buttonread(5)){
tohost = 0; break;
}
}
tftfill(0x0000);
if(tohost){
tftprint("Downloading remote code..\n");
Serial.println();
Serial.print("Game: ");
Serial.println(gamename);
printtxt("game_name=", tmp, 500, 1);
printtxt(gamename, tmp, 500, 2);
printtxt("&host=", tmp, 500, 2);
printtxt(myhost, tmp, 500, 2);
httpget(tmp, REMOTE, dbuffer, sizeofdbuffer);
return;
}
else{
tftprint("Downloading the browser...\n");
httpget("game_name=bootstrap&host=0", REMOTE, dbuffer, sizeofdbuffer);
return;
}
}