-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathLV2checkswt
137 lines (125 loc) · 3.87 KB
/
LV2checkswt
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
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
/***********************************************************************************************************************
Includes
***********************************************************************************************************************/
#include "r_macro.h" /* System macro and standard type definition */
#include "r_spi_if.h" /* SPI driver interface */
#include "lcd.h" /* LCD driver interface */
#include "Port.h"
#include <string.h>
#include "ChatDel.h"
#include "checkswitch.h"
/******************************************************************************
Macro definitions
******************************************************************************/
#define SETTING 0 // Setting...
#define RUNNING 1 // Running...
#define PAUSED 2 // Paused...
#define SWT1 0x40
#define SWT2 0x10
#define SWT3 0x20
#define SWT12 0x50
#define DOWN 0
#define UP 1
#define REC 1
/******************************************************************************
Imported global variables and functions (from other files)
******************************************************************************/
extern unsigned int button;
extern uint8_t state;
extern int second;
extern int minute;
extern char* string_shown_on_lcd[10];
extern int scroll_flag;
extern int rec_flag = 0;
extern unsigned int rec_min;
extern unsigned int rec_sec;
extern unsigned int rec_10centisec;
/******************************************************************************
Private global variables and functions
******************************************************************************/
/******************************************************************************
* Function Name: checkswitch
* Description : Check which switch was pressed. Change state.
* Arguments : none
* Return Value : none
******************************************************************************/
void checkswitch (void)
{
button = ChatDel();
//A button is pressed;
if((button != 0) && (button != 0x70)){
if (button == SWT1)
{
// Increment second
if (state == PAUSED) // Setting
{
second++;
if (second > 59)
{
second = 0;
}
sprintf(string_shown_on_lcd, "%0.2d:%0.2d", minute, second);
DisplayLCD(LCD_LINE2, string_shown_on_lcd);
}
//Scroll up
else if (state == RUNNING) // RUNNING
{
if (
scroll_flag = UP;
}
}
else if (button == SWT2)
{
//Increment minute
if (state == PAUSED) // Setting
{
DisplayLCD(LCD_LINE1, "Setting...");
minute++;
if (minute > 59)
{
minute = 0;
}
sprintf(string_shown_on_lcd, "%0.2d:%0.2d", minute, second);
DisplayLCD(LCD_LINE2, string_shown_on_lcd);
}
//Scroll down
else if (state == RUNNING) // RUNNING
{
scroll_flag = DOWN;
}
}
else if (button == SWT3)
{
//Record
if (state == RUNNING)
{
rec_flag = REC;
}
// Counting
else if (state == PAUSED)
{
DisplayLCD(LCD_LINE1, "Running...");
state = RUNNING; // Counting
}
}
else if (button == SWT12)
{
//Paused
if (state == RUNNING)
{
DisplayLCD(LCD_LINE1, "Paused...");
state = PAUSED; // Paused
}
//Reset
else if (state == PAUSED)
{
DisplayLCD(LCD_LINE1, "Paused...");
state = PAUSED; // Paused
second = 0;
minute = 0;
sprintf(string_shown_on_lcd, "%0.2d:%0.2d", minute, second);
DisplayLCD(LCD_LINE2, string_shown_on_lcd);
}
}
}
}