Update mqttd hal code, can control relay now
| | |
| | | |
| | | int hal_init(void) |
| | | { |
| | | wiringPiSetup(); |
| | | |
| | | init_led(); |
| | | relay_init(); |
| | | init_relay(); |
| | | |
| | | #if 0 |
| | | if( sht2x_init() < 0 ) |
| | |
| | | #ifndef _HAL_H_ |
| | | #define _HAL_H_ |
| | | |
| | | #include <wiringPi.h> |
| | | |
| | | #include "lylib/logger.h" |
| | | |
| | | #include "led.h" |
| | |
| | | * |
| | | * pi@raspberrypi:~ $ gpio readall show BCM and wPi pinmap |
| | | * |
| | | * LED BCM wPi |
| | | * G ---- GPIO.13 ---- GPIO.23 |
| | | * R ---- GPIO.19 ---- GPIO.24 |
| | | * B ---- GPIO.26 ---- GPIO.25 |
| | | * LED BCM wPi Phy Pin |
| | | * G ---- GPIO.13 ---- GPIO.23 ---- #Pin33 |
| | | * R ---- GPIO.19 ---- GPIO.24 ---- #Pin35 |
| | | * B ---- GPIO.26 ---- GPIO.25 ---- #Pin37 |
| | | * I ---- GND ---- |
| | | * |
| | | * Version: 1.0.0(2018/10/14) |
| | |
| | | { |
| | | int i; |
| | | |
| | | wiringPiSetup(); |
| | | |
| | | for(i=0; i<LED_MAX; i++) |
| | | { |
| | | pinMode( led_gpio[i], OUTPUT ); |
| | | pinMode( led_gpio[i], OUTPUT ); |
| | | } |
| | | } |
| | | |
| | |
| | | if( which<0 || which>=LED_MAX ) |
| | | return -1; |
| | | |
| | | |
| | | if( OFF == cmd ) |
| | | digitalWrite (led_gpio[which], LOW); |
| | | else |
| | | digitalWrite (led_gpio[which], HIGH); |
| | | digitalWrite (led_gpio[which], LOW); |
| | | else |
| | | digitalWrite (led_gpio[which], HIGH); |
| | | |
| | | return 0; |
| | | } |
| | |
| | | * |
| | | * pi@raspberrypi:~ $ gpio readall show BCM and wPi pinmap |
| | | * |
| | | * LED BCM wPi |
| | | * G ---- GPIO.13 ---- GPIO.23 |
| | | * R ---- GPIO.19 ---- GPIO.24 |
| | | * B ---- GPIO.26 ---- GPIO.25 |
| | | * LED BCM wPi #PIN |
| | | * G ---- GPIO.13 ---- GPIO.23 ---- 33 |
| | | * R ---- GPIO.19 ---- GPIO.24 ---- 35 |
| | | * B ---- GPIO.26 ---- GPIO.25 ---- 37 |
| | | * I ---- GND ---- |
| | | * |
| | | * Version: 1.0.0(2018/10/14) |
| | |
| | | ********************************************************************************/ |
| | | |
| | | |
| | | #include <stdio.h> |
| | | #include <wiringPi.h> |
| | | #include "relay.h" |
| | | |
| | | void relay_init(void) |
| | | void init_relay(void) |
| | | { |
| | | wiringPiSetup(); |
| | | pinMode(RELAY_PIN, OUTPUT); |
| | | } |
| | | |
| | |
| | | { |
| | | if( OFF == cmd ) |
| | | { |
| | | digitalWrite ( RELAY_PIN, HIGH ); |
| | | digitalWrite ( RELAY_PIN, LOW ); |
| | | } |
| | | else |
| | | { |
| | | digitalWrite ( RELAY_PIN, LOW ); |
| | | digitalWrite ( RELAY_PIN, HIGH ); |
| | | } |
| | | } |
| | | |
| | |
| | | #define OFF 0 |
| | | #endif |
| | | |
| | | /* I/O Pin connected to PIN#18, BCM code pin number is 24 and wPi pin number is 5 */ |
| | | #define RELAY_PIN 5 |
| | | |
| | | void relay_init(void); |
| | | /* I/O Pin connected to PIN#40, BCM code pin number is 21 and wPi pin number is 29, |
| | | * can check by linux command <gpio readall> on RPi */ |
| | | #define RELAY_PIN 29 |
| | | |
| | | void init_relay(void); |
| | | void turn_relay(int cmd); |
| | | |
| | | #endif /* ----- #ifndef _RELAY_H_ ----- */ |
| | |
| | | return -1; |
| | | } |
| | | log_nrml("HAL initialise ok\n"); |
| | | |
| | | |
| | | install_proc_signal(); |
| | | |
| | | if( check_set_program_running(daemon) < 0 ) |