Skip to content

Commit

Permalink
Initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
thed636 committed Dec 5, 2012
0 parents commit 364010e
Show file tree
Hide file tree
Showing 10 changed files with 414 additions and 0 deletions.
22 changes: 22 additions & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# Auto detect text files and perform LF normalization
* text=auto

# Custom for Visual Studio
*.cs diff=csharp
*.sln merge=union
*.csproj merge=union
*.vbproj merge=union
*.fsproj merge=union
*.dbproj merge=union

# Standard to msysgit
*.doc diff=astextplain
*.DOC diff=astextplain
*.docx diff=astextplain
*.DOCX diff=astextplain
*.dot diff=astextplain
*.DOT diff=astextplain
*.pdf diff=astextplain
*.PDF diff=astextplain
*.rtf diff=astextplain
*.RTF diff=astextplain
163 changes: 163 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,163 @@
#################
## Eclipse
#################

*.pydevproject
.project
.metadata
bin/
tmp/
*.tmp
*.bak
*.swp
*~.nib
local.properties
.classpath
.settings/
.loadpath

# External tool builders
.externalToolBuilders/

# Locally stored "Eclipse launch configurations"
*.launch

# CDT-specific
.cproject

# PDT-specific
.buildpath


#################
## Visual Studio
#################

## Ignore Visual Studio temporary files, build results, and
## files generated by popular Visual Studio add-ons.

# User-specific files
*.suo
*.user
*.sln.docstates

# Build results
[Dd]ebug/
[Rr]elease/
*_i.c
*_p.c
*.ilk
*.meta
*.obj
*.pch
*.pdb
*.pgc
*.pgd
*.rsp
*.sbr
*.tlb
*.tli
*.tlh
*.tmp
*.vspscc
.builds
*.dotCover

## TODO: If you have NuGet Package Restore enabled, uncomment this
#packages/

# Visual C++ cache files
ipch/
*.aps
*.ncb
*.opensdf
*.sdf

# Visual Studio profiler
*.psess
*.vsp

# ReSharper is a .NET coding add-in
_ReSharper*

# Installshield output folder
[Ee]xpress

# DocProject is a documentation generator add-in
DocProject/buildhelp/
DocProject/Help/*.HxT
DocProject/Help/*.HxC
DocProject/Help/*.hhc
DocProject/Help/*.hhk
DocProject/Help/*.hhp
DocProject/Help/Html2
DocProject/Help/html

# Click-Once directory
publish

# Others
[Bb]in
[Oo]bj
sql
TestResults
*.Cache
ClientBin
stylecop.*
~$*
*.dbmdl
Generated_Code #added for RIA/Silverlight projects

# Backup & report files from converting an old project file to a newer
# Visual Studio version. Backup files are not needed, because we have git ;-)
_UpgradeReport_Files/
Backup*/
UpgradeLog*.XML



############
## Windows
############

# Windows image file caches
Thumbs.db

# Folder config file
Desktop.ini


#############
## Python
#############

*.py[co]

# Packages
*.egg
*.egg-info
dist
build
eggs
parts
bin
var
sdist
develop-eggs
.installed.cfg

# Installer logs
pip-log.txt

# Unit test / coverage reports
.coverage
.tox

#Translations
*.mo

#Mr Developer
.mr.developer.cfg

# Mac crap
.DS_Store
24 changes: 24 additions & 0 deletions Blink/Blink.ino
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
/*
Blink
Turns on an LED on for one second, then off for one second, repeatedly.
This example code is in the public domain.
*/

// Pin 13 has an LED connected on most Arduino boards.
// give it a name:
int led = 22;

// the setup routine runs once when you press reset:
void setup() {
// initialize the digital pin as an output.
pinMode(led, OUTPUT);
}

// the loop routine runs over and over again forever:
void loop() {
digitalWrite(led, HIGH); // turn the LED on (HIGH is the voltage level)
delay(1000); // wait for a second
digitalWrite(led, LOW); // turn the LED off by making the voltage LOW
delay(1000); // wait for a second
}
101 changes: 101 additions & 0 deletions BlinkPwm/BlinkPwm.ino
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
#include <pwm_pin.h>

PwmPin ledPin(2);



#pragma pack(1)
const uint32_t packetSize = 16;

struct ArduinoMessage {
uint8_t type;
ArduinoMessage( char type ) : type(type) {}
};

struct PwmOut : public ArduinoMessage {
enum {messageType = 0x1, freeSize = packetSize - sizeof(ArduinoMessage) - 3};
uint8_t pin;
uint8_t value;
uint8_t zero;
uint8_t dummy[freeSize];
PwmOut( uint8_t pin, uint8_t value ) : ArduinoMessage(messageType), pin(pin), value(value), zero(0) {}
};

struct MoveDriveTo : public ArduinoMessage {
enum {messageType = 0x2, freeSize = packetSize - sizeof(ArduinoMessage) - 7};
uint8_t drive;
uint8_t speed;
int32_t x;
uint8_t zero;
uint8_t dummy[freeSize];
MoveDriveTo(uint8_t drive, uint8_t speed, int32_t x)
: ArduinoMessage(messageType), drive(drive), speed(speed), x(x), zero(0) {}
};

struct ArduinoResponse {
uint8_t result;
ArduinoResponse(uint8_t result = 0) : result(result) {}
};

#pragma pack()

char inBuf[packetSize];
uint8_t outBuf[packetSize];

void lightOn() {
for( int i=0; i!=255; ++i ) {
ledPin.value(i);
delay(1);
}
}

void lightOff(){
for( int i=255; i!=0; --i ) {
ledPin.value(i);
delay(1);
}
}
// the setup routine runs once when you press reset:
void setup() {
Serial.begin(115200);
Serial.flush();
while( Serial.available() )
Serial.read();

for( int i=0; i!=packetSize; ++i ) {
inBuf[i]=0x1;
outBuf[i]=0x1;
}
lightOn();
lightOff();
lightOn();
lightOff();
Serial.write(0x22);
}


// the loop routine runs over and over again forever:
void loop() {
if (Serial.available() >= packetSize) { //если есть доступные данные
// считываем байт
for( int i = 0; i!= packetSize; ++i )
inBuf[i]= Serial.read();
//if( inBuf[0] == 0xF ) {
switch( ((ArduinoMessage*)inBuf)->type ) {
case PwmOut::messageType:
{
const PwmOut & msg(*((PwmOut*)inBuf));
PwmPin pin(msg.pin);
pin.value(msg.value);
ArduinoResponse & response(*((ArduinoResponse*)outBuf));
response.result = 0;
}
default:;
}
//ledPin.value(inBuf[1]);
Serial.flush();
//lightOn();
Serial.write((uint8_t*)outBuf, packetSize);
//lightOff();
}
}
28 changes: 28 additions & 0 deletions libraries/pwm/pwm_driver.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
#ifndef PWM_DRIVER_H_031220122303
#define PWM_DRIVER_H_031220122303

#include <Arduino.h>
#include "pwm_pin.h"
#include "ttlout_pin.h"

class PwmDriver {
public:
PwmDriver(byte cwPinNumber, byte ccwPinNumber, byte pwmPinNumber)
: cwP(cwPinNumber), ccw(ccwPinNumber), pwm(pwmPinNumber) {
stop();
}
inline void stop() {
cw.low();
ccw.low();
}
inline void start( byte speed, bool ccwDirection ) {
pwm.value(speed);
cw.state(!ccwDirection);
ccw.state(ccwDirection);
}
private:
TtlOutPin cw;
TtlOutPin ccw;
PwmPin pwm;
}
#endif
1 change: 1 addition & 0 deletions libraries/pwm/pwm_pin.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
#include "pwm_pin.h"
23 changes: 23 additions & 0 deletions libraries/pwm/pwm_pin.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
#ifndef PWM_PIN_H_031220122303
#define PWM_PIN_H_031220122303
#include <Arduino.h>

class PwmPin {
public:
PwmPin( byte pinNumber ) : pin(pinNumber) {
pinMode(pin, OUTPUT);
}
inline void value(byte v) {
analogWrite(number(), v);
}
inline byte number() const {
return pin;
}
inline void reset() {
digitalWrite(number(),0);
}
private:
const byte pin;
};

#endif //PWM_PIN_H_031220122303
24 changes: 24 additions & 0 deletions libraries/pwm/ttlin_pin.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
#ifndef TTL_IN_PIN_H_031220122303
#define TTL_IN_PIN_H_031220122303

#include <Arduino.h>

class TtlInPin {
public:
TtlInPin( byte pinNumber ) : pin(pinNumber) {
pinMode(pin, INPUT);
}
inline bool high() const {
return digitalRead(number()) == HIGH;
}
inline bool low() const {
return !high();
}
inline byte number() const {
return pin;
}
private:
const byte pin;
};

#endif //TTL_IN_PIN_H_031220122303
Loading

0 comments on commit 364010e

Please sign in to comment.