1 | ////////////////////////////////////////////////////////////////////////////// |
---|
2 | // Copyright 2002-2006 Andreas Huber Doenni |
---|
3 | // Distributed under the Boost Software License, Version 1.0. (See accompany- |
---|
4 | // ing file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) |
---|
5 | ////////////////////////////////////////////////////////////////////////////// |
---|
6 | |
---|
7 | |
---|
8 | |
---|
9 | ////////////////////////////////////////////////////////////////////////////// |
---|
10 | // This program shows how a state machine can be spread over several |
---|
11 | // translation units if necessary. The inner workings of a digital camera are |
---|
12 | // modeled, the corresponding state chart looks as follows: |
---|
13 | // |
---|
14 | // --------------------------- |
---|
15 | // | | |
---|
16 | // | NotShooting | |
---|
17 | // | | |
---|
18 | // | ------------- |<---O |
---|
19 | // | O--->| Idle | | -------------- |
---|
20 | // | ------------- | EvShutterHalf | | |
---|
21 | // | | ^ |------------------>| Shooting | |
---|
22 | // | EvConfig | | EvConfig | | | |
---|
23 | // | v | | EvShutterRelease | | |
---|
24 | // | ------------- |<------------------| | |
---|
25 | // | | Configuring | | | | |
---|
26 | // | ------------- | -------------- |
---|
27 | // --------------------------- |
---|
28 | // |
---|
29 | // The states Configuring and Shooting will contain a large amount of logic, |
---|
30 | // so they are implemented in their own translation units. This way one team |
---|
31 | // could implement the Configuring mode while the other would work on the |
---|
32 | // Shooting mode. Once the above state chart is implemented, the teams could |
---|
33 | // work completely independently of each other. |
---|
34 | |
---|
35 | |
---|
36 | |
---|
37 | #include "Precompiled.hpp" |
---|
38 | #include "Camera.hpp" |
---|
39 | #include <iostream> |
---|
40 | |
---|
41 | |
---|
42 | |
---|
43 | ////////////////////////////////////////////////////////////////////////////// |
---|
44 | char GetKey() |
---|
45 | { |
---|
46 | char key; |
---|
47 | std::cin >> key; |
---|
48 | return key; |
---|
49 | } |
---|
50 | |
---|
51 | |
---|
52 | ////////////////////////////////////////////////////////////////////////////// |
---|
53 | int main() |
---|
54 | { |
---|
55 | std::cout << "Boost.Statechart Camera example\n\n"; |
---|
56 | |
---|
57 | std::cout << "h<CR>: Press shutter half-way\n"; |
---|
58 | std::cout << "f<CR>: Press shutter fully\n"; |
---|
59 | std::cout << "r<CR>: Release shutter\n"; |
---|
60 | std::cout << "c<CR>: Enter/exit configuration\n"; |
---|
61 | std::cout << "e<CR>: Exits the program\n\n"; |
---|
62 | std::cout << "You may chain commands, e.g. hfr<CR> first presses the shutter half-way,\n"; |
---|
63 | std::cout << "fully and then releases it.\n\n"; |
---|
64 | |
---|
65 | |
---|
66 | Camera myCamera; |
---|
67 | myCamera.initiate(); |
---|
68 | |
---|
69 | char key = GetKey(); |
---|
70 | |
---|
71 | while ( key != 'e' ) |
---|
72 | { |
---|
73 | switch( key ) |
---|
74 | { |
---|
75 | case 'h': |
---|
76 | { |
---|
77 | myCamera.process_event( EvShutterHalf() ); |
---|
78 | } |
---|
79 | break; |
---|
80 | |
---|
81 | case 'f': |
---|
82 | { |
---|
83 | myCamera.process_event( EvShutterFull() ); |
---|
84 | } |
---|
85 | break; |
---|
86 | |
---|
87 | case 'r': |
---|
88 | { |
---|
89 | myCamera.process_event( EvShutterRelease() ); |
---|
90 | } |
---|
91 | break; |
---|
92 | |
---|
93 | case 'c': |
---|
94 | { |
---|
95 | myCamera.process_event( EvConfig() ); |
---|
96 | } |
---|
97 | break; |
---|
98 | |
---|
99 | default: |
---|
100 | { |
---|
101 | std::cout << "Invalid key!\n"; |
---|
102 | } |
---|
103 | break; |
---|
104 | } |
---|
105 | |
---|
106 | key = GetKey(); |
---|
107 | } |
---|
108 | |
---|
109 | return 0; |
---|
110 | } |
---|