#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <iothinx/iothinxio.h>
int main(
int argc,
char **
const argv)
{
int32_t rc;
uint32_t relay_slot = 3;
uint8_t relay_channel = 0;
uint32_t relay_values = 0;
uint32_t relay_count = 0;
char ch;
while (-1 != (rc = getopt(argc, argv, "c:hs:")))
{
switch (rc)
{
case 's':
relay_slot = atoi(optarg);
break;
case 'c':
relay_channel = atoi(optarg);
break;
case 'h':
default:
printf("Relay sample program.\n\n");
printf("Usage: ./relay [OPTIONS]\n\n");
printf("Options:\n");
printf("\t%-8s Slot of relay module. Default slot = %d\n", "-s", relay_slot);
printf("\t%-8s Relay channel. Default channel = %d\n", "-c", relay_channel);
printf("\n");
return 0;
}
}
printf("Relay slot = %lu\n", relay_slot);
printf("Relay channel = %u\n", relay_channel);
{
printf("ioThinx_IO_Client_Init() = %d\n", rc);
return -1;
}
{
printf("ioThinx_Relay_GetValues() = %d\n", rc);
}
do
{
if (relay_values & (0x1 << relay_channel))
{
relay_values &= ~(0x1 << relay_channel);
}
else
{
relay_values |= 0x1 << relay_channel;
}
{
printf("ioThinx_DO_GetValues() = %d\n", rc);
}
printf("[%lu:%u] relay value = %x\n", relay_slot, relay_channel, (relay_values >> relay_channel) & 0x1);
{
printf("ioThinx_Relay_GetCurrentCounts() = %d\n", rc);
}
printf("[%lu:%u] relay count = %lu\n", relay_slot, relay_channel, relay_count);
ch = getchar();
}
while (ch != 'q');
return 0;
}
53 uint32_t relay_slot = 3;
54 uint8_t relay_channel = 0;
55 uint32_t relay_values = 0;
56 uint32_t relay_count = 0;
59 while (-1 != (rc = getopt(argc, argv,
"c:hs:")))
64 relay_slot = atoi(optarg);
67 relay_channel = atoi(optarg);
71 printf(
"Relay sample program.\n\n");
72 printf(
"Usage: ./relay [OPTIONS]\n\n");
74 printf(
"\t%-8s Slot of relay module. Default slot = %d\n",
"-s", relay_slot);
75 printf(
"\t%-8s Relay channel. Default channel = %d\n",
"-c", relay_channel);
81 printf(
"Relay slot = %lu\n", relay_slot);
82 printf(
"Relay channel = %u\n", relay_channel);
88 printf(
"ioThinx_IO_Client_Init() = %d\n", rc);
95 printf(
"ioThinx_Relay_GetValues() = %d\n", rc);
102 if (relay_values & (0x1 << relay_channel))
104 relay_values &= ~(0x1 << relay_channel);
108 relay_values |= 0x1 << relay_channel;
114 printf(
"ioThinx_DO_GetValues() = %d\n", rc);
116 printf(
"[%lu:%u] relay value = %x\n", relay_slot, relay_channel, (relay_values >> relay_channel) & 0x1);
121 printf(
"ioThinx_Relay_GetCurrentCounts() = %d\n", rc);
123 printf(
"[%lu:%u] relay count = %lu\n", relay_slot, relay_channel, relay_count);
IOTHINX_ERR ioThinx_Relay_GetCurrentCounts(uint32_t slot, uint8_t start, uint8_t count, uint32_t buf[])
IOTHINX_ERR ioThinx_Relay_GetValues(uint32_t slot, uint32_t *p_values)
IOTHINX_ERR ioThinx_Relay_SetValues(uint32_t slot, uint32_t values)
IOTHINX_ERR ioThinx_IO_Client_Init(void)