Skip to content

Commit

Permalink
Merge pull request #35 from FabLabWgtn/bugfixe
Browse files Browse the repository at this point in the history
clean macosX, speed R/W, Try to port to 3.0
  • Loading branch information
mcanet committed Oct 5, 2015
2 parents a3f5cb0 + ba70918 commit c88116b
Show file tree
Hide file tree
Showing 636 changed files with 325 additions and 14,658 deletions.
35 changes: 30 additions & 5 deletions arduino_code/openKnitting_handMadepcb_v0_1/communication.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,15 @@ class communication {
endLines* myEndlines;
solenoids* mysolenoids;
unsigned long lastSendTimeStamp;
char receivedBin[201];
unsigned long lastRecieveTimeStamp;
char receivedBin[202];
int dataSize;
boolean dataReplace;
byte footer;
char lf;
boolean solenoidsAreOff;
boolean corruptMessage;

public:
String _status;
communication() {
Expand All @@ -30,9 +34,12 @@ class communication {
myEndlines = _myEndlines;
mysolenoids = _mysolenoids;
lastSendTimeStamp = millis();
dataSize = 201;
footer = 126;
lastRecieveTimeStamp = millis();
dataSize = 202;
footer = '&';
dataReplace = false;
solenoidsAreOff = false;
corruptMessage = false;
lf = '@'; // AT in ASCII
Serial.setTimeout(10);
}
Expand Down Expand Up @@ -97,25 +104,43 @@ class communication {
Serial.println(lf);
myEncoders->lastencoder1Pos = myEncoders->encoder1Pos;
}
if (corruptMessage){
Serial.print("C"); // for corrupt
Serial.println(lf);
corruptMessage=false;
}
}

// recieve from processing
void receiveAllLine() {
while(Serial.available()) {
if ( Serial.readBytesUntil(footer, receivedBin, dataSize)) {
dataReplace = true;
if (receivedBin[0]==lf){ // begin and end are here so ok
dataReplace = true;
}
else{
corruptMessage=true;
sendSerialToComputer();
}
}
}
if (dataReplace) {
lastRecieveTimeStamp = millis();
sendCurrentPixelArray();
dataReplace = false;
solenoidsAreOff=false;
}
else if (((millis() - lastRecieveTimeStamp) > 50000) && (solenoidsAreOff==false)){ // release solenoid if nothing recieve after 50s
mysolenoids->setAllSolOff();
solenoidsAreOff=true;
}

}

// send to processing
void sendCurrentPixelArray() {
Serial.println(lf);
for (int i = 0; i < 200; i++) {
for (int i = 1; i < 201; i++) {
pixelBin[i] = receivedBin[i];
Serial.print(pixelBin[i]);
}
Expand Down
6 changes: 3 additions & 3 deletions arduino_code/openKnitting_handMadepcb_v0_1/encoders.h
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ class encoders{

//-------------------------------------------------------------------------
boolean get8segmentEncoder(){
_8segmentEncoder = (digitalRead(encoder0PinC)==HIGH);
_8segmentEncoder = (digitalReadDirect(encoder0PinC)==HIGH);
return _8segmentEncoder;
}

Expand All @@ -114,9 +114,9 @@ class encoders{
lastDirectionEncoders = directionEncoders;
directionEncoders = 0;

if(digitalRead(encoder0PinA)== HIGH){ directionEncoders += 1;}
if(digitalReadDirect(encoder0PinA)== HIGH){ directionEncoders += 1;}
else{ directionEncoders += 0;}
if(digitalRead(encoder0PinB)== HIGH){ directionEncoders +=3;}
if(digitalReadDirect(encoder0PinB)== HIGH){ directionEncoders +=3;}
else{ directionEncoders +=5;}

//last_8segmentEncoder = _8segmentEncoder;
Expand Down
10 changes: 10 additions & 0 deletions arduino_code/openKnitting_handMadepcb_v0_1/knitic.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,16 @@
*/
#ifndef KNITIC_H_
#define KNITIC_H_
#include "arduino.h"

inline void digitalWriteDirect(int pin, boolean val){
if(val) g_APinDescription[pin].pPort -> PIO_SODR = g_APinDescription[pin].ulPin;
else g_APinDescription[pin].pPort -> PIO_CODR = g_APinDescription[pin].ulPin;
}

inline int digitalReadDirect(int pin){
return !!(g_APinDescription[pin].pPort -> PIO_PDSR & g_APinDescription[pin].ulPin);
}

#include "encoders.h"
#include "sound_alerts.h"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,10 +84,6 @@ void loop() {
mysolenoids.loop();
#endif

// Set all solenoids OFF when end of line
if(myEncoders.encoder1Pos==0 || myEncoders.encoder1Pos==255 ){
mysolenoids.setAllSolOff();
}
myCommunicator.sendSerialToComputer();
}

Expand Down
10 changes: 4 additions & 6 deletions arduino_code/openKnitting_handMadepcb_v0_1/solenoids.h
Original file line number Diff line number Diff line change
Expand Up @@ -108,19 +108,17 @@ class solenoids{
}
}

if(currentStitchSetup>=(0-END_OF_LINE_OFFSET_R) && currentStitchSetup<(200+END_OF_LINE_OFFSET_L)){ //IF the head is within the switches....no. 200 is the left switch
if(currentStitchSetup>=0 && currentStitchSetup<200){ //IF the head is within the switches....no. 200 is the left switch
currentPixState = pixelBin[currentStitchSetup]; //Pixel Bin is an array of 256 values. It pulls values from the Serial Port
if(solenoidstateOn[m_solenoidToSet] != (currentPixState==1) ){ //if the current solenoid is different from the pixelBin value
digitalWrite(amegaPinsArray[m_solenoidToSet], currentPixState); //the that state to the Indexed Solenoid
solenoidstateOn[m_solenoidToSet] = (currentPixState==1); //update array of current solenoid States
}
digitalWriteDirect(amegaPinsArray[m_solenoidToSet], currentPixState); //the that state to the Indexed Solenoid
solenoidstateOn[m_solenoidToSet] = currentPixState; //update array of current solenoid States
}
}
}

void setAllSolOff(){
for(int i=0;i<16;i++){
digitalWrite(amegaPinsArray[i], LOW);
digitalWriteDirect(amegaPinsArray[i], LOW);
solenoidstateOn[i] = false;
}
}
Expand Down
6 changes: 0 additions & 6 deletions protoAppKnitic_p5/application.macosx/data/settings.json

This file was deleted.

This file was deleted.

Binary file not shown.
Binary file not shown.

This file was deleted.

Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.

This file was deleted.

Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

Loading

0 comments on commit c88116b

Please sign in to comment.