Created
January 11, 2011 06:35
-
-
Save jimsynz/774123 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include "Connection.h" | |
void Connection::is_connected_to(State* state) { | |
_state = state; | |
has_new_connection(state); | |
} | |
State* Connection::is_connected_to() { | |
return _state; | |
} | |
void Connection::has_new_connection(State* state) { | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#ifndef dCouple_Connection_h | |
#define dCouple_Connection_h | |
#include "State.h" | |
class Connection { | |
State* _state; | |
public: | |
void is_connected_to(State* state); | |
State* is_connected_to(); | |
void has_new_connection(State* state); | |
}; | |
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include "LED.h" | |
LED::LED () { | |
_intensity = 0.0; | |
set_state_resolution(255); | |
set_state_value((unsigned int)_intensity); | |
} | |
LED::LED (unsigned int intensity) { | |
_intensity = (float)intensity; | |
set_state_resolution(255); | |
set_state_value((unsigned int)_intensity); | |
} | |
LED::LED (unsigned int intensity, unsigned int resolution) { | |
_intensity = (float)intensity; | |
set_state_resolution(resolution); | |
set_state_value((unsigned int)_intensity); | |
} | |
unsigned int LED::intensity() { | |
return (unsigned int)_intensity; | |
} | |
void LED::set_intensity(unsigned int intensity) { | |
_intensity = (float)intensity; | |
set_state_value((unsigned int)_intensity); | |
} | |
void LED::animate_intensity_to(unsigned int intensity, unsigned int steps) { | |
_target_intensity = intensity; | |
_animation_step_size = ((float)_target_intensity - _intensity) / (float)steps; | |
_animation_steps_left = steps; | |
} | |
void LED::animate() { | |
if (_animation_steps_left != 0) { | |
_intensity = _intensity + _animation_step_size; | |
set_state_value((unsigned int)_intensity); | |
_animation_steps_left--; | |
} | |
else if (_intensity != _target_intensity) { | |
set_intensity(_target_intensity); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#ifndef dCouple_LED_h | |
#define dCouple_LED_h | |
class LED: public dCouple::State { | |
float _intensity; | |
unsigned int _target_intensity; | |
float _animation_step_size; | |
unsigned int _animation_steps_left; | |
public: | |
LED (); | |
LED (unsigned int intensity); | |
LED (unsigned int intensity, unsigned int resolution); | |
unsigned int intensity(); | |
void set_intensity(unsigned int intensity); | |
void animate_intensity_to(unsigned int intensity, unsigned int steps); | |
void animate(); | |
}; | |
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#ifndef dCouple_Sink_h | |
#define dCouple_Sink_h | |
#include "Connection.h" | |
class Sink: public Connection { | |
public: | |
virtual void sink_update() = 0; | |
}; | |
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#ifndef dCouple_Source_h | |
#define dCouple_Source_h | |
#include "Connection.h" | |
class Source: public Connection { | |
public: | |
virtual void source_update() = 0; | |
}; | |
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include "State.h" | |
State::State () { | |
_state_value = 0; | |
_state_resolution = 1; | |
_state_dirty = false; | |
} | |
void State::set_state_value(unsigned int value) { | |
if (value > _state_resolution) { | |
value = _state_resolution; | |
} | |
if (_state_value != value) { | |
_state_value = value; | |
_state_dirty = true; | |
state_has_changed(); | |
} | |
} | |
void State::set_state_resolution(unsigned int resolution) { | |
_state_resolution = resolution; | |
} | |
unsigned int State::state_value() { | |
_state_dirty = false; | |
return _state_value; | |
} | |
unsigned int State::state_resolution() { | |
return _state_resolution; | |
} | |
bool State::state_dirty() { | |
return _state_dirty; | |
} | |
void State::state_has_changed() { | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#ifndef dCouple_State_h | |
#define dCouple_State_h | |
class State { | |
unsigned int _state_value; | |
unsigned int _state_resolution; | |
bool _state_dirty; | |
public: | |
State (); | |
unsigned int state_value(); | |
unsigned int state_resolution(); | |
bool state_dirty(); | |
void set_state_value(unsigned int value); | |
void set_state_resolution(unsigned int resolution); | |
void state_has_changed(); | |
}; | |
#endif |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment