-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.c
More file actions
63 lines (49 loc) · 1.39 KB
/
main.c
File metadata and controls
63 lines (49 loc) · 1.39 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
//
// main.c
// ObserverPattern
//
// Created by Balu Pillai on 23/05/2020.
// Copyright © 2020 Balu Pillai. All rights reserved.
//
#include <stdio.h>
// To use time library of C
#include <time.h>
#include "TimeSource.h"
#include "App.h"
#include "AnotherApp.h"
/* Delay function */
void delay(uint8_t number_of_seconds)
{
/* Converting time into milli_seconds */
uint32_t milli_seconds = 1000000UL * number_of_seconds;
/* Storing start time */
clock_t start_time = clock();
/* looping till required time is not achieved */
while (clock() < start_time + milli_seconds);
}
/* Entry point */
int main(int argc, const char * argv[]) {
uint8_t i;
/* 1 sec clock increment */
const uint8_t delaySecs = 1;
/* Digital stop watch object pointer */
DigitalStopWatch_t *dwatch;
AnalogueWatch_t *awatch;
/* create a digital watch object */
dwatch = createDigitalWatch();
awatch = createAnalogueWatch();
printf("Digital watch object address is %x", dwatch);
printf("Analogue watch object address is %x", awatch);
/* Verify the observers */
getAllObservers();
/* Update time every sec for 10 secs */
for (i = 0; i < 10; i++)
{
delay(delaySecs);
/* Increment seconds counter */
msTick();
}
/* Destroy digital watch object */
destroyDigitalWatch(dwatch);
return 0;
}