-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathmain.cpp
More file actions
92 lines (76 loc) · 1.68 KB
/
main.cpp
File metadata and controls
92 lines (76 loc) · 1.68 KB
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
//yo this will ostream the characters 'H' and 'L' to control coffee production
#include <iostream>
#include <string>
#include <cstdio>
#include <ctime>
#include <unistd.h>
#include <stdio.h>
#include <time.h>
#include <stdlib.h>
using namespace std;
void spinner(int num) {
if (num < 1000) {
putchar('0');
}
if (num < 100) {
putchar('0');
}
if (num < 10) {
putchar('0');
}
cout << num;
putchar(' ');
fflush(stdout);
}
const int NUM_SECONDS = 30;
int main(int argC, char* argV[])
{
if (argC < 2) {
cerr << "NOT ENOUGH ARGUMENTS!" << endl;
return 1;
}
int cups = atoi(argV[1]);
if (cups > 10) {
cerr << "TOO MANY CUPS!" << endl;
return 1;
}
double minutes;
FILE *file;
int desc = 0;
minutes=(double)cups+0.5;
cout<< "making "<<cups<< " cups of coffee."<<endl;
cout<< "Coffee maker will take " << minutes
<<" minutes to steep coffee."<<endl;
file = fopen("/dev/rfcomm0", "w+");
if (!file) {
cerr << "Cannot open file" << endl;
cout << "Cannot open file" << endl;
return(1);
}
desc = fileno(file);
write(desc, "H", 1);
double time_counter = 0;
double spin_time = 0;
double print_time = 0;
time_t beginning_time;
time(&beginning_time);
time_t this_time;
time(&this_time);
while((time_counter/60) < minutes)
{
time(&this_time);
if (time_counter >= spin_time) {
spinner(minutes * 60 - (time_counter + 1));
spin_time += 1;
}
time_counter = difftime(this_time, beginning_time);
if(time_counter > print_time)
{
write(desc, "H", 1);
print_time += 30;
}
usleep(1000);
}
write(desc, "L", 1);
return 0;
}