New file |
| | |
| | | /********************************************************************************* |
| | | * Copyright: (C) 2019 LingYun IoT System Studio |
| | | * All rights reserved. |
| | | * |
| | | * Filename: relay.c |
| | | * Description: This file |
| | | * |
| | | * Version: 1.0.0(30/01/19) |
| | | * Author: Guo Wenxue <guowenxue@gmail.com> |
| | | * ChangeLog: 1, Release initial version on "30/01/19 08:44:30" |
| | | * |
| | | ********************************************************************************/ |
| | | |
| | | #include <stdio.h> |
| | | #include <unistd.h> |
| | | #include <libgen.h> |
| | | |
| | | #include <string.h> |
| | | |
| | | #include <wiringPi.h> |
| | | #include "relay.h" |
| | | |
| | | int main (int argc, char **argv) |
| | | { |
| | | if( argc != 2 ) |
| | | { |
| | | printf("Usage: %s [on/off]\n", basename(argv[0])); |
| | | return -1; |
| | | } |
| | | |
| | | wiringPiSetup(); |
| | | relay_init(); |
| | | |
| | | if( !strstr(argv[1], "on") || !strstr(argv[1], "on") ) |
| | | { |
| | | turn_relay(ON); |
| | | } |
| | | else if( !strstr(argv[1], "off") || !strstr(argv[1], "off") ) |
| | | { |
| | | turn_relay(OFF); |
| | | } |
| | | |
| | | return 0; |
| | | } |
| | | |
| | | void relay_init(void) |
| | | { |
| | | pinMode(RELAY_PIN, OUTPUT); |
| | | } |
| | | |
| | | |
| | | void turn_relay(int cmd) |
| | | { |
| | | if( OFF == cmd ) |
| | | { |
| | | digitalWrite ( RELAY_PIN, HIGH ); |
| | | } |
| | | else |
| | | { |
| | | digitalWrite ( RELAY_PIN, LOW ); |
| | | } |
| | | } |
| | | |