wbs_michael

=Michael West=

Role: Integration and Software

To Do List: > >
 * Set [|http://www.mtrx3700.wikispaces.com] as a homepage.
 * Write serial transmission code and upload it to the Modules  page.
 * Peer review get_AD_value . Suggest changes if necessary.
 * Peer review store_sample. Suggest changes if necessary.

Hi Michael, I put this together for COUNT mode - I thought I would share it with you so you can see how I chose to wait for user input. Tell me if you think it will work. code format="c" count_mode(void) {	int i = 0; char itemStr[4]; transmit(COUNT1); //You are in count mode. Please place one or more identical items on the scales. totalMass = weigh; transmit(int_to_string(totalMass)); transmit(COUNT2); //How many items are on the scales? //settings.recieveMode = RAW; //save numbers from string, don't interperet or change modes

numstart = recvbuf_iPtr; //Remember the start of the recieve string //Wait for an, then return the number from the recvstring while(*recvbuf_iPtr != 0x0D || *recvbuf_iPtr != 0x0A) {		//wait for an enter/lf to indicate user has entered a number }

for(i = 0; recvbuf_ePtr < recvbuf_iPtr; i++) {		itemStr[i] = *recvbuf_ePtr; }	itemStr[i] == '\0';

items = str_to_int(itemStr);

itemMass = totalMass/items;

transmit(COUNT3); //Now, put an unknown number of items on the scales, then press enter.

while(*recvbuf_iPtr != 0x0D || *recvbuf_iPtr != 0x0A) {		//wait for an enter/lf to indicate user is done }

transmit(int_to_string(getMass/itemMass);

}

int str_to_int(char* string) {	int sum; int length = strlen(string); int multiplicand = 1;

for(length = strlen(string); length > 0; length--) {		sum += (string[length] - '0')*multiplicand; multiplicand *= 10; }

return sum; } code