void I2C_OnWriteReq(void) { /* Called by a master 'write' request on the bus. It is always followed by the device memory address. * At this time we have the device address on the bus, but not the address yet. */ dbgF(I2C_DEBUG_WriteReq); I2C_ClearBuffers(); memDevice.nextRXisMemAddress = TRUE; /* next byte on bus will be memory address */ }
static portTASK_FUNCTION(TaskRunner, pvParameters) { RUNNER_WindowDesc *ui = (RUNNER_WindowDesc*)pvParameters; char_t buf[I2C_RUNNER_I2C_MSG_SIZE]; uint8_t cnt; bool errorCond; appWp = ui; #if PL_APP_MODE_I2C_LCD I2C_ClearBuffers(); #endif ResetRunnerDisplayList(); RUNNER_listLastRecords = TRUE; /* request getting runners */ cnt = 0; for (;;) { I2C_SendCmd(); errorCond = FALSE; while (I2C_GetRunnerMessage(buf, sizeof(buf))==ERR_OK) { /* message received, process as many and as fast as possible */ if (ParseNewRunnerMsg(buf)!=ERR_OK) { errorCond = TRUE; /* flag error */ } } /* while */ DisplayRunners(ui); if (errorCond) { UI1_DrawFilledBox(&appWp->window, 120, 8, 5, 5, UI1_COLOR_RED); } else { UI1_DrawFilledBox(&appWp->window, 120, 8, 5, 5, UI1_COLOR_BLUE); } FRTOS1_vTaskDelay(100/portTICK_RATE_MS); cnt++; UI1_DrawFilledBox(&appWp->window, 110, 8, 5, 5, cnt<10?UI1_COLOR_BLUE:UI1_COLOR_GREEN); if (cnt==20) { cnt=0; } } /* for */ }
static portTASK_FUNCTION(TaskMotorDemo, pvParameters) { MOTOR_WindowDesc *ui = (MOTOR_WindowDesc*)pvParameters; UIG1_DataPoint data[2], prevData[2]; appWp = ui; #if PL_APP_MODE_I2C_LCD I2C_ClearBuffers(); #endif /* current speed: */ data[0].color = UI1_COLOR_RED; data[0].data = 0; /* desired PID speed: */ data[1].color = UI1_COLOR_BLUE; data[1].data = 0; /* previous data information */ prevData[0].color = UI1_COLOR_BLUE; prevData[0].data = 0; prevData[1].color = UI1_COLOR_RED; prevData[1].data = 0; for (;;) { #if PL_HAS_I2C_COMM I2C_StoreCmd(); data[0].data = RangeSpeed(I2C_GetMotorDesiredSpeed()); data[1].data = RangeSpeed(I2C_GetMotorActualSpeed()); #else data[0].data = 50; data[1].data = 60; #endif (void)UIG1_AddDataLine((UI1_Element *)&ui->graph, &prevData[0], &data[0], 2); /* remember data for next iteration */ prevData[0].data = data[0].data; prevData[1].data = data[1].data; if (EVNT1_GetEvent(EVNT1_APP_MODE_CHANGE)) { /* request to close application */ EVNT1_ClearEvent(EVNT1_APP_MODE_CHANGE); /* reset event flag */ xHandleTaskMotorDemo = NULL; FRTOS1_vTaskDelete(NULL); /* kill ourself */ } FRTOS1_vTaskDelay(20/portTICK_RATE_MS); } /* for */ }
static portTASK_FUNCTION(TaskAccelDemo, pvParameters) { int16_t x,y,z; ACCEL_WindowDesc *ui = (ACCEL_WindowDesc*)pvParameters; unsigned char buf[sizeof("X: 123")]; UIG1_DataPoint data[3], prevData[3]; appWp = ui; #if PL_APP_MODE_I2C_LCD I2C_ClearBuffers(); #endif data[0].color = UI1_COLOR_RED; data[0].data = 0; data[1].color = UI1_COLOR_BLUE; data[1].data = 0; data[2].color = UI1_COLOR_DARK_GREEN; data[3].data = 0; prevData[0].color = UI1_COLOR_RED; prevData[0].data = 0; prevData[1].color = UI1_COLOR_BLUE; prevData[1].data = 0; prevData[2].color = UI1_COLOR_DARK_GREEN; prevData[2].data = 0; for (;;) { /* we are getting the values in milli-g (means: around -1200 to +1200 */ #if PL_HAS_AUTO_DEMO && PL_HAS_HW_ACCELEROMETER /* for demo, make values more interesting */ x = ACCEL1_GetX(); y = ACCEL1_GetY(); z = ACCEL1_GetZ(); while (z>900) { /* put in range */ z /= 2; } #else x = ACCEL_GetX(); y = ACCEL_GetY(); z = ACCEL_GetZ(); #endif /* cap to -100..+100 */ x /= 11; /* little bit more than 10, just to have 1g not always hitting the limit of 100% */ y /= 11; z /= 11; /* make sure it is in the -100..+100 range */ if (x>100) { x = 100; } else if (x<-100) { x = -100; } if (y>100) { y = 100; } else if (y<-100) { y = -100; } if (z>100) { z = 100; } else if (z<-100) { z = -100; } /* midpoint of graph is at 50% */ x = 50+(x/2); /* scale between 0..100% */ y = 50+(y/2); /* scale between 0..100% */ z = 50+(z/2); /* scale between 0..100% */ UTIL1_strcpy(buf, sizeof(buf), (unsigned char*)"X: "); UTIL1_strcatNum16s(buf, sizeof(buf), x); UI1_ChangeText(&ui->window, (UI1_Element *)&ui->txtX, sizeof(ui->txtBufX), buf); UTIL1_strcpy(buf, sizeof(buf), (unsigned char*)"Y: "); UTIL1_strcatNum16s(buf, sizeof(buf), y); UI1_ChangeText(&ui->window, (UI1_Element *)&ui->txtY, sizeof(ui->txtBufY), buf); UTIL1_strcpy(buf, sizeof(buf), (unsigned char*)"Z: "); UTIL1_strcatNum16s(buf, sizeof(buf), z); UI1_ChangeText(&ui->window, (UI1_Element *)&ui->txtZ, sizeof(ui->txtBufZ), buf); (void)UI1_ChangeBarGraphData(&ui->window, &ui->accelBarGraph, 0, (uint8_t)x); (void)UI1_ChangeBarGraphData(&ui->window, &ui->accelBarGraph, 1, (uint8_t)y); (void)UI1_ChangeBarGraphData(&ui->window, &ui->accelBarGraph, 2, (uint8_t)z); /* graph */ data[0].data = (uint8_t)x; data[1].data = (uint8_t)y; data[2].data = (uint8_t)z; (void)UIG1_AddDataLine((UI1_Element *)&ui->graph, &prevData[0], &data[0], 3); prevData[0].data = data[0].data; prevData[1].data = data[1].data; prevData[2].data = data[2].data; if (EVNT1_GetEvent(EVNT1_APP_MODE_CHANGE)) { /* request to close application */ EVNT1_ClearEvent(EVNT1_APP_MODE_CHANGE); /* reset event flag */ FRTOS1_vTaskDelete(NULL); /* kill ourself */ } FRTOS1_vTaskDelay(25/portTICK_RATE_MS); } /* for */ }