Repo restyled using astyle (#683)

The rules are in .tools/astyle/config/style.cfg
and can also be reviewed at
https://www.mysensors.org/view/260#coding-guidelines-core-library
This commit is contained in:
Patrick Fallberg
2016-12-07 23:44:29 +01:00
committed by GitHub
parent d4c4ab82ea
commit 8e1ef13804
167 changed files with 16103 additions and 15168 deletions
+20 -18
View File
@@ -13,32 +13,34 @@
#define LOGDEBUG 1
#if defined ( LOGDEBUG )
#define LOG(fmt, args... ) log( fmt, ## args );
#define LOG(fmt, args... ) log( fmt, ## args );
#else
#define log(fmt, args... )
#define log(fmt, args... )
#endif
void log(const char *fmt, ... ) {
char buff[128];
va_list args;
va_start (args, fmt);
vsnprintf(buff, sizeof(buff), fmt, args);
va_end (args);
buff[sizeof(buff)/sizeof(buff[0])-1]='\0';
Serial.print(buff);
void log(const char *fmt, ... )
{
char buff[128];
va_list args;
va_start (args, fmt);
vsnprintf(buff, sizeof(buff), fmt, args);
va_end (args);
buff[sizeof(buff)/sizeof(buff[0])-1]='\0';
Serial.print(buff);
}
void log(const __FlashStringHelper *fmt, ... ){
char buf[128]; // resulting string limited to 128 chars
va_list args;
va_start (args, fmt);
void log(const __FlashStringHelper *fmt, ... )
{
char buf[128]; // resulting string limited to 128 chars
va_list args;
va_start (args, fmt);
#ifdef __AVR__
vsnprintf_P(buf, sizeof(buf), (const char *)fmt, args); // progmem for AVR
vsnprintf_P(buf, sizeof(buf), (const char *)fmt, args); // progmem for AVR
#else
vsnprintf(buf, sizeof(buf), (const char *)fmt, args); // for the rest of the world
vsnprintf(buf, sizeof(buf), (const char *)fmt, args); // for the rest of the world
#endif
va_end(args);
Serial.print(buf);
va_end(args);
Serial.print(buf);
}
#endif
+61 -53
View File
@@ -9,7 +9,7 @@
*/
// Enable debug prints to serial monitor
#define MY_DEBUG
#define MY_DEBUG
// Enable and select radio type attached
#define MY_RADIO_NRF24
@@ -28,71 +28,79 @@
MyMessage mPing(CHILD, V_VAR1); //Ping message
MyMessage mPong(CHILD, V_VAR2); //Pong message
void setup() {
void setup()
{
}
void presentation() {
present(CHILD, S_CUSTOM); //
sendSketchInfo( nodeTypeAsCharRepresentation( getNodeId() ), VSN );
LOG(F("\n%sReady.\n"), nodeTypeAsCharRepresentation(getNodeId()));
void presentation()
{
present(CHILD, S_CUSTOM); //
sendSketchInfo( nodeTypeAsCharRepresentation( getNodeId() ), VSN );
LOG(F("\n%sReady.\n"), nodeTypeAsCharRepresentation(getNodeId()));
}
void loop() {
// Interactive command and control
// Entering a number from 0 or 1 will write the node 200 (YING) or 201 (YANG) to EEPROM
// Entering T on either node will initiatve a ping-pong test.
if (Serial.available()) {
byte inChar = Serial.read();
uint8_t node = getNodeId();
// Manual Test Mode
if (inChar == 'T' || inChar == 't') {
LOG(F("T received - starting test...\n"));
MyMessage msg = mPong;
msg.sender = (node == YING ? YANG : YING);
sendPingOrPongResponse( msg );
}
else if (inChar == '0' or inChar == '1') {
byte nodeID = 200 + (inChar - '0');
setNodeId(nodeID);
}
else {
LOG("Invalid input\n");
}
}
void loop()
{
// Interactive command and control
// Entering a number from 0 or 1 will write the node 200 (YING) or 201 (YANG) to EEPROM
// Entering T on either node will initiatve a ping-pong test.
if (Serial.available()) {
byte inChar = Serial.read();
uint8_t node = getNodeId();
// Manual Test Mode
if (inChar == 'T' || inChar == 't') {
LOG(F("T received - starting test...\n"));
MyMessage msg = mPong;
msg.sender = (node == YING ? YANG : YING);
sendPingOrPongResponse( msg );
} else if (inChar == '0' or inChar == '1') {
byte nodeID = 200 + (inChar - '0');
setNodeId(nodeID);
} else {
LOG("Invalid input\n");
}
}
}
void receive(const MyMessage &message) {
LOG(F("Received %s from %s\n"), msgTypeAsCharRepresentation((mysensor_data)message.type), nodeTypeAsCharRepresentation(message.sender));
void receive(const MyMessage &message)
{
delay(250);
sendPingOrPongResponse( message );
LOG(F("Received %s from %s\n"), msgTypeAsCharRepresentation((mysensor_data)message.type),
nodeTypeAsCharRepresentation(message.sender));
delay(250);
sendPingOrPongResponse( message );
}
void sendPingOrPongResponse( MyMessage msg ) {
MyMessage response = (msg.type == V_VAR1 ? mPong : mPing);
LOG(F("Sending %s to %s\n"), msgTypeAsCharRepresentation( (mysensor_data)response.type ), nodeTypeAsCharRepresentation(msg.sender));
// Set payload to current time in millis to ensure each message is unique
response.set( millis() );
response.setDestination(msg.sender);
send(response);
void sendPingOrPongResponse( MyMessage msg )
{
MyMessage response = (msg.type == V_VAR1 ? mPong : mPing);
LOG(F("Sending %s to %s\n"), msgTypeAsCharRepresentation( (mysensor_data)response.type ),
nodeTypeAsCharRepresentation(msg.sender));
// Set payload to current time in millis to ensure each message is unique
response.set( millis() );
response.setDestination(msg.sender);
send(response);
}
void setNodeId(byte nodeID) {
LOG(F("Setting node id to: %i.\n***Please restart the node for changes to take effect.\n"), nodeID);
eeprom_write_byte((uint8_t*)EEPROM_NODE_ID_ADDRESS, (byte)nodeID);
void setNodeId(byte nodeID)
{
LOG(F("Setting node id to: %i.\n***Please restart the node for changes to take effect.\n"), nodeID);
eeprom_write_byte((uint8_t*)EEPROM_NODE_ID_ADDRESS, (byte)nodeID);
}
const char * msgTypeAsCharRepresentation( mysensor_data mType ) {
return mType == V_VAR1 ? "Ping" : "Pong";
const char * msgTypeAsCharRepresentation( mysensor_data mType )
{
return mType == V_VAR1 ? "Ping" : "Pong";
}
const char * nodeTypeAsCharRepresentation( uint8_t node ) {
return node == YING ? "Ying Node" : "Yang Node";
const char * nodeTypeAsCharRepresentation( uint8_t node )
{
return node == YING ? "Ying Node" : "Yang Node";
}