42 static char input[16];
43 static struct ctk_label inputlabel =
46 static struct ctk_button button7 =
48 static struct ctk_button button8 =
50 static struct ctk_button button9 =
52 static struct ctk_button button4 =
54 static struct ctk_button button5 =
56 static struct ctk_button button6 =
58 static struct ctk_button button1 =
60 static struct ctk_button button2 =
62 static struct ctk_button button3 =
64 static struct ctk_button button0 =
67 static struct ctk_button cbutton =
70 static struct ctk_button divbutton =
72 static struct ctk_button mulbutton =
75 static struct ctk_button subbutton =
77 static struct ctk_button addbutton =
79 static struct ctk_button calcbutton =
82 PROCESS(calc_process,
"Calculator");
84 AUTOSTART_PROCESSES(&calc_process);
86 static unsigned long operand1, operand2;
87 static unsigned char op;
106 for(i = 0; i < 11; ++i) {
107 input[i] = input[i + 1];
117 for(i = 0; i <
sizeof(input); ++i) {
123 input_to_operand1(
void)
130 i > 7; --i, m *= 10) {
131 if(input[i] >=
'0' &&
133 operand1 += (input[i] -
'0') * m;
140 operand2_to_input(
void)
144 input[7] = (char)((operand2/10000) % 10) +
'0';
145 input[8] = (char)((operand2/1000) % 10) +
'0';
146 input[9] = (char)((operand2/100) % 10) +
'0';
147 input[10] = (char)((operand2/10) % 10) +
'0';
148 input[11] = (char)(operand2 % 10) +
'0';
150 for(i = 0; i < 4; ++i) {
151 if(input[7 + i] ==
'0') {
166 operand2 = operand2 + operand1;
169 operand2 = operand2 - operand1;
172 operand2 = operand2 * operand1;
175 operand2 = operand2 / operand1;
188 CTK_WIDGET_SET_FLAG(&inputlabel, CTK_WIDGET_FLAG_MONOSPACE);
227 if((
char)(
size_t)data >=
'0' &&
228 (
char)(
size_t)data <=
'9') {
229 add_to_input((
char)(
size_t)data);
230 }
else if((
char)(
size_t)data ==
' ') {
232 }
else if((
char)(
size_t)data ==
'+') {
235 }
else if((
char)(
size_t)data ==
'-') {
238 }
else if((
char)(
size_t)data ==
'*') {
241 }
else if((
char)(
size_t)data ==
'/') {
244 }
else if((
char)(
size_t)data ==
'=' ||
245 (
char)(
size_t)data == CH_ENTER) {
251 if(data == (process_data_t)&button0) {
253 }
else if(data == (process_data_t)&button1) {
255 }
else if(data == (process_data_t)&button2) {
257 }
else if(data == (process_data_t)&button3) {
259 }
else if(data == (process_data_t)&button4) {
261 }
else if(data == (process_data_t)&button5) {
263 }
else if(data == (process_data_t)&button6) {
265 }
else if(data == (process_data_t)&button7) {
267 }
else if(data == (process_data_t)&button8) {
269 }
else if(data == (process_data_t)&button9) {
271 }
else if(data == (process_data_t)&cbutton) {
273 }
else if(data == (process_data_t)&calcbutton) {
275 }
else if(data == (process_data_t)&addbutton) {
278 }
else if(data == (process_data_t)&subbutton) {
281 }
else if(data == (process_data_t)&mulbutton) {
284 }
else if(data == (process_data_t)&divbutton) {
290 data == (process_data_t)&window) {
#define CTK_WIDGET_ADD(win, widg)
Add a widget to a window.
process_event_t ctk_signal_window_close
Emitted when a window is closed.
process_event_t ctk_signal_button_activate
Same as ctk_signal_widget_activate.
void ctk_window_open(CC_REGISTER_ARG struct ctk_window *w)
Open a window, or bring window to front if already open.
#define PROCESS_BEGIN()
Define the beginning of a process.
#define CTK_LABEL(x, y, w, h, text)
Instantiating macro for the ctk_label widget.
process_event_t ctk_signal_keypress
Emitted for every key being pressed.
#define PROCESS_THREAD(name, ev, data)
Define the body of a process.
#define PROCESS_END()
Define the end of a process.
void ctk_window_new(struct ctk_window *window, unsigned char w, unsigned char h, char *title)
Create a new window.
#define LOADER_UNLOAD()
Unload a program from memory.
#define PROCESS_WAIT_EVENT()
Wait for an event to be posted to the process.
#define PROCESS(name, strname)
Declare a process.
#define CTK_BUTTON(x, y, w, text)
Instantiating macro for the ctk_button widget.
Representation of a CTK window.
#define CTK_WIDGET_REDRAW(widg)
Add a widget to the redraw queue.
void process_exit(struct process *p)
Cause a process to exit.