#include "DSTemperature.h"

DSTemperature::DSTemperature(byte pin) {
  _wire = new OneWire(pin);
  _addresses = (DSAddress*)malloc(sizeof(DSAddress));
}

void DSTemperature::begin(void) {

  DSAddress addr;

  while (_wire->search(addr.value)) {
    if (OneWire::crc8(addr.value, 7) == addr.value[7]) {
      resizeAddresses();
      _addresses[_nSensors++] = addr;
    }
  }

  _wire->reset_search();
  delay(250);
  return;

}

void DSTemperature::resizeAddresses() {

  if (_nSensors == 0)
    return;

  DSAddress* new_addresses = (DSAddress*)malloc(sizeof(DSAddress) * _nSensors);
  for (byte i = 0 ; i < _nSensors ; i++)
    new_addresses[i] = _addresses[i];
  free(_addresses);
  _addresses = new_addresses;

}

float DSTemperature::getCelsius(byte ds) {
  return CELSIUS(getRawTemperature(ds));
}

float DSTemperature::getFahrenheit(byte ds) {
  return FAHRENHEIT(getRawTemperature(ds));
}

#include "DSTemperature.h"

DSTemperature::DSTemperature(byte pin) {
  _wire = new OneWire(pin);
  _addresses = (DSAddress*)malloc(sizeof(DSAddress));
}

void DSTemperature::begin(void) {

  DSAddress addr;

  while (_wire->search(addr.value)) {
    if (OneWire::crc8(addr.value, 7) == addr.value[7]) {
      if (_nSensors != 0)
        resizeAddresses();
      _addresses[_nSensors++] = addr;
    }
  }

  _wire->reset_search();
  delay(250);
  return;

}

void DSTemperature::resizeAddresses() {

  DSAddress* new_addresses = (DSAddress*)malloc(sizeof(DSAddress) * _nSensors);
  for (byte i = 0 ; i < _nSensors ; i++)
    new_addresses[i] = _addresses[i];
  free(_addresses);
  _addresses = new_addresses;

}

float DSTemperature::getCelsius(byte ds) {
  return CELSIUS(getRawTemperature(ds));
}

float DSTemperature::getFahrenheit(byte ds) {
  return FAHRENHEIT(getRawTemperature(ds));
}

Call resizeAddresses only if you manage more than one sensor


/*
 * Copyright 2011 Google Inc.
 *
 * Use of this source code is governed by a BSD-style license that can be
 * found in the LICENSE file.
 */

#include "GrGLConfig.h"
#include "GrGLInterface.h"

void GrGLClearErr(const GrGLInterface* gl) {
    while (GR_GL_NO_ERROR != gl->fGetError()) {}
}

void GrGLCheckErr(const GrGLInterface* gl,
                  const char* location,
                  const char* call) {
    uint32_t err = GR_GL_GET_ERROR(gl);
    if (GR_GL_NO_ERROR != err) {
        GrPrintf("---- glGetError %x", GR_GL_GET_ERROR(gl));
        if (NULL != location) {
            GrPrintf(" at\n\t%s", location);
        }
        if (NULL != call) {
            GrPrintf("\n\t\t%s", call);
        }
        GrPrintf("\n");
    }
}

void GrGLResetRowLength(const GrGLInterface* gl) {
    if (gl->supportsDesktop()) {
        GR_GL_CALL(gl, PixelStorei(GR_GL_UNPACK_ROW_LENGTH, 0));
    }
}

///////////////////////////////////////////////////////////////////////////////

#if GR_GL_LOG_CALLS
    bool gLogCallsGL = !!(GR_GL_LOG_CALLS_START);
#endif

#if GR_GL_CHECK_ERROR
    bool gCheckErrorGL = !!(GR_GL_CHECK_ERROR_START);
#endif

/*
 * Copyright 2011 Google Inc.
 *
 * Use of this source code is governed by a BSD-style license that can be
 * found in the LICENSE file.
 */

#include "GrGLConfig.h"
#include "GrGLInterface.h"

void GrGLClearErr(const GrGLInterface* gl) {
    while (GR_GL_NO_ERROR != gl->fGetError()) {}
}

void GrGLCheckErr(const GrGLInterface* gl,
                  const char* location,
                  const char* call) {
    uint32_t err = GR_GL_GET_ERROR(gl);
    if (GR_GL_NO_ERROR != err) {
        GrPrintf("---- glGetError %x", err);
        if (NULL != location) {
            GrPrintf(" at\n\t%s", location);
        }
        if (NULL != call) {
            GrPrintf("\n\t\t%s", call);
        }
        GrPrintf("\n");
    }
}

void GrGLResetRowLength(const GrGLInterface* gl) {
    if (gl->supportsDesktop()) {
        GR_GL_CALL(gl, PixelStorei(GR_GL_UNPACK_ROW_LENGTH, 0));
    }
}

///////////////////////////////////////////////////////////////////////////////

#if GR_GL_LOG_CALLS
    bool gLogCallsGL = !!(GR_GL_LOG_CALLS_START);
#endif

#if GR_GL_CHECK_ERROR
    bool gCheckErrorGL = !!(GR_GL_CHECK_ERROR_START);
#endif

Fix gl error debug print.

Fix gl error debug print.


#include <iostream>
#include <vector>

#include <adios2.h>
#ifdef ADIOS2_HAVE_MPI
#include <mpi.h>
#endif

int main(int argc, char *argv[])
{
    int rank = 0;
    int size = 1;
#ifdef ADIOS2_HAVE_MPI
    MPI_Init(&argc, &argv);
    MPI_Comm_rank(MPI_COMM_WORLD, &rank);
    MPI_Comm_size(MPI_COMM_WORLD, &size);
#endif
    adios2::ADIOS ad;
    try
    {
#ifdef ADIOS2_HAVE_MPI
        ad = adios2::ADIOS("does_not_exist.xml", MPI_COMM_WORLD,
                           adios2::DebugON);
#else
        ad = adios2::ADIOS("does_not_exist.xml", adios2::DebugON);
#endif
    }
    catch (std::exception &e)
    {
        if (rank == 0)
        {
            std::cout << e.what() << "\n";
        }
#ifdef ADIOS2_HAVE_MPI
        ad = adios2::ADIOS(MPI_COMM_WORLD, adios2::DebugON);
#else
        ad = adios2::ADIOS(adios2::DebugON);
#endif
    }

#ifdef ADIOS2_HAVE_MPI
    return MPI_Finalize();
#endif
}

#include <iostream>
#include <vector>

#include <adios2.h>
#ifdef ADIOS2_HAVE_MPI
#include <mpi.h>
#endif

int main(int argc, char *argv[])
{
    int rank = 0;
#ifdef ADIOS2_HAVE_MPI
    int size = 1;
    MPI_Init(&argc, &argv);
    MPI_Comm_rank(MPI_COMM_WORLD, &rank);
    MPI_Comm_size(MPI_COMM_WORLD, &size);
#endif
    adios2::ADIOS ad;
    try
    {
#ifdef ADIOS2_HAVE_MPI
        ad = adios2::ADIOS("does_not_exist.xml", MPI_COMM_WORLD,
                           adios2::DebugON);
#else
        ad = adios2::ADIOS("does_not_exist.xml", adios2::DebugON);
#endif
    }
    catch (std::exception &e)
    {
        if (rank == 0)
        {
            std::cout << e.what() << "\n";
        }
#ifdef ADIOS2_HAVE_MPI
        ad = adios2::ADIOS(MPI_COMM_WORLD, adios2::DebugON);
#else
        ad = adios2::ADIOS(adios2::DebugON);
#endif
    }

#ifdef ADIOS2_HAVE_MPI
    return MPI_Finalize();
#endif
}

Remove unused variable warning when MPI is disabled.


// Copyright (c) 2012 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include "chrome/browser/sync/glue/chrome_report_unrecoverable_error.h"

#include "base/rand_util.h"
#include "build/build_config.h"

#if defined(OS_WIN)
#include <windows.h>
#endif

#include "chrome/common/chrome_constants.h"

namespace browser_sync {

void ChromeReportUnrecoverableError() {
  // TODO(lipalani): Add this for other platforms as well.
#if defined(OS_WIN)
  const double kErrorUploadRatio = 0.15;

  // We only want to upload |kErrorUploadRatio| ratio of errors.
  if (kErrorUploadRatio <= 0.0)
    return; // We are not allowed to upload errors.
  double random_number = base::RandDouble();
  if (random_number > kErrorUploadRatio)
    return;

  // Get the breakpad pointer from chrome.exe
  typedef void (__cdecl *DumpProcessFunction)();
  DumpProcessFunction DumpProcess = reinterpret_cast<DumpProcessFunction>(
      ::GetProcAddress(::GetModuleHandle(
                       chrome::kBrowserProcessExecutableName),
                       "DumpProcessWithoutCrash"));
  if (DumpProcess)
    DumpProcess();
#endif  // OS_WIN

}

}  // namespace browser_sync

// Copyright (c) 2012 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include "chrome/browser/sync/glue/chrome_report_unrecoverable_error.h"

#include "base/rand_util.h"
#include "chrome/common/chrome_constants.h"
#include "chrome/common/chrome_version_info.h"
#include "chrome/common/dump_without_crashing.h"

namespace browser_sync {

void ChromeReportUnrecoverableError() {
  // Only upload on canary/dev builds to avoid overwhelming crash server.
  chrome::VersionInfo::Channel channel = chrome::VersionInfo::GetChannel();
  if (channel != chrome::VersionInfo::CHANNEL_CANARY &&
      channel != chrome::VersionInfo::CHANNEL_DEV) {
    return;
  }

  // We only want to upload |kErrorUploadRatio| ratio of errors.
  const double kErrorUploadRatio = 0.15;
  if (kErrorUploadRatio <= 0.0)
    return; // We are not allowed to upload errors.
  double random_number = base::RandDouble();
  if (random_number > kErrorUploadRatio)
    return;

  logging::DumpWithoutCrashing();
}

}  // namespace browser_sync

[Sync] Support unrecoverable error uploading on non-win platforms

We now use chrome/common/dump_without_crashing.h, and only upload on canary/
dev builds.

BUG=127429

Review URL: https://codereview.chromium.org/80963003

git-svn-id: de016e52bd170d2d4f2344f9bf92d50478b649e0@236623 0039d316-1c4b-4281-b951-d872f2087c98


// Copyright (c) 2009 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include "base/native_library.h"

#include <dlfcn.h>

#include "base/file_path.h"
#include "base/logging.h"

namespace base {

// static
NativeLibrary LoadNativeLibrary(const FilePath& library_path) {
  void* dl = dlopen(library_path.value().c_str(), RTLD_LAZY);
  if (!dl)
    NOTREACHED() << "dlopen failed: " << dlerror();

  return dl;
}

// static
void UnloadNativeLibrary(NativeLibrary library) {
  int ret = dlclose(library);
  if (ret < 0)
    NOTREACHED() << "dlclose failed: " << dlerror();
}

// static
void* GetFunctionPointerFromNativeLibrary(NativeLibrary library,
                                          NativeLibraryFunctionNameType name) {
  return dlsym(library, name);
}

}  // namespace base

// Copyright (c) 2009 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include "base/native_library.h"

#include <dlfcn.h>

#include "base/file_path.h"
#include "base/logging.h"

namespace base {

// static
NativeLibrary LoadNativeLibrary(const FilePath& library_path) {
  void* dl = dlopen(library_path.value().c_str(), RTLD_LAZY|RTLD_DEEPBIND);
  if (!dl)
    NOTREACHED() << "dlopen failed: " << dlerror();

  return dl;
}

// static
void UnloadNativeLibrary(NativeLibrary library) {
  int ret = dlclose(library);
  if (ret < 0)
    NOTREACHED() << "dlclose failed: " << dlerror();
}

// static
void* GetFunctionPointerFromNativeLibrary(NativeLibrary library,
                                          NativeLibraryFunctionNameType name) {
  return dlsym(library, name);
}

}  // namespace base

Use RTLD_DEEPBIND to make sure plugins don't use Chrome's symbols instead of their own

Review URL: http://codereview.chromium.org/112030
Patch from Antoine Labour <piman@google.com>.

git-svn-id: de016e52bd170d2d4f2344f9bf92d50478b649e0@16278 0039d316-1c4b-4281-b951-d872f2087c98


#include "mainwindow.h"
#include <QApplication>

int main(int argc, char *argv[])
{
    QApplication a(argc, argv);
    MainWindow w;
    w.show();

    return a.exec();
}

#include "mainwindow.h"
#include <QApplication>

int main(int argc, char *argv[])
{
    QApplication a(argc, argv);
    std::locale::global( std::locale( "C" ) );
    MainWindow w;
    w.show();

    return a.exec();
}

Set local to C. Maybe not the best longterm solution.


#include "ui.hpp"
#include "window.hpp"

namespace rack {

Tooltip::Tooltip() {
}

void Tooltip::draw(NVGcontext *vg) {
	// Wrap size to contents
	box.size.x = bndLabelWidth(vg, -1, text.c_str());
	box.size.y = bndLabelHeight(vg, -1, text.c_str(), INFINITY);

	bndTooltipBackground(vg, 0.0, 0.0, box.size.x, box.size.y);
	bndMenuLabel(vg, 0.0, 0.0, box.size.x, box.size.y, -1, text.c_str());
	Widget::draw(vg);
}

} // namespace rack

#include "ui.hpp"
#include "window.hpp"

namespace rack {

Tooltip::Tooltip() {
}

void Tooltip::draw(NVGcontext *vg) {
	// Wrap size to contents
	box.size.x = bndLabelWidth(vg, -1, text.c_str()) + 10.0;
	box.size.y = bndLabelHeight(vg, -1, text.c_str(), INFINITY);

	bndTooltipBackground(vg, 0.0, 0.0, box.size.x, box.size.y);
	bndMenuLabel(vg, 0.0, 0.0, box.size.x, box.size.y, -1, text.c_str());
	Widget::draw(vg);
}

} // namespace rack

Add 10 pixels to tooltip because of Retina text width bug


#include "zcash/JoinSplit.hpp"

#include <iostream>

int main(int argc, char **argv)
{
    if(argc != 3) {
        std::cerr << "Usage: " << argv[0] << " provingKeyFileName verificationKeyFileName" << std::endl;
        return 1;
    }

    std::string pkFile = argv[1];
    std::string vkFile = argv[2];

    auto p = ZCJoinSplit::Generate();

    p->saveProvingKey(pkFile);
    p->saveVerifyingKey(vkFile);

    return 0;
}

#include "zcash/JoinSplit.hpp"

#include <iostream>
#include "sodium.h"

int main(int argc, char **argv)
{
    if (sodium_init() == -1) {
        return 1;
    }

    if(argc != 3) {
        std::cerr << "Usage: " << argv[0] << " provingKeyFileName verificationKeyFileName" << std::endl;
        return 1;
    }

    std::string pkFile = argv[1];
    std::string vkFile = argv[2];

    auto p = ZCJoinSplit::Generate();

    p->saveProvingKey(pkFile);
    p->saveVerifyingKey(vkFile);

    return 0;
}

Initialize libsodium in this routine, which is now necessary because libsnark uses its PRNG.


#include "visionnage.h"
#include "mainwindow.h"

#include <QDebug>
#include <QException>

Visionnage::Visionnage(MainWindow *parent, Projet *projet, int nPreviousImage) :
    QThread(parent),
    _parent(parent),
    _projet(projet),
    _nPreviousImage(nPreviousImage),
    _initFrame(parent->getNbFrame()),
    _stop(false)
{
}

void Visionnage::run()
{
    int frame = _initFrame;

    while(!_stop)
    {
        _parent->loadFrame(frame);

        if(_nPreviousImage == -1)
        {
            if(frame == _projet->getNbFrameVideo())
            {
                frame = 0;
            }
            else
            {
                frame += 1;
            }
        }
        else
        {
            if(frame == _initFrame)
            {
                frame -= _nPreviousImage;

                if(frame < 0)
                    frame = 0;
            }
            else
            {
                frame += 1;
            }
        }

        msleep(20);
    }
}

void Visionnage::stop()
{
    _stop = true;
    msleep(20);
    _parent->loadFrame(_initFrame);
}

#include "visionnage.h"
#include "mainwindow.h"

#include <QDebug>
#include <QException>

Visionnage::Visionnage(MainWindow *parent, Projet *projet, int nPreviousImage) :
    QThread(parent),
    _parent(parent),
    _projet(projet),
    _nPreviousImage(nPreviousImage),
    _initFrame(parent->getNbFrame()),
    _stop(false)
{
}

void Visionnage::run()
{
    int frame = _initFrame;

    while(!_stop)
    {
        _parent->loadFrame(frame);

        if(_nPreviousImage == -1)
        {
            if(frame == _projet->getNbFrameVideo())
            {
                frame = 0;
            }
            else
            {
                frame += 1;
            }
        }
        else
        {
            if(frame == _initFrame)
            {
                frame -= _nPreviousImage;

                if(frame < 0)
                    frame = 0;
            }
            else
            {
                frame += 1;
            }
        }

        msleep(100);
    }
}

void Visionnage::stop()
{
    _stop = true;
    msleep(20);
    _parent->loadFrame(_initFrame);
}

Change time pause while visionning

Change time pause while visionning


// Copyright 2015 Matt Heard
// http://mattheard.net
// matt@mattheard.net
// @mattheard

#include <opencv2/opencv.hpp>
#include <iostream>
#include <string>

using cv::Mat;

Mat buildLookUpTable(const int divideWith) {
    return Mat();
}

int main(int argc, char **argv) {
    using std::string;
    const int expectedNumArgs = 3;
    if (argc != expectedNumArgs) {
        const string cmdName = "ConvertToGrey";
        const string argsDesc = " <Image_Path> <Reduce_By>";
        std::cout << "Usage: " << cmdName << argsDesc << std::endl;
        return -1;
    }
    const string inputFilename = argv[1];
    const Mat srcImg = cv::imread(inputFilename);
    if (!srcImg.data) {
        const string err = "No image data";
        std::cerr << err << std::cout;
        return -1;
    }
    const int divideWith = atoi(argv[2]);
    if (divideWith < 1) {
        std::cout << "Invalid number entered for dividing." << std::endl;
        return -1;
    }
    const Mat lookUpTable = buildLookUpTable(divideWith);
    return 0;
}

// Copyright 2015 Matt Heard
// http://mattheard.net
// matt@mattheard.net
// @mattheard

#include <opencv2/opencv.hpp>
#include <iostream>
#include <string>

using cv::Mat;

Mat buildLookUpTable(const int divideWith) {
    const int rows = 1;
    const int cols = 256;
    const int type = CV_8U;
    const Mat table(rows, cols, type);
    for (int i = 0; i < 256; ++i) {
        const int reduced = divideWith * (i / divideWith);
        table.data[i] = (uchar) reduced;
    }
    return table;
}

int main(int argc, char **argv) {
    using std::string;
    const int expectedNumArgs = 3;
    if (argc != expectedNumArgs) {
        const string cmdName = "ConvertToGrey";
        const string argsDesc = " <Image_Path> <Reduce_By>";
        std::cout << "Usage: " << cmdName << argsDesc << std::endl;
        return -1;
    }
    const string inputFilename = argv[1];
    const Mat srcImg = cv::imread(inputFilename);
    if (!srcImg.data) {
        const string err = "No image data";
        std::cerr << err << std::cout;
        return -1;
    }
    const int divideWith = atoi(argv[2]);
    if (divideWith < 1) {
        std::cout << "Invalid number entered for dividing." << std::endl;
        return -1;
    }
    const Mat lookUpTable = buildLookUpTable(divideWith);
    return 0;
}

Implement fn to build lookup table

Implement fn to build lookup table


// Copyright (c) 2011 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include "chrome/browser/ui/views/frame/browser_non_client_frame_view.h"

#include "chrome/browser/ui/touch/frame/touch_browser_frame_view.h"
#include "chrome/browser/ui/views/frame/browser_view.h"
#include "chrome/browser/ui/views/frame/popup_non_client_frame_view.h"

namespace browser {

BrowserNonClientFrameView* CreateBrowserNonClientFrameView(
    BrowserFrame* frame, BrowserView* browser_view) {
  if (browser_view->IsBrowserTypePopup() ||
      browser_view->IsBrowserTypePanel()) {
    // TODO(anicolao): implement popups for touch
    NOTIMPLEMENTED();
    return new PopupNonClientFrameView(frame);
  } else {
    return new TouchBrowserFrameView(frame, browser_view);
  }
}

}  // browser

// Copyright (c) 2011 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include "chrome/browser/ui/views/frame/browser_non_client_frame_view.h"

#include "base/command_line.h"
#include "chrome/browser/ui/panels/panel_browser_frame_view.h"
#include "chrome/browser/ui/panels/panel_browser_view.h"
#include "chrome/browser/ui/touch/frame/touch_browser_frame_view.h"
#include "chrome/browser/ui/views/frame/browser_view.h"
#include "chrome/browser/ui/views/frame/popup_non_client_frame_view.h"
#include "chrome/common/chrome_switches.h"

namespace browser {

BrowserNonClientFrameView* CreateBrowserNonClientFrameView(
    BrowserFrame* frame, BrowserView* browser_view) {
  Browser::Type type = browser_view->browser()->type();
  switch (type) {
    case Browser::TYPE_PANEL:
      if (CommandLine::ForCurrentProcess()->HasSwitch(
              switches::kEnablePanels)) {
        return new PanelBrowserFrameView(
            frame, static_cast<PanelBrowserView*>(browser_view));
      }  // else, fall-through and treat as popup
    case Browser::TYPE_POPUP:
      // TODO(anicolao): implement popups for touch
      NOTIMPLEMENTED();
      return new PopupNonClientFrameView(frame);
    default:
      return new TouchBrowserFrameView(frame, browser_view);
  }
}

}  // browser

Use the normal panel-frame until there's a touch-friendly version.

BUG=none
TEST=browser_test:WindowOpenPanel

Review URL: http://codereview.chromium.org/7192001

git-svn-id: de016e52bd170d2d4f2344f9bf92d50478b649e0@89364 0039d316-1c4b-4281-b951-d872f2087c98


// RUN: not %clang_cc1 -triple i686-pc-win32 -emit-llvm -fno-rtti %s 2>&1 | FileCheck %s

// CHECK: error: v-table layout for classes with non-virtual base classes that override methods in virtual bases is not supported yet

struct A {
  virtual int foo() { return a; }
  int a;
};
struct B : virtual A {
  B() : b(1) {}
  virtual int bar() { return b; }
  int b;
};
struct C : virtual A {
  C() : c(2) {}
  virtual int foo() { return c; }
  int c;
};
struct D : B, C {
  D() : d(3) {}
  virtual int bar() { return d; }
  int d;
};
int main() {
  D d;
  return d.foo();
}

// RUN: not %clang_cc1 -triple i686-pc-win32 -emit-llvm-only -fno-rtti %s 2>&1 | FileCheck %s

// CHECK: error: v-table layout for classes with non-virtual base classes that override methods in virtual bases is not supported yet

struct A {
  virtual int foo() { return a; }
  int a;
};
struct B : virtual A {
  B() : b(1) {}
  virtual int bar() { return b; }
  int b;
};
struct C : virtual A {
  C() : c(2) {}
  virtual int foo() { return c; }
  int c;
};
struct D : B, C {
  D() : d(3) {}
  virtual int bar() { return d; }
  int d;
};
int main() {
  D d;
  return d.foo();
}

Change this test to not try to emit any IR. (It should fail to, but it tries to create an output file before encountering the error.)

git-svn-id: ffe668792ed300d6c2daa1f6eba2e0aa28d7ec6c@202343 91177308-0d34-0410-b5e6-96231b3b80d8