bool BitTest::test_FlipBit() { int x = 1, y = 0; FlipBit(x,0); FlipBit(y,0); return ( (x == 0) && (y == 1) ); }
Boolean TTFprocess(Font *fnt, long Code, byte **bitmap, int *width, int *height, int *hoff, int *voff, Boolean hinting, Boolean quiet) { int Num; TT_Error error; if (!bitmap || !width || !height || !hoff || !voff) oops("Invalid parameter in call to TTFprocess()"); if (Code >= 0x1000000) Num = Code & 0xFFFFFF; else { Num = TT_Char_Index(char_map, Code); if (has_gsub) { in_string[0] = Num; error = TT_GSUB_Apply_String(gsub, &in, &out); if (error && error != TTO_Err_Not_Covered) warning("Cannot get the vertical glyph form for glyph index %d.", Num); else Num = out.string[0]; } } if ((error = LoadTrueTypeChar(fnt, Num, hinting, quiet)) == TT_Err_Ok) { memset(Bit.bitmap, 0, Bit.size); TT_Get_Glyph_Bitmap(glyph, &Bit, x_offset * 64, y_offset * 64); FlipBit(); *bitmap = Bit2.bitmap; *width = Bit2.width; *height = Bit2.rows; *hoff = x_offset; *voff = y_offset; /* *voff = Bit2.rows - y_offset; */ /* printf("%D %d\n", *hoff, *voff); */ /* Output(Bit2); */ return True; } else return False; }
// This is the actual task that is run static portTASK_FUNCTION( I2CTask, pvParameters ) { portTickType xUpdateRate, xLastUpdateTime; const uint8_t ReturnADCValue = 0xAA; //const uint8_t InsteonReserved; //reserved for Insteon if we are only requesting insteon data //uint8_t InsteonSendValue[12]; //reserved for Insteon send uint8_t MidiSendCount = 1; uint8_t MidiSendValue[9] = {0xAF, 0x80, 0x64, 0x64, 0x00, 0x00, 0x00, 0x00, 0x00}; uint8_t InstSendValue[9] = {0x11, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}; int msgcount = 0; uint8_t temp1, rxLen, status; uint8_t ADCValueReceived[12]; uint8_t MidiReceived[2]; // Get the parameters i2cParamStruct *param = (i2cParamStruct *) pvParameters; // Get the I2C device pointer vtI2CStruct *devPtr = param->i2cDev; // Get the LCD information pointer vtLCDMsgQueue *lcdData = param->lcdQ; vtLCDMsg lcdBuffer; MasterMsgQueue * masterData = param->masterQ; MasterMsgQueueMsg masterBuffer; I2CMsgQueue * i2cQ = param->i2cQ; I2CMsgQueueMsg i2cBuffer; vTaskDelay(10/portTICK_RATE_MS); xUpdateRate = i2cREAD_RATE_BASE / portTICK_RATE_MS; /* We need to initialise xLastUpdateTime prior to the first call to vTaskDelayUntil(). */ xLastUpdateTime = xTaskGetTickCount(); for(;;) { //delay for some amount of time before looping again //vTaskDelayUntil( &xLastUpdateTime, xUpdateRate ); //Send a request to the PIC for ADC values if (vtI2CEnQ(devPtr,0x01,0x4F,1,&ReturnADCValue,12) != pdTRUE) { VT_HANDLE_FATAL_ERROR(0); } //wait for message from I2C //bit0 is first portion of ADC value //bit1 is last portion of ADC value //bit2 is timer value //bit3 thru bit7 are garbage (all 0's) //bit8 is the size of the Midi buffer on the PIC //bit9 is the count //bit10 is the ADC channel number //bit11 is the OPCode we sent (0xAA) if (vtI2CDeQ(devPtr,12,&ADCValueReceived[0],&rxLen,&status) != pdTRUE) { //VT_HANDLE_FATAL_ERROR(0); } //check the message returned for errors: //0xAA signifying it's the correct op-code, verify the ADC is in the right order, //ensure the proper range of channel numbers is used. if ((ADCValueReceived[11] != 0xAA || ADCValueReceived[0] > 3 || ADCValueReceived[10] < 0 || ADCValueReceived[10] > 5) && ADCValueReceived[11] != 0xBB) { FlipBit(6); } else { //check the inbound i2c message queue from messages either from the Main Thread or the LCD //thread. Forward them to the PIC depending on op-code if (ADCValueReceived[8] < 4 && uxQueueMessagesWaiting(i2cQ->inQ) > 0)//check for room on the PIC and if a message exists { if (xQueueReceive(i2cQ->inQ,(void *) &i2cBuffer,portMAX_DELAY) != pdTRUE) //receive message from message queue { VT_HANDLE_FATAL_ERROR(0); } /*if (i2cBuffer.buf[0] == 0x13) { InstSendValue[0] = i2cBuffer.buf[0]; InstSendValue[1] = 0x02; InstSendValue[2] = 0x62; InstSendValue[3] = 0x12; InstSendValue[4] = 0x07; InstSendValue[5] = 0x4F; InstSendValue[6] = 0x00; InstSendValue[7] = 0x11; InstSendValue[8] = i2cBuffer.buf[1]; if (i2cBuffer.buf[1] == 8) FlipBit(3); if (vtI2CEnQ(devPtr,0x00,0x4F,9,InstSendValue,0) != pdTRUE) { VT_HANDLE_FATAL_ERROR(0); } //wait for message from I2C if (vtI2CDeQ(devPtr,0,&MidiReceived[0],&rxLen,&status) != pdTRUE) { //VT_HANDLE_FATAL_ERROR(0); } } */ else if (i2cBuffer.buf[0] == 0x4) //MIDI message to be forwarded { MidiSendValue[1] = i2cBuffer.buf[1]; //Here are the three MIDI control bytes sent MidiSendValue[2] = i2cBuffer.buf[2]; //They are formulated in the mainthread and sent here MidiSendValue[3] = i2cBuffer.buf[3]; //Midi message to I2C to the PIC, there is also a count to maintain messages if (MidiSendCount > 100) MidiSendCount = 1; MidiSendValue[4] = MidiSendCount; if (vtI2CEnQ(devPtr,0x00,0x4F,9,MidiSendValue,0) != pdTRUE) { VT_HANDLE_FATAL_ERROR(0); } //wait for message from I2C if (vtI2CDeQ(devPtr,0,&MidiReceived[0],&rxLen,&status) != pdTRUE) { //VT_HANDLE_FATAL_ERROR(0); } //Whenever a "note on" message is being sent to the MIDI device, we want to update the LED display as well //this checks the command portion of the MIDI message then changes the LED accordingly. The 0x90 signifies //that the message came from instrument 1 since it operates on MIDI channel 0; 0x91 means Instrument 2 since //it operates on MIDI channel 1 if (i2cBuffer.buf[1] == 0x90) { if (i2cBuffer.buf[2] == 60) InstSendValue[2] = 0x80; else if (i2cBuffer.buf[2] == 62) InstSendValue[2] = 0x40; else if (i2cBuffer.buf[2] == 64) InstSendValue[2] = 0x20; else if (i2cBuffer.buf[2] == 65) InstSendValue[2] = 0x10; else if (i2cBuffer.buf[2] == 67) InstSendValue[2] = 0x08; else if (i2cBuffer.buf[2] == 69) InstSendValue[2] = 0x04; else if (i2cBuffer.buf[2] == 71) InstSendValue[2] = 0x02; else if (i2cBuffer.buf[2] == 72) InstSendValue[2] = 0x01; InstSendValue[0] = 0x00; InstSendValue[1] = 0x16; //InstSendValue[2] = 0x80; InstSendValue[3] = 0x00; InstSendValue[4] = 0x00; InstSendValue[5] = 0x00; if (vtI2CEnQ(devPtr,0x00,0x38,6,InstSendValue,0) != pdTRUE) { VT_HANDLE_FATAL_ERROR(0); } if (vtI2CDeQ(devPtr,0,&MidiReceived[0],&rxLen,&status) != pdTRUE) { //VT_HANDLE_FATAL_ERROR(0); } MidiSendCount++; } else if (i2cBuffer.buf[1] == 0x91) { if (i2cBuffer.buf[2] == 60) InstSendValue[2] = 0x80; else if (i2cBuffer.buf[2] == 62) InstSendValue[2] = 0x40; else if (i2cBuffer.buf[2] == 64) InstSendValue[2] = 0x20; else if (i2cBuffer.buf[2] == 65) InstSendValue[2] = 0x10; else if (i2cBuffer.buf[2] == 67) InstSendValue[2] = 0x08; else if (i2cBuffer.buf[2] == 69) InstSendValue[2] = 0x04; else if (i2cBuffer.buf[2] == 71) InstSendValue[2] = 0x02; else if (i2cBuffer.buf[2] == 72) InstSendValue[2] = 0x01; InstSendValue[0] = 0x00; InstSendValue[1] = 0x16; //InstSendValue[2] = 0x80; InstSendValue[3] = 0x00; InstSendValue[4] = 0x00; InstSendValue[5] = 0x00; if (vtI2CEnQ(devPtr,0x00,0x3B,6,InstSendValue,0) != pdTRUE) { VT_HANDLE_FATAL_ERROR(0); } if (vtI2CDeQ(devPtr,0,&MidiReceived[0],&rxLen,&status) != pdTRUE) { //VT_HANDLE_FATAL_ERROR(0); } MidiSendCount++; } //Here are similar checks on the MIDI messages for a change in pitch. The same checkes are made //for different channels if (i2cBuffer.buf[1] == 0xE0) { if (i2cBuffer.buf[3] == 0x00) InstSendValue[1] = 0x04; else if (i2cBuffer.buf[3] == 0x40) InstSendValue[1] = 0x02; else if (i2cBuffer.buf[3] == 0x7F) InstSendValue[1] = 0x01; InstSendValue[0] = 0x02; InstSendValue[3] = 0x00; InstSendValue[2] = 0x00; InstSendValue[4] = 0x00; InstSendValue[5] = 0x00; if (vtI2CEnQ(devPtr,0x00,0x38,6,InstSendValue,0) != pdTRUE) { VT_HANDLE_FATAL_ERROR(0); } if (vtI2CDeQ(devPtr,0,&MidiReceived[0],&rxLen,&status) != pdTRUE) { //VT_HANDLE_FATAL_ERROR(0); } MidiSendCount++; } else if (i2cBuffer.buf[1] == 0xE1) { if (i2cBuffer.buf[3] == 0x00) InstSendValue[1] = 0x04; else if (i2cBuffer.buf[3] == 0x40) InstSendValue[1] = 0x02; else if (i2cBuffer.buf[3] == 0x7F) InstSendValue[1] = 0x01; InstSendValue[0] = 0x02; InstSendValue[3] = 0x00; InstSendValue[2] = 0x00; InstSendValue[4] = 0x00; InstSendValue[5] = 0x00; if (vtI2CEnQ(devPtr,0x00,0x3B,6,InstSendValue,0) != pdTRUE) { VT_HANDLE_FATAL_ERROR(0); } if (vtI2CDeQ(devPtr,0,&MidiReceived[0],&rxLen,&status) != pdTRUE) { //VT_HANDLE_FATAL_ERROR(0); } MidiSendCount++; } //wait for message from I2C } } //If the message is not NULL then it is an ADC message, this message gets forwarded to MainThread.c where //the data is used for calculations. FlipBit(7); if (lcdData != NULL) { //message sent to the master message queue masterBuffer.length = 13; masterBuffer.buf[0] = 0x08; //means the message is from I2C - change to 0x09 for Nick's program masterBuffer.buf[1] = ADCValueReceived[0]; masterBuffer.buf[2] = ADCValueReceived[1]; masterBuffer.buf[3] = ADCValueReceived[2]; masterBuffer.buf[4] = ADCValueReceived[3]; masterBuffer.buf[5] = ADCValueReceived[4]; masterBuffer.buf[6] = ADCValueReceived[5]; masterBuffer.buf[7] = ADCValueReceived[6]; masterBuffer.buf[8] = ADCValueReceived[7]; masterBuffer.buf[9] = ADCValueReceived[8]; masterBuffer.buf[10] = ADCValueReceived[9]; masterBuffer.buf[11] = ADCValueReceived[10]; masterBuffer.buf[12] = ADCValueReceived[11]; if (xQueueSend(masterData->inQ,(void *) (&masterBuffer),portMAX_DELAY) != pdTRUE) { VT_HANDLE_FATAL_ERROR(0); } } } } }