-
Notifications
You must be signed in to change notification settings - Fork 1
/
phpPi.bak2.c
190 lines (162 loc) · 5.22 KB
/
phpPi.bak2.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
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
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
/*
+----------------------------------------------------------------------+
| PHP Version 7 |
+----------------------------------------------------------------------+
| Copyright (c) 1997-2018 The PHP Group |
+----------------------------------------------------------------------+
| This source file is subject to version 3.01 of the PHP license, |
| that is bundled with this package in the file LICENSE, and is |
| available through the world-wide-web at the following url: |
| http://www.php.net/license/3_01.txt |
| If you did not receive a copy of the PHP license and are unable to |
| obtain it through the world-wide-web, please send a note to |
| [email protected] so we can mail you a copy immediately. |
+----------------------------------------------------------------------+
| Author: |
+----------------------------------------------------------------------+
*/
/* $Id$ */
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
#include "php.h"
#include "php_ini.h"
#include "ext/standard/info.h"
#include "php_phpPi.h"
#include <wiringPi.h>
#include <stdio.h>
#include <time.h>
#include <stdlib.h>
static int le_phpPi;
ZEND_BEGIN_ARG_INFO(arginfo_tioncico_test1, 0)//函数名,参数是否为引用类型,0代表不是
ZEND_END_ARG_INFO()//结束函数参数信息声明
ZEND_BEGIN_ARG_INFO(arginfo_tioncico_test2, 0)//函数名,参数是否为引用类型,0代表不是
ZEND_ARG_INFO(0, str)//声明一个普通参数str
ZEND_END_ARG_INFO()//结束函数参数信息声明
PHP_FUNCTION (wiringPiSetup) {
int status = wiringPiSetup();
if (status == -1) {
RETURN_BOOL(FALSE);
} else {
RETURN_BOOL(TRUE);
}
}
PHP_FUNCTION (wiringPiSetupGpio) {
int status = wiringPiSetupGpio();
if (status == -1) {
RETURN_BOOL(FALSE);
} else {
RETURN_BOOL(TRUE);
}
}
PHP_FUNCTION (wiringPiSetupPhys) {
wiringPiSetupPhys();
}
PHP_FUNCTION (wiringPiSetupSys) {
wiringPiSetupSys();
}
PHP_FUNCTION (pinMode) {
char *pin;
int pinLength;
char *model;
int modelLength;
if (zend_parse_parameters(2, "ss",&pin, &pinLength,&model, &modelLength) == FAILURE){
RETURN_BOOL(FALSE);
}
php_printf("%s%s",pin,model);
// pinMode(pin, model);
}
//
PHP_FUNCTION (digitalWrite) {
int *pin;
int *value;
if (zend_parse_parameters(2, "s|s", &pin, &value) == FAILURE) {
return;
}
pin = atoi(pin);
value = atoi(value);
digitalWrite(pin, value);
}
PHP_FUNCTION (digitalRead) {
int *pin;
if (zend_parse_parameters(1, "s", &pin) == FAILURE) {
return;
}
pin = atoi(pin);
int retVal = digitalRead(pin);
RETURN_LONG(retVal);
}
PHP_FUNCTION (pwmWrite) {
int *pin;
int *value;
if (zend_parse_parameters(2, "s|2", &pin, &value) == FAILURE) {
return;
}
pin = atoi(pin);
value = atoi(value);
pwmWrite(pin, value);
}
PHP_FUNCTION (pullUpDnControl) {
int *pin;
int *pud;
if (zend_parse_parameters(2, "s|2", &pin, &pud) == FAILURE) {
return;
}
pin = atoi(pin);
pud = atoi(pud);
pullUpDnControl(pin, pud);
}
PHP_MINIT_FUNCTION (phpPi) {
/* If you have INI entries, uncomment these lines
REGISTER_INI_ENTRIES();
*/
return SUCCESS;
}
PHP_MSHUTDOWN_FUNCTION (phpPi) {
/* uncomment this line if you have INI entries
UNREGISTER_INI_ENTRIES();
*/
return SUCCESS;
}
PHP_RINIT_FUNCTION (phpPi) {
#if defined(COMPILE_DL_PHPPI) && defined(ZTS)
ZEND_TSRMLS_CACHE_UPDATE();
#endif
return SUCCESS;
}
PHP_RSHUTDOWN_FUNCTION (phpPi) {
return SUCCESS;
}
PHP_MINFO_FUNCTION (phpPi) {
php_info_print_table_start();
php_info_print_table_header(2, "phpPi support", "enabled");
php_info_print_table_end();
/* Remove comments if you have entries in php.ini
DISPLAY_INI_ENTRIES();
*/
}
const zend_function_entry phpPi_functions[] = {
PHP_FE(wiringPiSetup, NULL) /* For testing, remove later. */
PHP_FE(wiringPiSetupGpio, NULL) /* For testing, remove later. */
PHP_FE(wiringPiSetupPhys, NULL) /* For testing, remove later. */
PHP_FE(wiringPiSetupSys, NULL) /* For testing, remove later. */
PHP_FE(pinMode, NULL) /* For testing, remove later. */
// PHP_FE(digitalWrite, NULL) /* For testing, remove later. */
// PHP_FE(digitalRead, NULL) /* For testing, remove later. */
// PHP_FE(pullUpDnControl, NULL) /* For testing, remove later. */
PHP_FE_END /* Must be the last line in phpPi_functions[] */
};
zend_module_entry phpPi_module_entry = {
STANDARD_MODULE_HEADER,
"phpPi",
phpPi_functions,
PHP_MINIT(phpPi),
PHP_MSHUTDOWN(phpPi),
PHP_RINIT(phpPi), /* Replace with NULL if there's nothing to do at request start */
PHP_RSHUTDOWN(phpPi), /* Replace with NULL if there's nothing to do at request end */
PHP_MINFO(phpPi),
PHP_PHPPI_VERSION,
STANDARD_MODULE_PROPERTIES
};
#ifdef COMPILE_DL_PHPPI
#endif