-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrangeKeyController.c
50 lines (42 loc) · 1.16 KB
/
rangeKeyController.c
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
#include <stdio.h>
#include <stdlib.h>
#include <stddef.h>
#include <string.h>
#include <stdbool.h>
#include "rangeKeyControllerClass.h"
static void scanKey (rangeKeyController_t *this);
static int getKey (rangeKeyController_t *this, int key);
const rangeKeyController_t rangeKeyControllerInitValue = {
' ',
' ',
0,
&scanKey,
&getKey,
};
static void scanKey (rangeKeyController_t *this)
{
this->keyCodeBuff = getchar();
if (this->keyCodeBuff != '\n') {
this->counter = true;
this->keyCode = this->keyCodeBuff;
}
}
static int getKey (rangeKeyController_t *this, int key)
{
int rsp = false;
if (this->counter == true) {
if (this->keyCode == (char)key) {
this->counter = false;
rsp = true;
}
}
return (rsp);
}
void rangeKeyController_Constructor (rangeKeyController_t *this)
{
this->keyCodeBuff = rangeKeyControllerInitValue.keyCodeBuff;
this->keyCode = rangeKeyControllerInitValue.keyCode;
this->counter = rangeKeyControllerInitValue.counter;
this->pScanKey = rangeKeyControllerInitValue.pScanKey;
this->pGetKey = rangeKeyControllerInitValue.pGetKey;
}