void ColourEngine::Update() { _LAT(PIO_LED2) = HIGH; // Adjust current colour by brightness RGBWColour colour = current_rgbw * current_brightness; // Raw RGBW values are passed directly to the PWM outputs. // Note that scaling by brightness will probably not look right, so refrain from using brightness control in this case! // sRGBW values operate in a perceptually-uniform colour space // ie, 0.5 = half brightness (not half power!) // These values can be scaled while still appearing linear. if (colour.space == RGBWColour::sRGB) { colour = colour.to_linear(); } PWMUpdate(colour.red, colour.green, colour.blue, colour.white); _LAT(PIO_LED2) = LOW; }
////////////////////////////////////////////////////////////////////////////////////////// // // TransducerUpdate - Update the transducer driver // // Inputs: None // // Outputs: None. // // NOTE: Called by timer update, not for public consumption // void TransducerUpdate(void) { // // Update all subordinate components // PWMUpdate(); ACS712Update(); InputsUpdate(); // // If we're running, use the PWM version of frequency since it's the most accurate. // Otherwise the PWM is offline so use the less-accurate count to keep us in the // ballpark. // // Note: SG3525 counted output is twice the actual frequency // TransducerCurr.Freq = GetPWMFreq(); TransducerCurr.PWM = GetPWM()*2; TransducerCurr.Current = ACS712GetCurrent(); // // PWM is % x 10, Current is in Amps x 10, and drive is 12 volts // // Multiply everything together and divide by 10 to get power in Watts x 10 // uint32_t PwrTemp; PwrTemp = TransducerCurr.Current*TRANSDUCER_DRIVE_VOLTS; PwrTemp *= TransducerCurr.PWM; PwrTemp /= 1000; TransducerCurr.Power = (uint16_t) PwrTemp; // // If we're running on timer, decrement and possibly stop // if( TransducerCurr.On && TransducerSet.RunMode == RUN_TIMED ) { if( --TransducerCurr.RunTimer == 0 ) TransducerOn(false); } switch(TransducerSet.CtlMode) { ////////////////////////////////////////////////////////////////////////////////// // // CTL_CONST_FREQ - Set constant frequency and power // case CTL_CONST_FREQ: // AdjustPower(); break; ////////////////////////////////////////////////////////////////////////////////// // // CTL_MAX_EFF - Keep maximum efficiency // case CTL_MAX_EFF: break; default: break; } }