Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

adding the tag class

  • Loading branch information...
commit 2a238c5ce2173a52cdbb3137b492c49333b0160e 1 parent 7deb969
@tenderlove authored
View
51 ext/nfc/nfc_device.c
@@ -3,7 +3,8 @@
static VALUE connect(VALUE klass)
{
dev_info * dev = nfc_connect();
- nfc_initiator_init(dev);
+ if(!nfc_initiator_init(dev))
+ rb_raise(rb_eRuntimeError, "oh snap, could not init");
return Data_Wrap_Struct(klass, 0, 0, dev);
}
@@ -17,10 +18,58 @@ static VALUE disconnect(VALUE self)
return self;
}
+static VALUE configure(VALUE self, VALUE option, VALUE flag)
+{
+ dev_info * dev;
+ Data_Get_Struct(self, dev_info, dev);
+
+ nfc_configure(
+ dev,
+ (const dev_config_option)NUM2INT(option),
+ (const bool)NUM2INT(flag)
+ );
+
+ return self;
+}
+
+static VALUE dev_select(VALUE self, VALUE tag)
+{
+ dev_info * dev;
+ Data_Get_Struct(self, dev_info, dev);
+
+ tag_info * ti = calloc(1, sizeof(tag_info));
+
+ nfc_initiator_select_tag(dev, IM_ISO14443A_106, NULL, 0, ti);
+
+ return Data_Wrap_Struct(cNfcISO14443A, 0, free, ti);
+}
+
+static VALUE name(VALUE self)
+{
+ dev_info * dev;
+ Data_Get_Struct(self, dev_info, dev);
+
+ return rb_str_new2(dev->acName);
+}
+
+static VALUE dev_deselect(VALUE self)
+{
+ dev_info * dev;
+ Data_Get_Struct(self, dev_info, dev);
+
+ nfc_initiator_deselect_tag(dev);
+
+ return self;
+}
+
void init_device()
{
VALUE cNfcDevice = rb_define_class_under(cNfc, "Device", rb_cObject);
rb_define_singleton_method(cNfcDevice, "connect", connect, 0);
rb_define_method(cNfcDevice, "disconnect", disconnect, 0);
+ rb_define_method(cNfcDevice, "configure", configure, 2);
+ rb_define_method(cNfcDevice, "select", dev_select, 1);
+ rb_define_method(cNfcDevice, "deselect", dev_deselect, 0);
+ rb_define_method(cNfcDevice, "name", name, 0);
}
View
8 ext/nfc/nfc_iso14443a.c
@@ -0,0 +1,8 @@
+#include <nfc_iso14443a.h>
+
+VALUE cNfcISO14443A;
+
+void init_iso14443a()
+{
+ cNfcISO14443A = rb_define_class_under(cNfc, "ISO14443A", rb_cObject);
+}
View
10 ext/nfc/nfc_iso14443a.h
@@ -0,0 +1,10 @@
+#ifndef NFC_ISO14443A
+#define NFC_ISO14443A
+
+#include <nfc.h>
+
+extern VALUE cNfcISO14443A;
+
+void init_iso14443a();
+
+#endif
View
10 lib/nfc/device.rb
@@ -0,0 +1,10 @@
+class NFC
+ class Device
+ DCO_HANDLE_CRC = 0x00
+ DCO_HANDLE_PARITY = 0x01
+ DCO_ACTIVATE_FIELD = 0x10
+ DCO_INFINITE_LIST_PASSIVE = 0x20
+
+ IM_ISO14443A_106 = 0x00
+ end
+end
Please sign in to comment.
Something went wrong with that request. Please try again.