Skip to content

Commit

Permalink
Release
Browse files Browse the repository at this point in the history
  • Loading branch information
Arkadiy Butermanov committed Mar 13, 2016
1 parent f66819a commit fcbea53
Show file tree
Hide file tree
Showing 11 changed files with 63 additions and 144 deletions.
2 changes: 1 addition & 1 deletion Gemfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
source 'https://rubygems.org'

# Specify your gem's dependencies in co2mond.gemspec
# Specify your gem's dependencies in co2mon.gemspec
gemspec
42 changes: 4 additions & 38 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,41 +1,7 @@
# Co2mond
# Co2mon

Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/co2mond`. To experiment with that code, run `bin/console` for an interactive prompt.
Based on https://github.com/dmage/co2mon

TODO: Delete this and the text above, and describe your gem

## Installation

Add this line to your application's Gemfile:

```ruby
gem 'co2mond'
```

And then execute:

$ bundle

Or install it yourself as:

$ gem install co2mond

## Usage

TODO: Write usage instructions here

## Development

After checking out the repo, run `bin/setup` to install dependencies. You can also run `bin/console` for an interactive prompt that will allow you to experiment.

To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).

## Contributing

Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/co2mond. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.


## License

The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
## Requirements

$ brew install hidapi
5 changes: 2 additions & 3 deletions Rakefile
Original file line number Diff line number Diff line change
@@ -1,3 +1,2 @@
require 'rake/extensiontask'
spec = Gem::Specification.load('co2mond.gemspec')
Rake::ExtensionTask.new('co2mon', spec)
require "bundler/gem_tasks"
task :default => :spec
2 changes: 1 addition & 1 deletion bin/console
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#!/usr/bin/env ruby

require "bundler/setup"
require "co2mond"
require "co2mon"

# You can add fixtures and/or initialization code here to make experimenting
# with your gem easier. You can also use a different console, if you like.
Expand Down
25 changes: 25 additions & 0 deletions co2mon.gemspec
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# coding: utf-8
lib = File.expand_path('../lib', __FILE__)
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
require 'co2mon/version'

Gem::Specification.new do |spec|
spec.name = "co2mon"
spec.version = Co2mon::VERSION
spec.authors = ["Arkadiy Butermanov"]
spec.email = ["[email protected]"]

spec.summary = %q{FFI bindings for MasterKit CO2 Monitor}
spec.homepage = "https://github.com/arkadiybutermanov/co2mon"
spec.license = "MIT"

spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
spec.bindir = "bin"
spec.extensions << './ext/co2mon/extconf.rb'
spec.require_paths = ["lib"]

spec.add_dependency "ffi"

spec.add_development_dependency "bundler", "~> 1.11"
spec.add_development_dependency "rake", "~> 10.0"
end
34 changes: 0 additions & 34 deletions co2mond.gemspec

This file was deleted.

68 changes: 9 additions & 59 deletions ext/co2mon/co2mon.c
Original file line number Diff line number Diff line change
Expand Up @@ -35,44 +35,13 @@ typedef hid_device *co2mon_device;

typedef unsigned char co2mon_data_t[8];

int
co2mon_init()
{
int r = hid_init();
if (r < 0)
{
fprintf(stderr, "hid_init: error\n");
}
return r;
}

void
co2mon_exit()
{
int r = hid_exit();
if (r < 0)
{
fprintf(stderr, "hid_exit: error\n");
}
}

hid_device *
co2mon_open_device()
{
hid_device *dev = hid_open(0x04d9, 0xa052, NULL);
if (!dev)
{
fprintf(stderr, "hid_open: error\n");
}
return dev;
}

void
co2mon_close_device(hid_device *dev)
{
hid_close(dev);
}

int
co2mon_device_path(hid_device *dev, char *str, size_t maxlen)
{
Expand Down Expand Up @@ -225,48 +194,29 @@ static int *device_loop(co2mon_device dev)

static int *main_loop()
{
int error_shown = 0;
static int empty_result[2] = {0};

co2mon_device dev = co2mon_open_device();

if (dev == NULL)
{
if (!error_shown)
{
fprintf(stderr, "Unable to open CO2 device\n");
error_shown = 1;
}
} else {
error_shown = 0;
return empty_result;
}

int *result = device_loop(dev);

co2mon_close_device(dev);
hid_close(dev);

return result;
}

VALUE get(VALUE self)
int *get()
{
int r = co2mon_init();
if (r < 0)
{
return r;
}
hid_init();

int *result = main_loop();

co2mon_exit();
hid_exit();

VALUE array;
array = rb_ary_new();
rb_ary_push(array, INT2FIX(result[0]));
rb_ary_push(array, INT2FIX(result[1]));

return array;
}

void
Init_co2mon(void) {
VALUE cCo2mon = rb_define_class("Co2mon", rb_cObject);
rb_define_singleton_method(cCo2mon, "get", get, 0);
return result;
}
Binary file removed lib/co2mon.bundle
Binary file not shown.
20 changes: 20 additions & 0 deletions lib/co2mon.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
require "co2mon/version"
require "ffi"

module Co2mon
extend FFI::Library

ffi_lib File.expand_path("co2mon.bundle", __dir__)

attach_function :get, [], :pointer

def self.get_data
data = get.get_array_of_int32(0, 2)

{
:co2 => data[0],
:temp => data[1]
}
rescue => e
end
end
2 changes: 1 addition & 1 deletion lib/co2mond/version.rb → lib/co2mon/version.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
module Co2mond
module Co2mon
VERSION = "0.1.0"
end
7 changes: 0 additions & 7 deletions lib/co2mond.rb

This file was deleted.

0 comments on commit fcbea53

Please sign in to comment.