Index: trunk/desktop/mainWindow.rbfrm
===================================================================
--- trunk/desktop/mainWindow.rbfrm	(revision 10)
+++ trunk/desktop/mainWindow.rbfrm	(revision 11)
@@ -138,5 +138,5 @@
       Top             =   32
       Underline       =   ""
-      Value           =   3
+      Value           =   1
       Visible         =   True
       Width           =   637
@@ -2626,4 +2626,62 @@
       XON             =   ""
    End
+   Begin PushButton PushButton_Default
+      AutoDeactivate  =   True
+      Bold            =   ""
+      Cancel          =   ""
+      Caption         =   "Default"
+      Default         =   ""
+      Enabled         =   True
+      Height          =   20
+      HelpTag         =   ""
+      Index           =   -2147483648
+      InitialParent   =   ""
+      Italic          =   ""
+      Left            =   326
+      LockBottom      =   ""
+      LockedInPosition=   False
+      LockLeft        =   ""
+      LockRight       =   ""
+      LockTop         =   ""
+      Scope           =   0
+      TabIndex        =   44
+      TabPanelIndex   =   0
+      TabStop         =   True
+      TextFont        =   "System"
+      TextSize        =   0
+      Top             =   312
+      Underline       =   ""
+      Visible         =   True
+      Width           =   88
+   End
+   Begin PushButton PushButton_SaveProfile
+      AutoDeactivate  =   True
+      Bold            =   ""
+      Cancel          =   ""
+      Caption         =   "Save Profile"
+      Default         =   ""
+      Enabled         =   True
+      Height          =   20
+      HelpTag         =   ""
+      Index           =   -2147483648
+      InitialParent   =   ""
+      Italic          =   ""
+      Left            =   520
+      LockBottom      =   ""
+      LockedInPosition=   False
+      LockLeft        =   ""
+      LockRight       =   ""
+      LockTop         =   ""
+      Scope           =   0
+      TabIndex        =   45
+      TabPanelIndex   =   0
+      TabStop         =   True
+      TextFont        =   "System"
+      TextSize        =   0
+      Top             =   312
+      Underline       =   ""
+      Visible         =   False
+      Width           =   100
+   End
 End
 #tag EndWindow
@@ -2977,4 +3035,49 @@
 	#tag EndEvent
 #tag EndEvents
+#tag Events PopupMenu_Profile
+	#tag Event
+		Sub Change()
+		  if me.Text <> "" then
+		    PushButton_SaveProfile.Visible = true
+		  end if
+		End Sub
+	#tag EndEvent
+	#tag Event
+		Sub Open()
+		  dim s() as string
+		  dim i as integer
+		  
+		  s = ICSSerialPort1.listProfiles
+		  
+		  if UBound(s) > -1 then
+		    for each element as string in s
+		      me.AddRow(element)
+		    next
+		  end if
+		End Sub
+	#tag EndEvent
+#tag EndEvents
+#tag Events PushButton_Create
+	#tag Event
+		Sub Action()
+		  dim tempProfWindow as new createProfile
+		  tempProfWindow.Show
+		End Sub
+	#tag EndEvent
+#tag EndEvents
+#tag Events PushButton_Delete
+	#tag Event
+		Sub Action()
+		  ICSSerialPort1.deleteProfile(PopupMenu_Profile.Text)
+		End Sub
+	#tag EndEvent
+#tag EndEvents
+#tag Events PushButton_Save
+	#tag Event
+		Sub Action()
+		  ICSSerialPort1.saveProfile(PopupMenu_Profile.Text)
+		End Sub
+	#tag EndEvent
+#tag EndEvents
 #tag Events Slider_THGain
 	#tag Event
@@ -3408,2 +3511,25 @@
 	#tag EndEvent
 #tag EndEvents
+#tag Events ICSSerialPort1
+	#tag Event
+		Sub valuesChanged()
+		  //Update the screens with the new values
+		  updateAdvancedScreen
+		  updateCarScreen
+		End Sub
+	#tag EndEvent
+#tag EndEvents
+#tag Events PushButton_Default
+	#tag Event
+		Sub Action()
+		  ICSSerialPort1.setDefaultValues
+		End Sub
+	#tag EndEvent
+#tag EndEvents
+#tag Events PushButton_SaveProfile
+	#tag Event
+		Sub Action()
+		  ICSSerialPort1.saveProfile(PopupMenu_Profile.Text)
+		End Sub
+	#tag EndEvent
+#tag EndEvents
Index: trunk/desktop/FlipSideICS.rbvcp
===================================================================
--- trunk/desktop/FlipSideICS.rbvcp	(revision 5)
+++ trunk/desktop/FlipSideICS.rbvcp	(revision 11)
@@ -6,4 +6,5 @@
 Picture=background;background.jpg;&h527E8FD9;&h0;false;0;&h0
 Class=ICSSerialPort;ICSSerialPort.rbbas;&h73165B84;&h0;false
+Window=createProfile;createProfile.rbfrm;&h565C380D;&h0;false
 DefaultWindow=mainWindow
 AppMenuBar=mainMenuBar
Index: trunk/desktop/ICSSerialPort.rbbas
===================================================================
--- trunk/desktop/ICSSerialPort.rbbas	(revision 10)
+++ trunk/desktop/ICSSerialPort.rbbas	(revision 11)
@@ -99,13 +99,23 @@
 		  case "MR-03"
 		    carType = value
+		    byte15 = chrb(&h05)
+		    byte16 = chrb(&h5A)
+		    byte17 = chrb(&h3C)
 		  case "dNaNo"
 		    carType = value
-		  case "AD"
-		    carType = value
+		    byte15 = chrb(&hFF)
+		    byte16 = chrb(&h80)
+		    byte17 = chrb(&h80)
 		  case "ASF"
 		    carType = value
+		    byte15 = chrb(&hFF)
+		    byte16 = chrb(&hFF)
+		    byte17 = chrb(&hFF)
+		    
 		  else
 		    MsgBox "Error setting Car Type"
 		  end select
+		  
+		  valuesChanged()
 		End Sub
 	#tag EndMethod
@@ -114,4 +124,5 @@
 		Sub writeCar()
 		  //Send set bytes to the car
+		  mode = "write"
 		  
 		  dim sendstring as string
@@ -157,4 +168,6 @@
 		Sub readCar()
 		  //Read values from the currently attached car
+		  
+		  mode = "read"
 		End Sub
 	#tag EndMethod
@@ -175,4 +188,26 @@
 		    end if
 		  end if
+		  
+		  //Set default byte values
+		  byte01 = chrb(&hD5)
+		  byte02 = chrb(&h5A)
+		  byte03 = chrb(&h64)
+		  byte04 = chrb(&hFF)
+		  byte05 = chrb(&h02)
+		  byte06 = chrb(&h02)
+		  byte07 = chrb(&h01)
+		  byte08 = chrb(&hFF)
+		  byte09 = chrb(&hBC)
+		  byte10 = chrb(&h44)
+		  byte11 = chrb(&h88)
+		  byte12 = chrb(&h78)
+		  byte13 = chrb(&hFF)
+		  byte14 = chrb(&h2C)
+		  byte15 = chrb(&h05)
+		  byte16 = chrb(&h5A)
+		  byte17 = chrb(&h3C)
+		  byte18 = chrb(&h87)
+		  
+		  carType = "MR-03"
 		End Sub
 	#tag EndMethod
@@ -198,10 +233,14 @@
 		    if fsicsdb.Connect() then
 		      dim query as string
-		      query = "CREATE TABLE carprofiles (id INTEGER PRIMARY KEY, name VARCHAR, cartype VARCHAR, byte01 VARCHAR, byte02 VARCHAR, byte03 VARCHAR, byte04 VARCHAR, byte05 VARCHAR, byte06 VARCHAR"+_
-		      ", byte07 VARCHAR, byte08 VARCHAR, byte09 VARCHAR, byte10 VARCHAR, byte11 VARCHAR, byte12 VARCHAR, byte13 VARCHAR, byte14 VARCHAR, byte15 VARCHAR, byte16 VARCHAR, byte17 VARCHAR"+_
-		      ", byte18 VARCHAR, UNIQUE(name))"
+		      query = "CREATE TABLE carprofiles (id INTEGER PRIMARY KEY, name VARCHAR, cartype VARCHAR, byte01 INTEGER, byte02 INTEGER, byte03 INTEGER, byte04 INTEGER, byte05 INTEGER, byte06 INTEGER"+_
+		      ", byte07 INTEGER, byte08 INTEGER, byte09 INTEGER, byte10 INTEGER, byte11 INTEGER, byte12 INTEGER, byte13 INTEGER, byte14 INTEGER, byte15 INTEGER, byte16 INTEGER, byte17 INTEGER"+_
+		      ", byte18 INTEGER, UNIQUE(name))"
 		      fsicsdb.SQLExecute(query)
 		      if fsicsdb.Error then
 		        MsgBox "Database Error (carprofiles):" + fsicsdb.ErrorMessage
+		        fsicsdb.Rollback
+		        
+		      else
+		        fsicsdb.Commit
 		      end if
 		      
@@ -217,4 +256,118 @@
 	#tag EndMethod
 
+	#tag Method, Flags = &h0
+		Function createProfile(theName as String) As Boolean
+		  dim success as boolean
+		  success = false
+		  
+		  //Make sure we got a name
+		  if theName = "" then
+		    return success
+		  else
+		    //Build a new database record
+		    dim rec as DatabaseRecord
+		    rec = New DatabaseRecord
+		    
+		    rec.Column("name") = theName
+		    rec.Column("cartype") = carType
+		    rec.IntegerColumn("byte01") = asc(byte01)
+		    rec.IntegerColumn("byte02") = asc(byte02)
+		    rec.IntegerColumn("byte03") = asc(byte03)
+		    rec.IntegerColumn("byte04") = asc(byte04)
+		    rec.IntegerColumn("byte05") = asc(byte05)
+		    rec.IntegerColumn("byte06") = asc(byte06)
+		    rec.IntegerColumn("byte07") = asc(byte07)
+		    rec.IntegerColumn("byte08") = asc(byte08)
+		    rec.IntegerColumn("byte09") = asc(byte09)
+		    rec.IntegerColumn("byte10") = asc(byte10)
+		    rec.IntegerColumn("byte11") = asc(byte11)
+		    rec.IntegerColumn("byte12") = asc(byte12)
+		    rec.IntegerColumn("byte13") = asc(byte13)
+		    rec.IntegerColumn("byte14") = asc(byte14)
+		    rec.IntegerColumn("byte15") = asc(byte15)
+		    rec.IntegerColumn("byte16") = asc(byte16)
+		    rec.IntegerColumn("byte17") = asc(byte17)
+		    rec.IntegerColumn("byte18") = asc(byte18)
+		    
+		    fsicsdb.InsertRecord("carprofiles", rec)
+		    
+		    if fsicsdb.Error = True then
+		      MsgBox "Error creating profile, " + fsicsdb.ErrorMessage
+		      fsicsdb.Rollback
+		    else
+		      fsicsdb.Commit
+		      success = true
+		    end if
+		  end if
+		  
+		  Return success
+		End Function
+	#tag EndMethod
+
+	#tag Method, Flags = &h0
+		Sub deleteProfile(theName as String)
+		  if theName <> "" then
+		    
+		    //Delete the profile selected
+		    fsicsdb.SQLExecute("DELETE FROM carprofiles WHERE name = '" + theName + "'")
+		    
+		    //Check for errors
+		    if fsicsdb.Error = True then
+		      MsgBox "Error deleting profile"
+		      fsicsdb.Rollback
+		    else
+		      fsicsdb.Commit
+		    end if
+		    
+		  else
+		    
+		    MsgBox "Please select a profile to delete"
+		    
+		  end if
+		End Sub
+	#tag EndMethod
+
+	#tag Method, Flags = &h0
+		Sub saveProfile(theName as String)
+		  dim rs as RecordSet
+		  dim status as Boolean
+		  
+		  //Find a record
+		  rs = fsicsdb.SQLSelect("SELECT * FROM carprofiles WHERE name= '"+theName+"'")
+		  
+		  //Make sure we got a record
+		  if rs <> nil then
+		    //delete the record before saving
+		    deleteProfile(theName)
+		  end if
+		  
+		  rs.Close
+		  
+		  status = createProfile(theName)
+		End Sub
+	#tag EndMethod
+
+	#tag Method, Flags = &h0
+		Function listProfiles() As String()
+		  dim rs as RecordSet
+		  dim s() as string
+		  
+		  //Find records
+		  rs = fsicsdb.SQLSelect("SELECT name FROM carprofiles")
+		  
+		  if rs <> nil then
+		    
+		    while rs.EOF = false
+		      s.Append rs.Field("name").StringValue
+		      rs.MoveNext
+		    wend
+		    
+		  end if
+		  
+		  rs.Close
+		  Return s()
+		End Function
+	#tag EndMethod
+
 
 	#tag Hook, Flags = &h0
@@ -233,5 +386,5 @@
 
 	#tag Property, Flags = &h0
-		byte01 As String = "&hFF"
+		byte01 As String
 	#tag EndProperty
 
@@ -310,4 +463,8 @@
 	#tag Property, Flags = &h0
 		fsicsdb As REALSQLDatabase
+	#tag EndProperty
+
+	#tag Property, Flags = &h0
+		mode As String = "read"
 	#tag EndProperty
 
Index: trunk/desktop/createProfile.rbfrm
===================================================================
--- trunk/desktop/createProfile.rbfrm	(revision 11)
+++ trunk/desktop/createProfile.rbfrm	(revision 11)
@@ -0,0 +1,226 @@
+#tag Window
+Begin Window createProfile
+   BackColor       =   &hFFFFFF
+   Backdrop        =   ""
+   CloseButton     =   True
+   Composite       =   False
+   Frame           =   0
+   FullScreen      =   False
+   HasBackColor    =   False
+   Height          =   120
+   ImplicitInstance=   True
+   LiveResize      =   True
+   MacProcID       =   0
+   MaxHeight       =   32000
+   MaximizeButton  =   False
+   MaxWidth        =   32000
+   MenuBar         =   ""
+   MenuBarVisible  =   True
+   MinHeight       =   64
+   MinimizeButton  =   True
+   MinWidth        =   64
+   Placement       =   0
+   Resizeable      =   False
+   Title           =   "Create Profile"
+   Visible         =   True
+   Width           =   300
+   Begin EditField EditField_Name
+      AcceptTabs      =   ""
+      Alignment       =   0
+      AutoDeactivate  =   True
+      BackColor       =   &hFFFFFF
+      Bold            =   ""
+      Border          =   True
+      DataField       =   ""
+      DataSource      =   ""
+      Enabled         =   True
+      Format          =   ""
+      Height          =   22
+      HelpTag         =   ""
+      Index           =   -2147483648
+      InitialParent   =   ""
+      Italic          =   ""
+      Left            =   20
+      LimitText       =   0
+      LockBottom      =   ""
+      LockedInPosition=   False
+      LockLeft        =   ""
+      LockRight       =   ""
+      LockTop         =   ""
+      Mask            =   ""
+      Multiline       =   ""
+      Password        =   ""
+      ReadOnly        =   ""
+      Scope           =   0
+      ScrollbarHorizontal=   ""
+      ScrollbarVertical=   True
+      Styled          =   ""
+      TabIndex        =   0
+      TabPanelIndex   =   0
+      TabStop         =   True
+      Text            =   ""
+      TextColor       =   &h000000
+      TextFont        =   "System"
+      TextSize        =   0
+      Top             =   46
+      Underline       =   ""
+      UseFocusRing    =   True
+      Visible         =   True
+      Width           =   260
+   End
+   Begin PushButton PushButton_OK
+      AutoDeactivate  =   True
+      Bold            =   ""
+      Cancel          =   ""
+      Caption         =   "OK"
+      Default         =   ""
+      Enabled         =   True
+      Height          =   20
+      HelpTag         =   ""
+      Index           =   -2147483648
+      InitialParent   =   ""
+      Italic          =   ""
+      Left            =   20
+      LockBottom      =   ""
+      LockedInPosition=   False
+      LockLeft        =   ""
+      LockRight       =   ""
+      LockTop         =   ""
+      Scope           =   0
+      TabIndex        =   1
+      TabPanelIndex   =   0
+      TabStop         =   True
+      TextFont        =   "System"
+      TextSize        =   0
+      Top             =   80
+      Underline       =   ""
+      Visible         =   True
+      Width           =   80
+   End
+   Begin PushButton PushButton_Cancel
+      AutoDeactivate  =   True
+      Bold            =   ""
+      Cancel          =   ""
+      Caption         =   "Cancel"
+      Default         =   ""
+      Enabled         =   True
+      Height          =   20
+      HelpTag         =   ""
+      Index           =   -2147483648
+      InitialParent   =   ""
+      Italic          =   ""
+      Left            =   200
+      LockBottom      =   ""
+      LockedInPosition=   False
+      LockLeft        =   ""
+      LockRight       =   ""
+      LockTop         =   ""
+      Scope           =   0
+      TabIndex        =   2
+      TabPanelIndex   =   0
+      TabStop         =   True
+      TextFont        =   "System"
+      TextSize        =   0
+      Top             =   80
+      Underline       =   ""
+      Visible         =   True
+      Width           =   80
+   End
+   Begin StaticText StaticText_name
+      AutoDeactivate  =   True
+      Bold            =   ""
+      DataField       =   ""
+      DataSource      =   ""
+      Enabled         =   True
+      Height          =   20
+      HelpTag         =   ""
+      Index           =   -2147483648
+      InitialParent   =   ""
+      Italic          =   ""
+      Left            =   20
+      LockBottom      =   ""
+      LockedInPosition=   False
+      LockLeft        =   ""
+      LockRight       =   ""
+      LockTop         =   ""
+      Multiline       =   ""
+      Scope           =   0
+      TabIndex        =   3
+      TabPanelIndex   =   0
+      Text            =   "Enter new profile name"
+      TextAlign       =   0
+      TextColor       =   &h000000
+      TextFont        =   "System"
+      TextSize        =   0
+      Top             =   14
+      Underline       =   ""
+      Visible         =   True
+      Width           =   260
+   End
+End
+#tag EndWindow
+
+#tag WindowCode
+	#tag Event
+		Sub Open()
+		  allowedText = "ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789 -_."+chr(8)+chr(29)+chr(30)+chr(31)+chr(28)+chr(127)
+		End Sub
+	#tag EndEvent
+
+
+	#tag Property, Flags = &h0
+		allowedText As String
+	#tag EndProperty
+
+
+#tag EndWindowCode
+
+#tag Events EditField_Name
+	#tag Event
+		Function KeyDown(Key As String) As Boolean
+		  Return InStr(allowedText,key)=0
+		End Function
+	#tag EndEvent
+#tag EndEvents
+#tag Events PushButton_OK
+	#tag Event
+		Sub Action()
+		  dim success as Boolean
+		  
+		  
+		  if EditField_Name.Text <> "none" and EditField_Name.Text <> "None" and EditField_Name.Text <> "" then
+		    
+		    success = mainWindow.ICSSerialPort1.createProfile(EditField_Name.Text)
+		    
+		    if success = true then
+		      dim i as integer
+		      
+		      //cheesy way to update the popup menu
+		      mainWindow.PopupMenu_Profile.AddRow(EditField_Name.Text)
+		      
+		      for i = 0 to mainWindow.PopupMenu_Profile.ListCount - 1
+		        if EditField_Name.Text = mainWindow.PopupMenu_Profile.List(i) then
+		          mainWindow.PopupMenu_Profile.ListIndex = i
+		        end if
+		      next
+		      self.Close
+		      
+		    else
+		      
+		      MsgBox "Error creating profile, please try a different name"
+		      
+		    end if
+		    
+		  end if
+		  
+		  
+		End Sub
+	#tag EndEvent
+#tag EndEvents
+#tag Events PushButton_Cancel
+	#tag Event
+		Sub Action()
+		  self.Close
+		End Sub
+	#tag EndEvent
+#tag EndEvents
