![](/media/cache/img/default_profile.jpg.50x50_q85.jpg)
IVSC Project
Revision 4:262764d24e4d, committed 2013-06-07
- Comitter:
- kevinkent
- Date:
- Fri Jun 07 19:59:29 2013 +0000
- Parent:
- 3:0072c2a81472
- Commit message:
- Version 1.2
; Added MSG[0] = 0x06 tow write one pot chain with a single message
Changed in this revision
--- a/DigiPot.cpp Thu Jun 06 22:01:51 2013 +0000 +++ b/DigiPot.cpp Fri Jun 07 19:59:29 2013 +0000 @@ -7,7 +7,7 @@ // Enable pins for PCA9 BusOut Pbus(p14,p13,p12,p11); -//Serial dbg(USBTX, USBRX); +// This is the pins used for I2C and the base address of the chip MCP4651 Chip1(p9, p10, 0x1); MCP4651 Chip2(p9, p10, 0x2); @@ -61,12 +61,12 @@ dbg1.printf("data[3] = %d\n",data[3]); dbg1.printf("data[4] = %d\n",data[4]); dbg1.printf("data[5] = %d\n",data[5]); - if (data[0] != 3) return(1); + if (data[0] != 3) return(1); // should not be here if (data[1] == 0) return(1); // Zero = bus disable if (data[3] == 0) return(1); // Zero disallowed Pbus = data[1]; - if(data[4] > 0) wiper = (data[4] - 1); - value = data[5]; + if(data[4] > 0) wiper = (data[4] - 1); //Wiper on Device is zero based + value = data[5]; // Pot value switch (data[3]) { case 1: @@ -102,3 +102,52 @@ return(0); } // End SetResist +// Decode the HID report and set the pots +// This sets all pots in one string from the same USB message +// The HID report is the same format as SetResist except: +// the Chip#, Pot#, Value must be set for all 6 pots in the string. +// Only the Value is used and Chip# must == The top chip in the string. +int SetResistChain( uint8_t *data) { + + dbg1.printf("Starting string set\n"); + dbg1.printf("data[0] = %d\n",data[0]); + + + if (data[0] != 6) return(1); + if (data[1] == 0) return(1); // Zero = bus disable + if (data[3] == 0) return(1); // Zero = disallowed chip # + Pbus = data[1]; + dbg1.printf("Set Pbus = %d\n", data[1]); + if (data[3] == 1) { + Chip1.SetValue(0, data[5]); + Chip1.SetValue(1, data[8]); + dbg1.printf("Chip1: Wip0 = %d, Wip1 = %d\n", data[5], data[8]); + + Chip2.SetValue(0, data[11]); + Chip2.SetValue(1, data[14]); + dbg1.printf("Chip2: Wip0 = %d, Wip1 = %d\n", data[11], data[14]); + + Chip3.SetValue(0, data[17]); + Chip3.SetValue(1, data[20]); + dbg1.printf("Chip3: Wip0 = %d, Wip1 = %d\n", data[17], data[20]); + } + + if (data[3] == 4) { + Chip4.SetValue(0, data[5]); + Chip4.SetValue(1, data[8]); + dbg1.printf("Chip4: Wip0 = %d, Wip1 = %d\n", data[5], data[8]); + + Chip5.SetValue(0, data[11]); + Chip5.SetValue(1, data[14]); + dbg1.printf("Chip5: Wip0 = %d, Wip1 = %d\n", data[11], data[14]); + + Chip6.SetValue(0, data[17]); + Chip6.SetValue(1, data[20]); + dbg1.printf("Chip6: Wip0 = %d, Wip1 = %d\n", data[17], data[20]); + } + dbg1.printf("Resistor Chain Set Done\n"); + data[0] = 0; + Pbus = 0; + return(0); +} // End SetResistChain +
--- a/DigiPot.h Thu Jun 06 22:01:51 2013 +0000 +++ b/DigiPot.h Fri Jun 07 19:59:29 2013 +0000 @@ -3,3 +3,4 @@ int PotReset(void); int SetResist (uint8_t *); +int SetResistChain (uint8_t *); \ No newline at end of file
--- a/main.cpp Thu Jun 06 22:01:51 2013 +0000 +++ b/main.cpp Fri Jun 07 19:59:29 2013 +0000 @@ -54,7 +54,7 @@ break; case 6: pc.printf("Going to Resistor Chain set\n"); - //Set_Relay(recv.data); + SetResistChain(recv.data); break; default: break;