Skip to content

Commit

Permalink
Format with clang-format (ikeyasu#21)
Browse files Browse the repository at this point in the history
* Format with clang-format

* Update relative library include paths
  • Loading branch information
Sturla22 authored Feb 10, 2020
1 parent 22d5ffb commit 93da38d
Show file tree
Hide file tree
Showing 13 changed files with 378 additions and 458 deletions.
4 changes: 4 additions & 0 deletions .clang-format
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
---
AllowShortFunctionsOnASingleLine: None

...
80 changes: 36 additions & 44 deletions ayab.ino
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,14 @@ This file is part of AYAB.
http://ayab-knitting.com
*/


/*
* INCLUDES
*/
#include "Arduino.h"
#include "SerialCommand.h"
#include "./libraries/SerialCommand/SerialCommand.h"

#include "./libraries/PacketSerial/src/PacketSerial.h"
#include "./debug.h"
#include "./libraries/PacketSerial/src/PacketSerial.h"
#include "./settings.h"

#include "./knitter.h"
Expand All @@ -36,12 +35,11 @@ This file is part of AYAB.
* DEFINES
*/


/*
* DECLARATIONS
*/
Knitter *knitter;
byte lineBuffer[25];
*/
Knitter *knitter;
byte lineBuffer[25];

SLIPPacketSerial packetSerial;

Expand All @@ -55,9 +53,9 @@ void isr_encA() {
/*
* Serial Command handling
*/
void h_reqStart(const uint8_t* buffer, size_t size) {
void h_reqStart(const uint8_t *buffer, size_t size) {
byte _startNeedle = (byte)buffer[1];
byte _stopNeedle = (byte)buffer[2];
byte _stopNeedle = (byte)buffer[2];
bool _continuousReportingEnabled = (bool)buffer[3];

// TODO verify operation
Expand All @@ -67,43 +65,40 @@ void h_reqStart(const uint8_t* buffer, size_t size) {
lineBuffer[i] = 0xFF;
}

bool _success = knitter->startOperation(_startNeedle,
_stopNeedle,
_continuousReportingEnabled,
&(lineBuffer[0]));
bool _success = knitter->startOperation(
_startNeedle, _stopNeedle, _continuousReportingEnabled, &(lineBuffer[0]));

uint8_t payload[2];
payload[0] = cnfStart_msgid;
payload[1] = _success;
packetSerial.send(payload, 2);
}


void h_cnfLine(const uint8_t* buffer, size_t size) {
void h_cnfLine(const uint8_t *buffer, size_t size) {
byte _lineNumber = 0;
byte _flags = 0;
byte _crc8 = 0;
byte _crc8 = 0;
bool _flagLastLine = false;

_lineNumber = (byte)buffer[1];

for (int i = 0; i < 25; i++) {
// Values have to be inverted because of needle states
lineBuffer[i] = ~(byte)buffer[i+2];
lineBuffer[i] = ~(byte)buffer[i + 2];
}
_flags = (byte)buffer[27];
_crc8 = (byte)buffer[28];
_crc8 = (byte)buffer[28];

// TODO insert CRC8 check

if (knitter->setNextLine(_lineNumber)) {
// Line was accepted
_flagLastLine = bitRead(_flags, 0);
if ( _flagLastLine ) {
if (_flagLastLine) {
knitter->setLastLine();
}
}
}
}

void h_reqInfo() {
uint8_t payload[4];
Expand All @@ -115,44 +110,42 @@ void h_reqInfo() {
}

void h_reqTest() {
bool _success = knitter->startTest();
bool _success = knitter->startTest();

uint8_t payload[2];
payload[0] = cnfTest_msgid;
payload[1] = _success;
packetSerial.send(payload, 2);
uint8_t payload[2];
payload[0] = cnfTest_msgid;
payload[1] = _success;
packetSerial.send(payload, 2);
}


void h_unrecognized() {
return;
}

/*! Callback for PacketSerial
*
*/
void onPacketReceived(const uint8_t* buffer, size_t size)
{
void onPacketReceived(const uint8_t *buffer, size_t size) {
switch (buffer[0]) {
case reqStart_msgid:
h_reqStart(buffer, size);
break;
case reqStart_msgid:
h_reqStart(buffer, size);
break;

case cnfLine_msgid:
h_cnfLine(buffer, size);
break;
case cnfLine_msgid:
h_cnfLine(buffer, size);
break;

case reqInfo_msgid:
h_reqInfo();
break;
case reqInfo_msgid:
h_reqInfo();
break;

case reqTest_msgid:
h_reqTest();
break;
case reqTest_msgid:
h_reqTest();
break;

default:
h_unrecognized();
break;
default:
h_unrecognized();
break;
}
}

Expand Down Expand Up @@ -180,7 +173,6 @@ void setup() {
knitter = new Knitter(&packetSerial);
}


void loop() {
knitter->fsm();
packetSerial.update();
Expand Down
Loading

0 comments on commit 93da38d

Please sign in to comment.