Skip to content

Commit

Permalink
Cleanup open TI3410
Browse files Browse the repository at this point in the history
  • Loading branch information
gandalfn committed Apr 17, 2012
1 parent 6bd7638 commit 5cf4307
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 20 deletions.
21 changes: 16 additions & 5 deletions lib/usb/ti-3410-stream.vala
Expand Up @@ -22,6 +22,12 @@ namespace GlucoseBoard
public class TI3410Stream : UsbStreamSerial
{
// types
public enum ConfigurationValue
{
BOOT = 0x01,
ACTIVE = 0x02
}

private enum Commands
{
GET_VERSION = 0x01,
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -197,6 +210,8 @@ namespace GlucoseBoard
}
}

Posix.usleep (100 * 1000);

// Reset device
reset ();
}
Expand Down Expand Up @@ -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));
Expand Down Expand Up @@ -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 ();

Expand Down
12 changes: 12 additions & 0 deletions lib/usb/usb-stream.vala
Expand Up @@ -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;
Expand Down Expand Up @@ -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
Expand All @@ -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)
Expand Down
16 changes: 1 addition & 15 deletions src/modules/abbott/device.vala
Expand Up @@ -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 ();
}
Expand All @@ -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)
Expand Down

0 comments on commit 5cf4307

Please sign in to comment.