コード例 #1
0
ファイル: fcdevice.cpp プロジェクト: RGB-123/fadecandy
void FCDevice::writeDevicePixels(Document &msg)
{
    /*
     * Write pixels without mapping, from a JSON integer
     * array in msg["pixels"]. The pixel array is removed from
     * the reply to save network bandwidth.
     *
     * Pixel values are clamped to [0, 255], for convenience.
     */

    const Value &pixels = msg["pixels"];
    if (!pixels.IsArray()) {
        msg.AddMember("error", "Pixel array is missing", msg.GetAllocator());
    } else {

        // Truncate to the framebuffer size, and only deal in whole pixels.
        int numPixels = pixels.Size() / 3;
        if (numPixels > NUM_PIXELS)
            numPixels = NUM_PIXELS;

        for (int i = 0; i < numPixels; i++) {
            uint8_t *out = fbPixel(i);

            const Value &r = pixels[i*3 + 0];
            const Value &g = pixels[i*3 + 1];
            const Value &b = pixels[i*3 + 2];

            out[0] = std::max(0, std::min(255, r.IsInt() ? r.GetInt() : 0));
            out[1] = std::max(0, std::min(255, g.IsInt() ? g.GetInt() : 0));
            out[2] = std::max(0, std::min(255, b.IsInt() ? b.GetInt() : 0));
        }

        writeFramebuffer();
    }
}
コード例 #2
0
ファイル: bw_wsdevice.cpp プロジェクト: rewolff/fadecandy
void BitWizardWSDevice::writeMessage(const OPC::Message &msg)
{
  /*
   * Dispatch an incoming OPC command
   */
  //  std::cout  << "got a write message! ";

  switch (msg.command) {

  case OPC::SetPixelColors:
    //std::cout  << "setpixels...\n";

    opcSetPixelColors(msg);
    writeFramebuffer();
    return;

  case OPC::SystemExclusive:
    std::cout  << "sysex...\n";
    // No relevant SysEx for this device
    return;
  default: 
    std::cout  << "unhandled case...\n";
  }

  if (mVerbose) {
    std::clog << "Unsupported OPC command: " << unsigned(msg.command) << "\n";
  }
}
コード例 #3
0
ファイル: fcdevice.cpp プロジェクト: RGB-123/fadecandy
void FCDevice::flush()
{
    // Erase any finished transfers

    std::set<Transfer*>::iterator current = mPending.begin();
    while (current != mPending.end()) {
        std::set<Transfer*>::iterator next = current;
        next++;

        Transfer *fct = *current;
        if (fct->finished) {
            switch (fct->type) {

                case FRAME:
                    mNumFramesPending--;
                    break;

                default:
                    break;
            }

            mPending.erase(current);
            delete fct;
        }

        current = next;
    }

    // Submit new frames, if we had a queued frame waiting

    if (mFrameWaitingForSubmit && mNumFramesPending < MAX_FRAMES_PENDING) {
        writeFramebuffer();
    }
}
コード例 #4
0
ファイル: fcdevice.cpp プロジェクト: Dewb/fadecandy
void FCDevice::writeMessage(const OPCSink::Message &msg)
{
    /*
     * Dispatch an incoming OPC command
     */

    switch (msg.command) {

        case OPCSink::SetPixelColors:
            opcSetPixelColors(msg);
            writeFramebuffer();
            return;

        case OPCSink::SystemExclusive:
            opcSysEx(msg);
            return;
    }

    if (mVerbose) {
        std::clog << "Unsupported OPC command: " << unsigned(msg.command) << "\n";
    }
}