Don't define TRUE/FALSE, use proper bool

This commit is contained in:
PaulStoffregen
2018-03-15 08:07:42 -07:00
parent 9e08f4e43e
commit 76a13dd6d5
3 changed files with 41 additions and 70 deletions
+27 -34
View File
@@ -328,7 +328,7 @@ void OneWire::reset_search()
{
// reset the search state
LastDiscrepancy = 0;
LastDeviceFlag = FALSE;
LastDeviceFlag = false;
LastFamilyDiscrepancy = 0;
for(int i = 7; ; i--) {
ROM_NO[i] = 0;
@@ -347,7 +347,7 @@ void OneWire::target_search(uint8_t family_code)
ROM_NO[i] = 0;
LastDiscrepancy = 64;
LastFamilyDiscrepancy = 0;
LastDeviceFlag = FALSE;
LastDeviceFlag = false;
}
//
@@ -366,10 +366,11 @@ void OneWire::target_search(uint8_t family_code)
// Return TRUE : device found, ROM number in ROM_NO buffer
// FALSE : device not found, end of search
//
uint8_t OneWire::search(uint8_t *newAddr, bool search_mode /* = true */)
bool OneWire::search(uint8_t *newAddr, bool search_mode /* = true */)
{
uint8_t id_bit_number;
uint8_t last_zero, rom_byte_number, search_result;
uint8_t last_zero, rom_byte_number;
bool search_result;
uint8_t id_bit, cmp_id_bit;
unsigned char rom_byte_mask, search_direction;
@@ -379,19 +380,17 @@ uint8_t OneWire::search(uint8_t *newAddr, bool search_mode /* = true */)
last_zero = 0;
rom_byte_number = 0;
rom_byte_mask = 1;
search_result = 0;
search_result = false;
// if the last call was not the last one
if (!LastDeviceFlag)
{
if (!LastDeviceFlag) {
// 1-Wire reset
if (!reset())
{
if (!reset()) {
// reset the search
LastDiscrepancy = 0;
LastDeviceFlag = FALSE;
LastDeviceFlag = false;
LastFamilyDiscrepancy = 0;
return FALSE;
return false;
}
// issue the search command
@@ -409,26 +408,23 @@ uint8_t OneWire::search(uint8_t *newAddr, bool search_mode /* = true */)
cmp_id_bit = read_bit();
// check for no devices on 1-wire
if ((id_bit == 1) && (cmp_id_bit == 1))
if ((id_bit == 1) && (cmp_id_bit == 1)) {
break;
else
{
} else {
// all devices coupled have 0 or 1
if (id_bit != cmp_id_bit)
if (id_bit != cmp_id_bit) {
search_direction = id_bit; // bit write value for search
else
{
} else {
// if this discrepancy if before the Last Discrepancy
// on a previous next then pick the same as last time
if (id_bit_number < LastDiscrepancy)
if (id_bit_number < LastDiscrepancy) {
search_direction = ((ROM_NO[rom_byte_number] & rom_byte_mask) > 0);
else
} else {
// if equal to last pick 1, if not then pick 0
search_direction = (id_bit_number == LastDiscrepancy);
}
// if 0 was picked then record its position in LastZero
if (search_direction == 0)
{
if (search_direction == 0) {
last_zero = id_bit_number;
// check for Last discrepancy in family
@@ -453,8 +449,7 @@ uint8_t OneWire::search(uint8_t *newAddr, bool search_mode /* = true */)
rom_byte_mask <<= 1;
// if the mask is 0 then go to new SerialNum byte rom_byte_number and reset mask
if (rom_byte_mask == 0)
{
if (rom_byte_mask == 0) {
rom_byte_number++;
rom_byte_mask = 1;
}
@@ -463,26 +458,24 @@ uint8_t OneWire::search(uint8_t *newAddr, bool search_mode /* = true */)
while(rom_byte_number < 8); // loop until through all ROM bytes 0-7
// if the search was successful then
if (!(id_bit_number < 65))
{
if (!(id_bit_number < 65)) {
// search successful so set LastDiscrepancy,LastDeviceFlag,search_result
LastDiscrepancy = last_zero;
// check for last device
if (LastDiscrepancy == 0)
LastDeviceFlag = TRUE;
search_result = TRUE;
if (LastDiscrepancy == 0) {
LastDeviceFlag = true;
}
search_result = true;
}
}
// if no device found then reset counters so next 'search' will be like a first
if (!search_result || !ROM_NO[0])
{
if (!search_result || !ROM_NO[0]) {
LastDiscrepancy = 0;
LastDeviceFlag = FALSE;
LastDeviceFlag = false;
LastFamilyDiscrepancy = 0;
search_result = FALSE;
search_result = false;
} else {
for (int i = 0; i < 8; i++) newAddr[i] = ROM_NO[i];
}
+2 -9
View File
@@ -51,13 +51,6 @@
#define ONEWIRE_CRC16 1
#endif
#ifndef FALSE
#define FALSE 0
#endif
#ifndef TRUE
#define TRUE 1
#endif
// Board-specific macros for direct GPIO
#include "util/OneWire_direct_regtype.h"
@@ -72,7 +65,7 @@ class OneWire
unsigned char ROM_NO[8];
uint8_t LastDiscrepancy;
uint8_t LastFamilyDiscrepancy;
uint8_t LastDeviceFlag;
bool LastDeviceFlag;
#endif
public:
@@ -130,7 +123,7 @@ class OneWire
// might be a good idea to check the CRC to make sure you didn't
// get garbage. The order is deterministic. You will always get
// the same devices in the same order.
uint8_t search(uint8_t *newAddr, bool search_mode = true);
bool search(uint8_t *newAddr, bool search_mode = true);
#endif
#if ONEWIRE_CRC
+12 -27
View File
@@ -1,25 +1,25 @@
/*
DS250x add-only programmable memory reader w/SKIP ROM.
The DS250x is a 512/1024bit add-only PROM(you can add data but cannot change the old one) that's used mainly for device identification purposes
like serial number, mfgr data, unique identifiers, etc. It uses the Maxim 1-wire bus.
This sketch will use the SKIP ROM function that skips the 1-Wire search phase since we only have one device connected in the bus on digital pin 6.
If more than one device is connected to the bus, it will fail.
Sketch will not verify if device connected is from the DS250x family since the skip rom function effectively skips the family-id byte readout.
thus it is possible to run this sketch with any Maxim OneWire device in which case the command CRC will most likely fail.
Sketch will only read the first page of memory(32bits) starting from the lower address(0000h), if more than 1 device is present, then use the sketch with search functions.
Remember to put a 4.7K pullup resistor between pin 6 and +Vcc
To change the range or ammount of data to read, simply change the data array size, LSB/MSB addresses and for loop iterations
This example code is in the public domain and is provided AS-IS.
Built with Arduino 0022 and PJRC OneWire 2.0 library http://www.pjrc.com/teensy/td_libs_OneWire.html
created by Guillermo Lovato <glovato@gmail.com>
march/2011
*/
#include <OneWire.h>
@@ -40,7 +40,7 @@ void loop() {
present = ds.reset(); // OneWire bus reset, always needed to start operation on the bus, returns a 1/TRUE if there's a device present.
ds.skip(); // Skip ROM search
if (present == TRUE){ // We only try to read the data if there's a device present
if (present == true) { // We only try to read the data if there's a device present
Serial.println("DS250x device present");
ds.write(leemem[0],1); // Read data command, leave ghost power on
ds.write(leemem[1],1); // LSB starting address, leave ghost power on
@@ -57,34 +57,19 @@ void loop() {
Serial.println(ccrc,HEX);
return; // Since CRC failed, we abort the rest of the loop and start over
}
Serial.println("Data is: "); // For the printout of the data
Serial.println("Data is: "); // For the printout of the data
for ( i = 0; i < 32; i++) { // Now it's time to read the PROM data itself, each page is 32 bytes so we need 32 read commands
data[i] = ds.read(); // we store each read byte to a different position in the data array
data[i] = ds.read(); // we store each read byte to a different position in the data array
Serial.print(data[i]); // printout in ASCII
Serial.print(" "); // blank space
Serial.print(" "); // blank space
}
Serial.println();
delay(5000); // Delay so we don't saturate the serial output
}
else { // Nothing is connected in the bus
else { // Nothing is connected in the bus
Serial.println("Nothing connected");
delay(3000);
}
}