slave_comms.h

Thu, 07 Jul 2016 12:23:34 +0200

author
mbayer
date
Thu, 07 Jul 2016 12:23:34 +0200
changeset 2
b373b0288715
parent 0
2c8ba1964db7
permissions
-rw-r--r--

added missing sanguino files

0
2c8ba1964db7 Initial code from reprappro Marlin repository
mbayer
parents:
diff changeset
1 #ifndef _SLAVE_COMMSH
2c8ba1964db7 Initial code from reprappro Marlin repository
mbayer
parents:
diff changeset
2 #define _SLAVE_COMMSH
2c8ba1964db7 Initial code from reprappro Marlin repository
mbayer
parents:
diff changeset
3 /*
2c8ba1964db7 Initial code from reprappro Marlin repository
mbayer
parents:
diff changeset
4 Functions to drive, and to return values from, a slave processor
2c8ba1964db7 Initial code from reprappro Marlin repository
mbayer
parents:
diff changeset
5
2c8ba1964db7 Initial code from reprappro Marlin repository
mbayer
parents:
diff changeset
6 Adrian Bowyer 29 July 2012
2c8ba1964db7 Initial code from reprappro Marlin repository
mbayer
parents:
diff changeset
7 */
2c8ba1964db7 Initial code from reprappro Marlin repository
mbayer
parents:
diff changeset
8
2c8ba1964db7 Initial code from reprappro Marlin repository
mbayer
parents:
diff changeset
9 #ifdef REPRAPPRO_MULTIMATERIALS
2c8ba1964db7 Initial code from reprappro Marlin repository
mbayer
parents:
diff changeset
10
2c8ba1964db7 Initial code from reprappro Marlin repository
mbayer
parents:
diff changeset
11 extern float txyz[];
2c8ba1964db7 Initial code from reprappro Marlin repository
mbayer
parents:
diff changeset
12 extern char slaveBuffer[];
2c8ba1964db7 Initial code from reprappro Marlin repository
mbayer
parents:
diff changeset
13 extern long timeout;
2c8ba1964db7 Initial code from reprappro Marlin repository
mbayer
parents:
diff changeset
14 #define TIMEOUT 4 // ms
2c8ba1964db7 Initial code from reprappro Marlin repository
mbayer
parents:
diff changeset
15
2c8ba1964db7 Initial code from reprappro Marlin repository
mbayer
parents:
diff changeset
16 float slaveDegHotend(uint8_t extruder);
2c8ba1964db7 Initial code from reprappro Marlin repository
mbayer
parents:
diff changeset
17 void slaveSetTargetHotend(const float &celsius, uint8_t extruder);
2c8ba1964db7 Initial code from reprappro Marlin repository
mbayer
parents:
diff changeset
18 float slaveDegTargetHotend(uint8_t extruder);
2c8ba1964db7 Initial code from reprappro Marlin repository
mbayer
parents:
diff changeset
19 bool slaveIsHeatingHotend(uint8_t extruder);
2c8ba1964db7 Initial code from reprappro Marlin repository
mbayer
parents:
diff changeset
20 bool slaveIsCoolingHotend(uint8_t extruder);
2c8ba1964db7 Initial code from reprappro Marlin repository
mbayer
parents:
diff changeset
21 void slaveRemoteStep(int8_t extruder, int8_t v);
2c8ba1964db7 Initial code from reprappro Marlin repository
mbayer
parents:
diff changeset
22 void slaveRemoteDir(int8_t extruder, bool forward);
2c8ba1964db7 Initial code from reprappro Marlin repository
mbayer
parents:
diff changeset
23 void talkToSlave(char s[]);
2c8ba1964db7 Initial code from reprappro Marlin repository
mbayer
parents:
diff changeset
24 char* listenToSlave();
2c8ba1964db7 Initial code from reprappro Marlin repository
mbayer
parents:
diff changeset
25 void setup_slave();
2c8ba1964db7 Initial code from reprappro Marlin repository
mbayer
parents:
diff changeset
26
2c8ba1964db7 Initial code from reprappro Marlin repository
mbayer
parents:
diff changeset
27
2c8ba1964db7 Initial code from reprappro Marlin repository
mbayer
parents:
diff changeset
28 FORCE_INLINE float slaveDegHotend(uint8_t extruder) { return txyz[extruder]; }
2c8ba1964db7 Initial code from reprappro Marlin repository
mbayer
parents:
diff changeset
29 FORCE_INLINE void slaveSetTargetHotend(const float &celsius, uint8_t extruder) {txyz[extruder] = celsius; }
2c8ba1964db7 Initial code from reprappro Marlin repository
mbayer
parents:
diff changeset
30 FORCE_INLINE float slaveDegTargetHotend(uint8_t extruder) { return txyz[extruder]; }
2c8ba1964db7 Initial code from reprappro Marlin repository
mbayer
parents:
diff changeset
31 FORCE_INLINE bool slaveIsHeatingHotend(uint8_t extruder) { return false; }
2c8ba1964db7 Initial code from reprappro Marlin repository
mbayer
parents:
diff changeset
32 FORCE_INLINE bool slaveIsCoolingHotend(uint8_t extruder) { return false; }
2c8ba1964db7 Initial code from reprappro Marlin repository
mbayer
parents:
diff changeset
33
2c8ba1964db7 Initial code from reprappro Marlin repository
mbayer
parents:
diff changeset
34
2c8ba1964db7 Initial code from reprappro Marlin repository
mbayer
parents:
diff changeset
35 FORCE_INLINE void slaveRemoteStep(int8_t extruder, int8_t v)
2c8ba1964db7 Initial code from reprappro Marlin repository
mbayer
parents:
diff changeset
36 {
2c8ba1964db7 Initial code from reprappro Marlin repository
mbayer
parents:
diff changeset
37
2c8ba1964db7 Initial code from reprappro Marlin repository
mbayer
parents:
diff changeset
38 }
2c8ba1964db7 Initial code from reprappro Marlin repository
mbayer
parents:
diff changeset
39
2c8ba1964db7 Initial code from reprappro Marlin repository
mbayer
parents:
diff changeset
40 FORCE_INLINE void toggleSlaveClock()
2c8ba1964db7 Initial code from reprappro Marlin repository
mbayer
parents:
diff changeset
41 {
2c8ba1964db7 Initial code from reprappro Marlin repository
mbayer
parents:
diff changeset
42 digitalWrite(SLAVE_CLOCK, !digitalRead(SLAVE_CLOCK));
2c8ba1964db7 Initial code from reprappro Marlin repository
mbayer
parents:
diff changeset
43 }
2c8ba1964db7 Initial code from reprappro Marlin repository
mbayer
parents:
diff changeset
44
2c8ba1964db7 Initial code from reprappro Marlin repository
mbayer
parents:
diff changeset
45 FORCE_INLINE void slaveRemoteDir(int8_t extruder, bool forward)
2c8ba1964db7 Initial code from reprappro Marlin repository
mbayer
parents:
diff changeset
46 {
2c8ba1964db7 Initial code from reprappro Marlin repository
mbayer
parents:
diff changeset
47
2c8ba1964db7 Initial code from reprappro Marlin repository
mbayer
parents:
diff changeset
48 }
2c8ba1964db7 Initial code from reprappro Marlin repository
mbayer
parents:
diff changeset
49
2c8ba1964db7 Initial code from reprappro Marlin repository
mbayer
parents:
diff changeset
50 FORCE_INLINE void talkToSlave(char s[]) { MYSERIAL1.println(s); }
2c8ba1964db7 Initial code from reprappro Marlin repository
mbayer
parents:
diff changeset
51 FORCE_INLINE char* listenToSlave()
2c8ba1964db7 Initial code from reprappro Marlin repository
mbayer
parents:
diff changeset
52 {
2c8ba1964db7 Initial code from reprappro Marlin repository
mbayer
parents:
diff changeset
53 int c = 0;
2c8ba1964db7 Initial code from reprappro Marlin repository
mbayer
parents:
diff changeset
54 timeout = millis();
2c8ba1964db7 Initial code from reprappro Marlin repository
mbayer
parents:
diff changeset
55 int8_t i = 0;
2c8ba1964db7 Initial code from reprappro Marlin repository
mbayer
parents:
diff changeset
56 while(c != '\n' && (millis() - timeout < TIMEOUT))
2c8ba1964db7 Initial code from reprappro Marlin repository
mbayer
parents:
diff changeset
57 {
2c8ba1964db7 Initial code from reprappro Marlin repository
mbayer
parents:
diff changeset
58 while(!MYSERIAL1.available() && (millis() - timeout < TIMEOUT));
2c8ba1964db7 Initial code from reprappro Marlin repository
mbayer
parents:
diff changeset
59 c = MYSERIAL1.read();
2c8ba1964db7 Initial code from reprappro Marlin repository
mbayer
parents:
diff changeset
60 //timeout = millis();
2c8ba1964db7 Initial code from reprappro Marlin repository
mbayer
parents:
diff changeset
61 slaveBuffer[i] = (char)c;
2c8ba1964db7 Initial code from reprappro Marlin repository
mbayer
parents:
diff changeset
62 i++;
2c8ba1964db7 Initial code from reprappro Marlin repository
mbayer
parents:
diff changeset
63 }
2c8ba1964db7 Initial code from reprappro Marlin repository
mbayer
parents:
diff changeset
64 slaveBuffer[i] = 0;
2c8ba1964db7 Initial code from reprappro Marlin repository
mbayer
parents:
diff changeset
65 return slaveBuffer;
2c8ba1964db7 Initial code from reprappro Marlin repository
mbayer
parents:
diff changeset
66 }
2c8ba1964db7 Initial code from reprappro Marlin repository
mbayer
parents:
diff changeset
67
2c8ba1964db7 Initial code from reprappro Marlin repository
mbayer
parents:
diff changeset
68 #endif
2c8ba1964db7 Initial code from reprappro Marlin repository
mbayer
parents:
diff changeset
69
2c8ba1964db7 Initial code from reprappro Marlin repository
mbayer
parents:
diff changeset
70 #endif
2c8ba1964db7 Initial code from reprappro Marlin repository
mbayer
parents:
diff changeset
71

mercurial