premise:

I am using an FTDI C232H cable to communicate via I2C protocol to a MAX31785 fan controller. I have a basic script setup
that can communicate with the fan controller and do other meaningful stuff. I want to convert that into a GUI that just has a
column of buttons on the left side that perform various functions, program, read temp, read fan rpm, and then write the
output and stuff to a text area.

Problem/Question:

I am not sure how to go about this using Qt. I am sure there are at least a dozen ways to perform this task but I am not sure
which one would work the best and make the most sense. Basically I want to transform all the fprints() to a write to the text area.

here is the script that I currently have:

Qt Code:
  1. #include <stdio.h>
  2. #include <tchar.h>
  3. #include <Windows.h>
  4. #include "Headers/ftd2xx.h"
  5. #include "Headers/libMPSSE_i2c.h"
  6.  
  7. using namespace std;
  8.  
  9.  
  10.  
  11. /******************************************************************************/
  12. /* Function Definitions */
  13. /******************************************************************************/
  14. /* Helper macros */
  15.  
  16.  
  17. void Check_Status(unsigned long exp)
  18. {
  19. if(exp!=FT_OK)
  20. {
  21. printf("\n\n\n%s: %d : %s(): \n status(0x%x)=\n",__FILE__, __LINE__, __FUNCTION__,exp);
  22. getchar();
  23. exit(1);
  24. }
  25. else
  26. {
  27. ;
  28. }
  29. }
  30.  
  31. FT_STATUS status;
  32. FT_HANDLE Handle;
  33.  
  34.  
  35. //int _tmain(int argc, _TCHAR* argv[])
  36. int main()
  37. {
  38. //FTDI Driver stuff
  39. FT_DEVICE_LIST_INFO_NODE devList;
  40. uint32 channels;
  41. int channelOpen = 0;
  42.  
  43. // EEPROM reading variables and structures
  44. char Manufacturer[64];
  45. char ManufacturerID[64];
  46. char Description[64];
  47. char SerialNumber[64];
  48.  
  49. FT_EEPROM_HEADER ft_eeprom_header;
  50. ft_eeprom_header.deviceType = FT_DEVICE_232H;
  51.  
  52. FT_EEPROM_232H ft_eeprom_232h;
  53. ft_eeprom_232h.common = ft_eeprom_header;
  54. ft_eeprom_232h.common.deviceType = FT_DEVICE_232H;
  55.  
  56. // libMPSSE-related variables
  57. ChannelConfig channelConf;
  58. Init_libMPSSE();
  59. //General variables
  60. uint32 TrialAddress = 0x00;
  61. int i;
  62. int j;
  63. uint8 i2cAddress = 0x00;
  64. unsigned char i2cDataSend[1024] = {0}; // Initialize a data buffer and set to all Zeros
  65. unsigned char i2cDataReceive[1024] = {0}; // Initialize a data buffer and set to all Zeros
  66. uint32 i2cNumBytesToTx = 0; // Initialize a counter for the buffer and set to Zero
  67. uint32 i2cNumBytesTxd = 0; // Initialize another counter for the number of bytes actually sent and set to Zero
  68. uint32 i2cNumBytesToRx = 0; // Initialize a counter for the recieve buffer and set to Zero
  69. uint32 i2cNumBytesRxd = 0; // Initialize another counter for the number of bytes actually recieved and set to Zero
  70.  
  71.  
  72. channelConf.ClockRate = I2C_CLOCK_STANDARD_MODE;// 100,000 Hz
  73. channelConf.LatencyTimer= 255;
  74. channelConf.Options = I2C_DISABLE_3PHASE_CLOCKING;
  75. printf("Press Enter to Start");
  76. getchar();
  77.  
  78. status = I2C_GetNumChannels(&channels);
  79. Check_Status(status);
  80. printf("Number of available I2C channels = %d\n",channels);
  81. //Get information on each available channel.
  82. if(channels>0)
  83. {
  84. for(i=0;i<channels;i++)
  85. {
  86. status = I2C_GetChannelInfo(i, &devList);
  87. Check_Status(status);
  88. printf("Information on channel number %d:\n",i);
  89. //print the dev info
  90. printf(" Flags=0x%x\n", devList.Flags);
  91. printf(" Type=0x%x\n", devList.Type);
  92. printf(" ID=0x0%x\n", devList.ID);
  93. printf(" LocId=0x%x\n", devList.LocId);
  94. printf(" SerialNumber=%s\n", devList.SerialNumber);
  95. printf(" Description=%s\n", devList.Description);
  96. }
  97. }
  98. else
  99. {
  100. printf("No FTDI devices were found\n");
  101. getchar();
  102. return 0;
  103. }
  104.  
  105.  
  106. //
  107. //I2C_OpenChannel
  108. status = FT_Open(channelOpen,&Handle);
  109. if (status == FT_OK)
  110. {
  111. printf("Channel %d has been successfully opened\n", channelOpen);
  112. }
  113. else
  114. {
  115. printf("Channel %d is unable to be opened\n", channelOpen);
  116. printf("status = 0x%x\n");
  117. getchar();
  118. return 0;
  119. }
  120. printf("Reading the EEPROM...\n");
  121. status = FT_EEPROM_Read(Handle, &ft_eeprom_232h, sizeof(ft_eeprom_232h), Manufacturer, ManufacturerID, Description, SerialNumber);
  122. if (status == FT_OK)
  123. {
  124. printf(" VendorID = 0x%04x\n", ft_eeprom_232h.common.VendorId);
  125. printf(" ProductID = 0x%04x\n", ft_eeprom_232h.common.ProductId);
  126. printf(" Manufacturer = %s\n",Manufacturer);
  127. printf(" Manufacturer ID = %s\n",ManufacturerID);
  128. printf(" Description = %s \n", Description);
  129. printf(" SerialNumber = %s \n", SerialNumber);
  130. }
  131. else
  132. {
  133. printf("Unable to read EEPROM\n");
  134. }
  135.  
  136. printf("Initializing for I2C operation...\n");
  137. status = I2C_InitChannel(Handle,&channelConf);
  138. if (status == FT_OK)
  139. {
  140. printf("Channel %d has been successfully initialized.\n", channelOpen);
  141. }
  142. else
  143. {
  144. printf("Channel %d is unable to be initialized\n", channelOpen);
  145. printf("status = 0x%x\n", status);
  146. getchar();
  147. I2C_CloseChannel(Handle);
  148. return 0;
  149. }
  150. getchar();
  151. printf("Searching for I2C devices... ");
  152. j = 0;
  153.  
  154. //this section finds all MAX chips by sending out the write_protect command
  155. //on every availavle 7 bit I2C address, not including address 0x00 because that is
  156. //a broadcast address
  157.  
  158. i2cNumBytesToTx = 0;
  159. i2cDataSend[i2cNumBytesToTx++] = 0x10; //Write_Protect Command
  160. i2cDataSend[i2cNumBytesToTx++] = 0x00; //Disable write protect
  161. for (i = 0x00; i < 128; i++)
  162. {
  163. TrialAddress = i;
  164. status = I2C_DeviceWrite(Handle, TrialAddress, i2cNumBytesToTx, i2cDataSend, &i2cNumBytesTxd, 0x07);
  165. if (status == FT_OK)
  166. {
  167.  
  168. j++;
  169. printf("\n I2C Address %X Responded\n",i);
  170. }
  171. else
  172. {
  173. ;
  174. }
  175. }
  176. if (j == 0)
  177. {
  178. printf("Could not find any I2C devices\n");
  179. }
  180. printf("\n\nThat is all for now, move along,\n nothing more to see here,\n move along to another program \n");
  181. getchar();
  182. Cleanup_libMPSSE();
  183. }
To copy to clipboard, switch view to plain text mode