change rel control
This commit is contained in:
@@ -0,0 +1,104 @@
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <rtthread.h>
|
||||
|
||||
#include "chrg_rel.h"
|
||||
|
||||
struct chrg_rel_t chrgrel[TOTAL_CHS] = {
|
||||
[IDX_CH_0] = {PIN_NORTH_CH0_P0, PIN_NORTH_CH0_P1, PIN_NORTH_CH0_P2},
|
||||
[IDX_CH_1] = {PIN_NORTH_CH1_P0, PIN_NORTH_CH1_P1, PIN_NORTH_CH1_P2},
|
||||
[IDX_CH_2] = {PIN_NORTH_CH2_P0, PIN_NORTH_CH2_P1, PIN_NORTH_CH2_P2},
|
||||
[IDX_CH_3] = {PIN_NORTH_CH3_P0, PIN_NORTH_CH3_P1, PIN_NORTH_CH3_P2}
|
||||
};
|
||||
|
||||
// 继电器组切换
|
||||
void chrg_north_sw_rel (eIDX_CH ch, eIDX_ID id)
|
||||
{
|
||||
if (ch >= TOTAL_CHS) {
|
||||
return ;
|
||||
}
|
||||
|
||||
rt_pin_write(chrgrel[ch].p2, PIN_HIGH);
|
||||
|
||||
if (ID_SOURCE == id) {
|
||||
rt_pin_write(chrgrel[ch].p0, PIN_LOW);
|
||||
rt_pin_write(chrgrel[ch].p1, PIN_HIGH);
|
||||
} else if (ID_SINK == id) {
|
||||
rt_pin_write(chrgrel[ch].p1, PIN_LOW);
|
||||
rt_pin_write(chrgrel[ch].p0, PIN_HIGH);
|
||||
} else {
|
||||
rt_pin_write(chrgrel[ch].p1, PIN_LOW);
|
||||
rt_pin_write(chrgrel[ch].p0, PIN_LOW);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
static int charg_rel_init (void)
|
||||
{
|
||||
int i = 0;
|
||||
|
||||
for (i = 0; i < TOTAL_CHS; i++) {
|
||||
rt_pin_mode(chrgrel[i].p0, PIN_MODE_OUTPUT);
|
||||
rt_pin_mode(chrgrel[i].p1, PIN_MODE_OUTPUT);
|
||||
rt_pin_mode(chrgrel[i].p2, PIN_MODE_OUTPUT);
|
||||
|
||||
rt_pin_write(chrgrel[i].p2, PIN_HIGH);
|
||||
rt_pin_write(chrgrel[i].p0, PIN_LOW);
|
||||
rt_pin_write(chrgrel[i].p1, PIN_LOW);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
INIT_DEVICE_EXPORT(charg_rel_init);
|
||||
|
||||
#if 1
|
||||
int rel_test (int argc, char **argv)
|
||||
{
|
||||
if (argc < 3) {
|
||||
rt_kprintf("help : %s <get|set> <0|1|2|3> [0, 1]", argv[0]);
|
||||
return -1;
|
||||
}
|
||||
|
||||
int idx = atoi(argv[2]);
|
||||
if ((idx > 3)||(idx < 0)) {
|
||||
rt_kprintf("help : %s <get|set> <0|1|2|3> [0, 1]", argv[0]);
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (strcmp(argv[1], "set") == 0) {
|
||||
if (argc != 4) {
|
||||
rt_kprintf("help : %s <get|set> <0|1|2|3> [0, 1]", argv[0]);
|
||||
return -1;
|
||||
}
|
||||
rt_uint8_t val = (rt_uint8_t)atoi(argv[3]);
|
||||
chrg_north_sw_rel((eIDX_CH)idx, (eIDX_ID)val);
|
||||
} else if (strcmp(argv[1], "get") == 0) {
|
||||
rt_uint8_t data[3] = {0};
|
||||
data[0] = rt_pin_read(chrgrel[idx].p0);
|
||||
data[1] = rt_pin_read(chrgrel[idx].p1);
|
||||
data[2] = rt_pin_read(chrgrel[idx].p2);
|
||||
if ((1 == data[0])&&(0 == data[1])&&(1 == data[2])) {
|
||||
rt_kprintf("rel connect [%d] : sink\r\n", idx);
|
||||
} else if ((0 == data[0])&&(1 == data[1])&&(1 == data[2])) {
|
||||
rt_kprintf("rel connect [%d] : source\r\n", idx);
|
||||
} else {
|
||||
rt_kprintf("rel connect [%d] : p0=%d, p1=%d, p2=%d\r\n",
|
||||
idx, data[0], data[1], data[2]);
|
||||
}
|
||||
|
||||
} else {
|
||||
return -1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
MSH_CMD_EXPORT(rel_test, test rel connect.);
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user