Skip to content

Commit

Permalink
Shorten code
Browse files Browse the repository at this point in the history
  • Loading branch information
feelfreelinux authored Mar 3, 2017
1 parent e1cb187 commit 3ae7d3a
Showing 1 changed file with 10 additions and 4 deletions.
14 changes: 10 additions & 4 deletions ds18b20.c
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include "freertos/FreeRTOS.h"
#include "freertos/task.h"
Expand All @@ -20,6 +20,7 @@

int DS_GPIO;
int init=0;
/// Sends one bit to bus
void send(char bit){
gpio_set_direction(DS_GPIO, GPIO_MODE_OUTPUT);
gpio_set_level(DS_GPIO,0);
Expand All @@ -28,6 +29,7 @@ void send(char bit){
ets_delay_us(80);
gpio_set_level(DS_GPIO,1);
}
// Reads one bit from bus
unsigned char read(void){
unsigned char PRESENCE=0;
gpio_set_direction(DS_GPIO, GPIO_MODE_OUTPUT);
Expand All @@ -36,9 +38,10 @@ unsigned char read(void){
gpio_set_level(DS_GPIO,1);
ets_delay_us(15);
gpio_set_direction(DS_GPIO, GPIO_MODE_INPUT);
if(gpio_get_level(DS_GPIO)==1){PRESENCE=1;}else{PRESENCE=0;}
if(gpio_get_level(DS_GPIO)==1) PRESENCE=1; else PRESENCE=0;
return(PRESENCE);
}
// Sends one byte to bus
void send_byte(char data){
unsigned char i;
unsigned char x;
Expand All @@ -49,6 +52,7 @@ void send_byte(char data){
}
ets_delay_us(100);
}
// Reads one byte from bus
unsigned char read_byte(void){
unsigned char i;
unsigned char data = 0;
Expand All @@ -59,6 +63,7 @@ unsigned char read_byte(void){
}
return(data);
}
// Sends reset pulse
unsigned char RST_PULSE(void){
unsigned char PRESENCE;
gpio_set_direction(DS_GPIO, GPIO_MODE_OUTPUT);
Expand All @@ -67,11 +72,12 @@ unsigned char RST_PULSE(void){
gpio_set_level(DS_GPIO,1);
gpio_set_direction(DS_GPIO, GPIO_MODE_INPUT);
ets_delay_us(30);
if(gpio_get_level(DS_GPIO)==0){PRESENCE=1;}else{PRESENCE=0;}
if(gpio_get_level(DS_GPIO)==0) PRESENCE=1; else PRESENCE=0;
ets_delay_us(470);
if(gpio_get_level(DS_GPIO)==1){PRESENCE=1;}else{PRESENCE=0;}
if(gpio_get_level(DS_GPIO)==1) PRESENCE=1; else PRESENCE=0;
return PRESENCE;
}
// Returns temperature from sensor
float DS_get_temp(void) {
if(init==1){
unsigned char check;
Expand Down

0 comments on commit 3ae7d3a

Please sign in to comment.