Permalink
Browse files

Cleanup open TI3410

  • Loading branch information...
1 parent 6bd7638 commit 5cf430726849ec1d74b370baf4c73fc280cbdf50 @gandalfn committed Apr 17, 2012
Showing with 29 additions and 20 deletions.
  1. +16 −5 lib/usb/ti-3410-stream.vala
  2. +12 −0 lib/usb/usb-stream.vala
  3. +1 −15 src/modules/abbott/device.vala
View
21 lib/usb/ti-3410-stream.vala
@@ -22,6 +22,12 @@ namespace GlucoseBoard
public class TI3410Stream : UsbStreamSerial
{
// types
+ public enum ConfigurationValue
+ {
+ BOOT = 0x01,
+ ACTIVE = 0x02
+ }
+
private enum Commands
{
GET_VERSION = 0x01,
@@ -76,6 +82,13 @@ namespace GlucoseBoard
uint8 mode;
}
+ public enum UARTType
+ {
+ RS232 = 0x00,
+ RS485_RECEIVER_DISABLED = 0x01,
+ RS485_RECEIVER_ENABLED = 0x02
+ }
+
private enum UARTFlags
{
ENABLE_RTS_IN = 0x0001,
@@ -197,6 +210,8 @@ namespace GlucoseBoard
}
}
+ Posix.usleep (100 * 1000);
+
// Reset device
reset ();
}
@@ -295,7 +310,7 @@ namespace GlucoseBoard
m_Config.flags = UARTFlags.ENABLE_MS_INTS | UARTFlags.ENABLE_AUTO_START_DMA;
// use rs232
- m_Config.mode = 0;
+ m_Config.mode = UARTType.RS232;
// set baud rate
m_Config.baud_rate = (uint16)(14769230.77 / (inConfig.baud_rate * 16));
@@ -364,10 +379,6 @@ namespace GlucoseBoard
// Configure serial communication
set_config ();
- // lock end point since open and start port
- clear_halt_read_ep ();
- clear_halt_write_ep ();
-
// Open port
open_port ();
View
12 lib/usb/usb-stream.vala
@@ -29,6 +29,7 @@ namespace GlucoseBoard
private uint m_Interface;
private uint m_EndPointRead;
private uint m_EndPointWrite;
+ private uint8 m_ConfigurationValue;
private bool m_ReadEndPointAvailable;
private LibUSB.TransferType m_ReadTransferType;
private uint m_ReadMaxPacketSize;
@@ -62,6 +63,16 @@ namespace GlucoseBoard
}
}
+ public uint8 configuration_value {
+ get {
+ return m_ConfigurationValue;
+ }
+ set {
+ if (m_Handle != null)
+ m_Handle.set_configuration (value);
+ }
+ }
+
// methods
/**
* Create new usb stream for inDevice
@@ -86,6 +97,7 @@ namespace GlucoseBoard
bool found_interface = false;
m_ReadEndPointAvailable = false;
m_WriteEndPointAvailable = false;
+ m_ConfigurationValue = config.bConfigurationValue;
// Search interface
for (int cpt = 0; cpt < config.bNumInterfaces; ++cpt)
View
16 src/modules/abbott/device.vala
@@ -85,7 +85,7 @@ namespace GlucoseBoard.Module.Abbott
m_Stream = new TI3410Stream (this, m_UsbInterface, m_UsbEndPointRead, m_UsbEndPointWrite);
// Read end point is not available load firmware
- if (!m_Stream.read_ep_available)
+ if (m_Stream.configuration_value == TI3410Stream.ConfigurationValue.BOOT)
{
load_firmware ();
}
@@ -97,20 +97,6 @@ namespace GlucoseBoard.Module.Abbott
// Open stream
m_Stream.open ();
-
- // Send mem message
- m_Stream.send (new Message (), 1000);
- m_Stream.send (new Message.mem (), 1000);
-
- // Close stream
- m_Stream.close ();
-
- // Open stream
- m_Stream.open ();
-
- // Send xmem message
- m_Stream.send (new Message (), 1000);
- m_Stream.send (new Message.xmem (), 1000);
}
}
catch (GLib.Error err)

0 comments on commit 5cf4307

Please sign in to comment.