ibutton function for mbed working!

Dependencies:   OneWire mbed

Fork of ibutton by Stijn Sontrop

Revision:
1:d6732fa1e5f8
Parent:
0:39cce56e485b
--- a/main.cpp	Sat Feb 12 11:00:05 2011 +0000
+++ b/main.cpp	Tue Aug 27 16:20:09 2013 +0000
@@ -1,9 +1,10 @@
 #include "mbed.h"
-#define ibuttonpin p20
+//#define ibuttonpin p21
 
 Serial pc(USBTX, USBRX);
 
-DigitalInOut ibuttondata(ibuttonpin);
+//DigitalInOut ibuttondata(ibuttonpin);
+DigitalInOut sensor(p21);
 
 typedef struct {
     unsigned char family;
@@ -26,25 +27,25 @@
 }
 
 void OneWireReset(void) { //Generates reset on 1-wire bus
-    ibuttondata.output();
-    ibuttondata = 0;
+    sensor.output();
+    sensor = 0;
     wait_us(500);
-    ibuttondata.input();
+    sensor.input();
     wait_us(500);
 }
 
 void OneWireOutByte(unsigned char data) { //Write byte on 1-wire bus
     for (int n = 8;n!=0; n--) {
         if ((data & 0x01) == 1) {
-            ibuttondata.output();
-            ibuttondata = 0;
+            sensor.output();
+            sensor = 0;
             wait_us(5);
-            ibuttondata.input();
+            sensor.input();
             wait_us(60);
         } else {
-            ibuttondata.output();
+            sensor.output();
             wait_us(60);
-            ibuttondata.input();
+            sensor.input();
         }
         data = data >> 1;
     }
@@ -54,12 +55,12 @@
     unsigned char d = 0;
     unsigned char b;
     for (int n = 0; n<8; n++) {
-        ibuttondata.output();
-        ibuttondata = 0;
+        sensor.output();
+        sensor = 0;
         wait_us(5);
-        ibuttondata.input();
+        sensor.input();
         wait_us(5);
-        b = ibuttondata;
+        b = sensor;
         wait_us(50);
         d = (d >> 1) | (b << 7);
     }
@@ -87,16 +88,25 @@
     }
     return detect;
 }
+
+//LocalFileSystem local("local");
+
 int main() {
-    ibuttonvalue detected;    
+
+//FILE *fp = fopen("/local/out.txt", "rw");
+
+    ibuttonvalue detected; 
+    int i;   
     while(1) {
         detected = DetectiButton();
         if (detected.valid == 1) { //Test valid flag
             pc.printf("iButton Family: %X Serial: ", detected.family);
-            for (int i = 0; i < 6; i++) {
+            for (i=6-1; i>=0; i--) {
                 pc.printf("%X", detected.serial[i]);
+               // fprintf(fp, "Serial: %X", detected.serial[i]);
+               
             }
             pc.printf(" CRC: %X\n", detected.crc);
-        }
+       }//fclose(fp);
     }
 }