neoclock 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 669e44699555eabde8eaba3d271dcc3dc3b3b4d9
4
+ data.tar.gz: 9669cd058530814b69c2af1e698b10d9a39b3d84
5
+ SHA512:
6
+ metadata.gz: 5164424ae26dbd6faff81b7511f8e723b144b8626af25fd9fe5f938cd58a67b418a7be27e8a692af29401276ce075c545a2e0c10ff30599c16bf5b8484a9edf0
7
+ data.tar.gz: d16682824227ea4cd41d0aa66d14339527bb1a6b0216380cb5127afee6bb5e56f62bd227aaf64710a49e2a2a34ab793b742ce313878ebfec90fe2fa23564da56
data/.gitignore ADDED
@@ -0,0 +1,9 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
data/.rspec ADDED
@@ -0,0 +1,3 @@
1
+ --format documentation
2
+ --color
3
+ --require spec_helper
data/.ruby-version ADDED
@@ -0,0 +1 @@
1
+ 2.3.1
data/.travis.yml ADDED
@@ -0,0 +1,3 @@
1
+ language: ruby
2
+ rvm:
3
+ - 2.3.1
@@ -0,0 +1,49 @@
1
+ # Contributor Code of Conduct
2
+
3
+ As contributors and maintainers of this project, and in the interest of
4
+ fostering an open and welcoming community, we pledge to respect all people who
5
+ contribute through reporting issues, posting feature requests, updating
6
+ documentation, submitting pull requests or patches, and other activities.
7
+
8
+ We are committed to making participation in this project a harassment-free
9
+ experience for everyone, regardless of level of experience, gender, gender
10
+ identity and expression, sexual orientation, disability, personal appearance,
11
+ body size, race, ethnicity, age, religion, or nationality.
12
+
13
+ Examples of unacceptable behavior by participants include:
14
+
15
+ * The use of sexualized language or imagery
16
+ * Personal attacks
17
+ * Trolling or insulting/derogatory comments
18
+ * Public or private harassment
19
+ * Publishing other's private information, such as physical or electronic
20
+ addresses, without explicit permission
21
+ * Other unethical or unprofessional conduct
22
+
23
+ Project maintainers have the right and responsibility to remove, edit, or
24
+ reject comments, commits, code, wiki edits, issues, and other contributions
25
+ that are not aligned to this Code of Conduct, or to ban temporarily or
26
+ permanently any contributor for other behaviors that they deem inappropriate,
27
+ threatening, offensive, or harmful.
28
+
29
+ By adopting this Code of Conduct, project maintainers commit themselves to
30
+ fairly and consistently applying these principles to every aspect of managing
31
+ this project. Project maintainers who do not follow or enforce the Code of
32
+ Conduct may be permanently removed from the project team.
33
+
34
+ This code of conduct applies both within project spaces and in public spaces
35
+ when an individual is representing the project or its community.
36
+
37
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be
38
+ reported by contacting a project maintainer at github@orgraphone.org. All
39
+ complaints will be reviewed and investigated and will result in a response that
40
+ is deemed necessary and appropriate to the circumstances. Maintainers are
41
+ obligated to maintain confidentiality with regard to the reporter of an
42
+ incident.
43
+
44
+ This Code of Conduct is adapted from the [Contributor Covenant][homepage],
45
+ version 1.3.0, available at
46
+ [http://contributor-covenant.org/version/1/3/0/][version]
47
+
48
+ [homepage]: http://contributor-covenant.org
49
+ [version]: http://contributor-covenant.org/version/1/3/0/
data/Gemfile ADDED
@@ -0,0 +1,6 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in neoclock.gemspec
4
+ gemspec
5
+
6
+ gem 'pry'
data/LICENSE.md ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2016 Sam Pikesley
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,6 @@
1
+ [![Build Status](http://img.shields.io/travis/pikesley/neoclock.svg?style=flat-square)](https://travis-ci.org/pikesley/neoclock)
2
+ [![Dependency Status](http://img.shields.io/gemnasium/pikesley/neoclock.svg?style=flat-square)](https://gemnasium.com/pikesley/neoclock)
3
+ [![Coverage Status](http://img.shields.io/coveralls/pikesley/neoclock.svg?style=flat-square)](https://coveralls.io/r/pikesley/neoclock)
4
+ [![Code Climate](http://img.shields.io/codeclimate/github/pikesley/neoclock.svg?style=flat-square)](https://codeclimate.com/github/pikesley/neoclock)
5
+ [![Gem Version](http://img.shields.io/gem/v/neoclock.svg?style=flat-square)](https://rubygems.org/gems/neoclock)
6
+ [![License](http://img.shields.io/:license-mit-blue.svg?style=flat-square)](http://pikesley.mit-license.org)
data/Rakefile ADDED
@@ -0,0 +1,40 @@
1
+ require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
3
+
4
+ require 'timecop'
5
+ require 'neoclock'
6
+
7
+ namespace :clock do
8
+ task :time do
9
+ clock = Neoclock::Clock.new
10
+ clock.time
11
+ end
12
+
13
+ task :roll do
14
+ clock = Neoclock::Clock.new
15
+ t = 82800
16
+ while t <= 126000
17
+ Timecop.freeze DateTime.strptime(t.to_s, '%s') do
18
+ clock.time
19
+ t += 60
20
+ end
21
+ sleep 0.05
22
+ end
23
+ clock.time
24
+ end
25
+
26
+ task :shuffle do
27
+ clock = Neoclock::Clock.new
28
+ Random.rand(256).times do
29
+ Timecop.freeze DateTime.strptime(Random.rand(86400).to_s, '%s') do
30
+ clock.time
31
+ end
32
+ sleep 0.05
33
+ end
34
+ clock.time
35
+ end
36
+ end
37
+
38
+ RSpec::Core::RakeTask.new(:spec)
39
+
40
+ task :default => :spec
data/bin/console ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "neoclock"
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require "irb"
14
+ IRB.start
data/bin/setup ADDED
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
data/config/clock.yml ADDED
@@ -0,0 +1,16 @@
1
+ minutes:
2
+ pins: 24
3
+
4
+ hours:
5
+ pins: 12
6
+
7
+ colours:
8
+ figure: red
9
+ ground: blue
10
+
11
+ led:
12
+ pin: 18
13
+ freq: 800000
14
+ dma: 5
15
+ brightness: 16 # DOES FUCK ALL
16
+ invert: false
@@ -0,0 +1,32 @@
1
+ black:
2
+ - 0
3
+ - 0
4
+ - 0
5
+ blue:
6
+ - 0
7
+ - 0
8
+ - 255
9
+ cyan:
10
+ - 0
11
+ - 255
12
+ - 255
13
+ green:
14
+ - 0
15
+ - 255
16
+ - 0
17
+ magenta:
18
+ - 255
19
+ - 0
20
+ - 255
21
+ red:
22
+ - 255
23
+ - 0
24
+ - 0
25
+ white:
26
+ - 255
27
+ - 255
28
+ - 255
29
+ yellow:
30
+ - 255
31
+ - 255
32
+ - 0
data/hack.rb ADDED
@@ -0,0 +1,43 @@
1
+ require 'date'
2
+
3
+ begin
4
+ require "pixel_pi"
5
+ rescue LoadError
6
+ lib = File.expand_path('../../lib', __FILE__)
7
+ raise if $LOAD_PATH.include?(lib)
8
+ $LOAD_PATH.unshift(lib)
9
+ retry
10
+ end
11
+
12
+ LED_COUNT = 36 # Number of LED pixels.
13
+ LED_PIN = 18 # GPIO pin connected to the pixels (must support PWM!).
14
+ LED_FREQ_HZ = 800000 # LED signal frequency in hertz (usually 800khz)
15
+ LED_DMA = 5 # DMA channel to use for generating signal (try 5)
16
+ LED_BRIGHTNESS = 255 # Scale the brightness of the pixels (0 to 255)
17
+ LED_INVERT = false # True to invert the signal (when using NPN transistor level shift)
18
+
19
+ clock = PixelPi::Leds.new \
20
+ LED_COUNT, LED_PIN,
21
+ :frequency => LED_FREQ_HZ,
22
+ :dma => LED_DMA,
23
+ :brightness => LED_BRIGHTNESS,
24
+ :invert => LED_INVERT,
25
+ :debug => true
26
+
27
+
28
+ loop do
29
+ clock.clear.show
30
+ dt = DateTime.now
31
+ hours = (dt.hour % 12) + 24
32
+ minutes = (dt.minute / 2.5).to_i
33
+ puts "#{dt.hour}:#{dt.minute} - #{hours}:#{minutes}"
34
+
35
+ LED_COUNT.times do |i|
36
+ clock[i] = PixelPi::Color(0, 0, 0)
37
+ end
38
+
39
+ clock[hours] = PixelPi::Color(250, 129, 0)
40
+ clock[minutes] = PixelPi::Color(250, 129, 0)
41
+ clock.show
42
+ sleep 60
43
+ end
data/lib/neoclock.rb ADDED
@@ -0,0 +1,27 @@
1
+ require 'pixel_pi'
2
+ require 'singleton'
3
+ require 'ostruct'
4
+ require 'yaml'
5
+
6
+ require 'neoclock/version'
7
+ require 'neoclock/clock'
8
+ require 'neoclock/config'
9
+
10
+ module Neoclock
11
+ def self.blender start, stop, sixtieth
12
+ c = []
13
+ start.each_with_index do |component, i|
14
+ c.push intersperse(component, stop[i], sixtieth)
15
+ end
16
+ c
17
+ end
18
+
19
+ def self.intersperse first, second, sixtieth
20
+ lower, higher = first, second
21
+ if second < first
22
+ lower, higher = second, first
23
+ sixtieth = 60 - sixtieth
24
+ end
25
+ ((higher - lower) / 60.0 * sixtieth).to_i + lower
26
+ end
27
+ end
@@ -0,0 +1,65 @@
1
+ module Neoclock
2
+ class Clock
3
+ attr_reader :lights
4
+
5
+ def initialize options = {}
6
+ @config = Config.instance.config
7
+
8
+ @figure = Config.instance.colours[@config.colours['figure']]
9
+ @ground = Config.instance.colours[@config.colours['ground']]
10
+
11
+ @total_size = @config.minutes['pins'] + @config.hours['pins']
12
+
13
+ @rings = PixelPi::Leds.new \
14
+ @total_size,
15
+ @config.led['pin'],
16
+ frequency: @config.led['freq'],
17
+ dma: @config.led['dma'],
18
+ brightness: @config.led['brightness'],
19
+ invert: @config.led['invert']
20
+ end
21
+
22
+ def time
23
+ dt = DateTime.now
24
+ @lights = []
25
+
26
+ minutes = ((@config.minutes['pins'] / 60.0) * dt.minute).round
27
+ hours = (dt.hour % 12) + @config.minutes['pins']
28
+
29
+ @total_size.times do
30
+ @lights.push @ground
31
+ end
32
+
33
+ @lights[hours] = @figure
34
+ Clock.minute_block(minutes, @figure, @ground).each_pair do |index, colour|
35
+ @lights[index] = colour
36
+ end
37
+
38
+ @lights.each_with_index do |colour, i|
39
+ @rings[i] = PixelPi::Color *colour
40
+ end
41
+
42
+ @rings.show
43
+ end
44
+
45
+ def self.minute_block pin, figure, ground
46
+ h = {}
47
+
48
+ h[pin] = figure
49
+
50
+ before = pin - 1
51
+ if before < 0
52
+ before = Config.instance.config.minutes['pins'] - 1
53
+ end
54
+ h[before] = figure
55
+
56
+ after = pin + 1
57
+ if after >= Config.instance.config.minutes['pins']
58
+ after = pin - Config.instance.config.minutes['pins'] + 1
59
+ end
60
+ h[after] = figure
61
+
62
+ h
63
+ end
64
+ end
65
+ end
@@ -0,0 +1,28 @@
1
+ module Neoclock
2
+ class Config
3
+ include Singleton
4
+
5
+ def initialize
6
+ reset!
7
+ end
8
+
9
+ def reset! # testing a singleton is hard
10
+ @config = OpenStruct.new fetch_yaml 'clock'
11
+ @colours = OpenStruct.new fetch_yaml 'colours'
12
+ end
13
+
14
+ def config
15
+ @config
16
+ end
17
+
18
+ def colours
19
+ @colours
20
+ end
21
+
22
+ private
23
+
24
+ def fetch_yaml file
25
+ YAML.load(File.open(File.join(File.dirname(__FILE__), '..', '..', 'config/%s.yml' % file)))
26
+ end
27
+ end
28
+ end
@@ -0,0 +1,3 @@
1
+ module Neoclock
2
+ VERSION = "0.1.0"
3
+ end
data/neoclock.gemspec ADDED
@@ -0,0 +1,29 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'neoclock/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = 'neoclock'
8
+ spec.version = Neoclock::VERSION
9
+ spec.authors = ['pikesley']
10
+ spec.email = ['github@orgraphone.org']
11
+
12
+ spec.summary = %q{NeoPixel clock}
13
+ spec.description = %q{NeoPixel clock}
14
+ spec.homepage = 'http://sam.pikesley.org'
15
+ spec.license = 'MIT'
16
+
17
+ spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
18
+ spec.bindir = 'exe'
19
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
20
+ spec.require_paths = ['lib']
21
+
22
+ spec.add_dependency 'pixel_pi', '~> 0.2'
23
+
24
+ spec.add_development_dependency 'bundler', '~> 1.12'
25
+ spec.add_development_dependency 'rake', '~> 11.3'
26
+ spec.add_development_dependency 'rspec', '~> 3.0'
27
+ spec.add_development_dependency 'coveralls', '~> 0.8'
28
+ spec.add_development_dependency 'timecop', '~> 0.8'
29
+ end
metadata ADDED
@@ -0,0 +1,147 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: neoclock
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - pikesley
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2016-10-02 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: pixel_pi
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '0.2'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '0.2'
27
+ - !ruby/object:Gem::Dependency
28
+ name: bundler
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '1.12'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '1.12'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rake
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '11.3'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '11.3'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rspec
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '3.0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '3.0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: coveralls
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: '0.8'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: '0.8'
83
+ - !ruby/object:Gem::Dependency
84
+ name: timecop
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - "~>"
88
+ - !ruby/object:Gem::Version
89
+ version: '0.8'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - "~>"
95
+ - !ruby/object:Gem::Version
96
+ version: '0.8'
97
+ description: NeoPixel clock
98
+ email:
99
+ - github@orgraphone.org
100
+ executables: []
101
+ extensions: []
102
+ extra_rdoc_files: []
103
+ files:
104
+ - ".gitignore"
105
+ - ".rspec"
106
+ - ".ruby-version"
107
+ - ".travis.yml"
108
+ - CODE_OF_CONDUCT.md
109
+ - Gemfile
110
+ - LICENSE.md
111
+ - README.md
112
+ - Rakefile
113
+ - bin/console
114
+ - bin/setup
115
+ - config/clock.yml
116
+ - config/colours.yml
117
+ - hack.rb
118
+ - lib/neoclock.rb
119
+ - lib/neoclock/clock.rb
120
+ - lib/neoclock/config.rb
121
+ - lib/neoclock/version.rb
122
+ - neoclock.gemspec
123
+ homepage: http://sam.pikesley.org
124
+ licenses:
125
+ - MIT
126
+ metadata: {}
127
+ post_install_message:
128
+ rdoc_options: []
129
+ require_paths:
130
+ - lib
131
+ required_ruby_version: !ruby/object:Gem::Requirement
132
+ requirements:
133
+ - - ">="
134
+ - !ruby/object:Gem::Version
135
+ version: '0'
136
+ required_rubygems_version: !ruby/object:Gem::Requirement
137
+ requirements:
138
+ - - ">="
139
+ - !ruby/object:Gem::Version
140
+ version: '0'
141
+ requirements: []
142
+ rubyforge_project:
143
+ rubygems_version: 2.5.1
144
+ signing_key:
145
+ specification_version: 4
146
+ summary: NeoPixel clock
147
+ test_files: []