Skip to content

Commit c1da2bc

Browse files
authored
eliminate compile errors on numerous platforms (#76)
* eliminate compile errors on numerous platforms * integrate note-c fixes * reformat
1 parent 3ecfb4b commit c1da2bc

File tree

10 files changed

+163
-155
lines changed

10 files changed

+163
-155
lines changed

src/NoteI2c.hpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,9 @@
44
#include <stddef.h>
55
#include <stdint.h>
66

7-
class NoteI2c {
8-
public:
7+
class NoteI2c
8+
{
9+
public:
910
/**************************************************************************/
1011
/*!
1112
@brief Type used to abstract specific hardware implementation types.

src/NoteI2c_Arduino.cpp

Lines changed: 18 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,8 @@ NoteI2c_Arduino::receive (
3636
uint8_t * buffer_,
3737
uint16_t requested_byte_count_,
3838
uint32_t * available_
39-
) {
39+
)
40+
{
4041
const char *result = nullptr;
4142
uint8_t transmission_error = 0;
4243

@@ -53,22 +54,22 @@ NoteI2c_Arduino::receive (
5354
}
5455

5556
switch (transmission_error) {
56-
case 1:
57+
case 1:
5758
result = ERRSTR("i2c: data too long to fit in transmit buffer {io}",i2cerr);
5859
break;
59-
case 2:
60+
case 2:
6061
result = ERRSTR("i2c: received NACK on transmit of address {io}",i2cerr);
6162
break;
62-
case 3:
63+
case 3:
6364
result = ERRSTR("i2c: received NACK on transmit of data {io}",i2cerr);
6465
break;
65-
case 4:
66+
case 4:
6667
result = ERRSTR("i2c: unknown error on TwoWire::endTransmission() {io}",i2cerr);
6768
break;
68-
case 5:
69+
case 5:
6970
result = ERRSTR("i2c: timeout {io}",i2cerr);
7071
break;
71-
default:
72+
default:
7273
result = ERRSTR("i2c: unknown error encounter during I2C transmission {io}",i2cerr);
7374
}
7475
}
@@ -102,7 +103,8 @@ NoteI2c_Arduino::receive (
102103
bool
103104
NoteI2c_Arduino::reset (
104105
uint16_t device_address_
105-
) {
106+
)
107+
{
106108
(void)device_address_;
107109
#if WIRE_HAS_END
108110
_i2cPort.end();
@@ -116,7 +118,8 @@ NoteI2c_Arduino::transmit (
116118
uint16_t device_address_,
117119
uint8_t * buffer_,
118120
uint16_t size_
119-
) {
121+
)
122+
{
120123
const char * result = nullptr;
121124
uint8_t transmission_error = 0;
122125

@@ -127,22 +130,22 @@ NoteI2c_Arduino::transmit (
127130

128131
if (transmission_error) {
129132
switch (transmission_error) {
130-
case 1:
133+
case 1:
131134
result = ERRSTR("i2c: data too long to fit in transmit buffer {io}",i2cerr);
132135
break;
133-
case 2:
136+
case 2:
134137
result = ERRSTR("i2c: received NACK on transmit of address {io}",i2cerr);
135138
break;
136-
case 3:
139+
case 3:
137140
result = ERRSTR("i2c: received NACK on transmit of data {io}",i2cerr);
138141
break;
139-
case 4:
142+
case 4:
140143
result = ERRSTR("i2c: unknown error on TwoWire::endTransmission() {io}",i2cerr);
141144
break;
142-
case 5:
145+
case 5:
143146
result = ERRSTR("i2c: timeout {io}",i2cerr);
144147
break;
145-
default:
148+
default:
146149
result = ERRSTR("i2c: unknown error encounter during I2C transmission {io}",i2cerr);
147150
}
148151
}

src/NoteI2c_Arduino.hpp

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,20 +6,21 @@
66
#include "Notecard.h"
77

88
#ifndef NOTE_MOCK
9-
#include <Wire.h>
9+
#include <Wire.h>
1010
#else
11-
#include "mock/mock-arduino.hpp"
12-
#include "mock/mock-parameters.hpp"
11+
#include "mock/mock-arduino.hpp"
12+
#include "mock/mock-parameters.hpp"
1313
#endif
1414

15-
class NoteI2c_Arduino final : public NoteI2c {
16-
public:
15+
class NoteI2c_Arduino final : public NoteI2c
16+
{
17+
public:
1718
NoteI2c_Arduino(TwoWire & i2c_bus);
1819
const char * receive(uint16_t device_address, uint8_t * buffer, uint16_t requested_byte_count, uint32_t * available) override;
1920
bool reset(uint16_t device_address) override;
2021
const char * transmit(uint16_t device_address, uint8_t * buffer, uint16_t size) override;
2122

22-
private:
23+
private:
2324
TwoWire & _i2cPort;
2425
};
2526

src/NoteLog.hpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,8 @@
33

44
#include <stddef.h>
55

6-
class NoteLog {
6+
class NoteLog
7+
{
78
public:
89
/**************************************************************************/
910
/*!

src/NoteLog_Arduino.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ make_note_log (
1212
note_log = nullptr;
1313
}
1414
} else if (!note_log) {
15-
note_log = new NoteLog_Arduino(reinterpret_cast<Stream *>(log_channel_));
15+
note_log = new NoteLog_Arduino(reinterpret_cast<Stream *>(log_channel_));
1616
}
1717
return note_log;
1818
}

src/Notecard.cpp

Lines changed: 95 additions & 93 deletions
Original file line numberDiff line numberDiff line change
@@ -48,117 +48,119 @@
4848

4949
namespace
5050
{
51-
NoteI2c *noteI2c(nullptr);
51+
NoteI2c *noteI2c(nullptr);
5252

53-
const char *noteI2cReceive(uint16_t device_address_, uint8_t *buffer_, uint16_t size_, uint32_t *available_)
54-
{
55-
const char *result;
56-
if (noteI2c)
57-
{
58-
result = noteI2c->receive(device_address_, buffer_, size_, available_);
59-
}
60-
else
61-
{
62-
result = "i2c: A call to Notecard::begin() is required. {io}";
63-
}
64-
return result;
53+
const char *noteI2cReceive(uint16_t device_address_, uint8_t *buffer_, uint16_t size_, uint32_t *available_)
54+
{
55+
const char *result;
56+
if (noteI2c) {
57+
result = noteI2c->receive(device_address_, buffer_, size_, available_);
58+
} else {
59+
result = "i2c: A call to Notecard::begin() is required. {io}";
6560
}
61+
return result;
62+
}
6663

67-
bool noteI2cReset(uint16_t device_address_)
68-
{
69-
bool result;
70-
if (noteI2c)
71-
{
72-
result = noteI2c->reset(device_address_);
73-
}
74-
else
75-
{
76-
result = false;
77-
}
78-
return result;
64+
bool noteI2cReset(uint16_t device_address_)
65+
{
66+
bool result;
67+
if (noteI2c) {
68+
result = noteI2c->reset(device_address_);
69+
} else {
70+
result = false;
7971
}
72+
return result;
73+
}
8074

81-
const char *noteI2cTransmit(uint16_t device_address_, uint8_t *buffer_, uint16_t size_)
82-
{
83-
const char *result;
84-
if (noteI2c)
85-
{
86-
result = noteI2c->transmit(device_address_, buffer_, size_);
87-
}
88-
else
89-
{
90-
result = "i2c: A call to Notecard::begin() is required. {io}";
91-
}
92-
return result;
75+
const char *noteI2cTransmit(uint16_t device_address_, uint8_t *buffer_, uint16_t size_)
76+
{
77+
const char *result;
78+
if (noteI2c) {
79+
result = noteI2c->transmit(device_address_, buffer_, size_);
80+
} else {
81+
result = "i2c: A call to Notecard::begin() is required. {io}";
9382
}
83+
return result;
84+
}
9485

95-
NoteLog *noteLog(nullptr);
86+
NoteLog *noteLog(nullptr);
9687

97-
size_t noteLogPrint(const char * message_)
98-
{
99-
size_t result;
100-
if (noteLog)
101-
{
102-
result = noteLog->print(message_);
103-
}
104-
else
105-
{
106-
result = 0;
107-
}
108-
return result;
88+
size_t noteLogPrint(const char * message_)
89+
{
90+
size_t result;
91+
if (noteLog) {
92+
result = noteLog->print(message_);
93+
} else {
94+
result = 0;
10995
}
96+
return result;
97+
}
11098

111-
NoteSerial *noteSerial(nullptr);
99+
NoteSerial *noteSerial(nullptr);
112100

113-
bool noteSerialAvailable(void)
114-
{
115-
bool result;
116-
if (noteSerial)
117-
{
118-
result = noteSerial->available();
119-
}
120-
else
121-
{
122-
result = false;
123-
}
124-
return result;
101+
bool noteSerialAvailable(void)
102+
{
103+
bool result;
104+
if (noteSerial) {
105+
result = noteSerial->available();
106+
} else {
107+
result = false;
125108
}
109+
return result;
110+
}
126111

127-
char noteSerialReceive(void)
128-
{
129-
char result;
130-
if (noteSerial)
131-
{
132-
result = noteSerial->receive();
133-
}
134-
else
135-
{
136-
result = '\0';
137-
}
138-
return result;
112+
char noteSerialReceive(void)
113+
{
114+
char result;
115+
if (noteSerial) {
116+
result = noteSerial->receive();
117+
} else {
118+
result = '\0';
139119
}
120+
return result;
121+
}
122+
123+
bool noteSerialReset(void)
124+
{
125+
bool result;
126+
if (noteSerial) {
127+
result = noteSerial->reset();
128+
} else {
129+
result = false;
130+
}
131+
return result;
132+
}
140133

141-
bool noteSerialReset(void)
134+
void noteSerialTransmit(uint8_t *text_, size_t len_, bool flush_)
135+
{
136+
if (noteSerial) {
137+
noteSerial->transmit(text_, len_, flush_);
138+
}
139+
}
140+
}
141+
142+
143+
/***************************************************************************
144+
PRIVATE FUNCTIONS
145+
***************************************************************************/
146+
147+
/* These functions are necessary because some platforms define types
148+
for delay and millis differently */
149+
150+
extern "C" {
151+
152+
static uint32_t platform_millis(void);
153+
static uint32_t platform_millis(void)
142154
{
143-
bool result;
144-
if (noteSerial)
145-
{
146-
result = noteSerial->reset();
147-
}
148-
else
149-
{
150-
result = false;
151-
}
152-
return result;
155+
return (uint32_t) millis();
153156
}
154157

155-
void noteSerialTransmit(uint8_t *text_, size_t len_, bool flush_)
158+
static void platform_delay(uint32_t ms);
159+
static void platform_delay(uint32_t ms)
156160
{
157-
if (noteSerial)
158-
{
159-
noteSerial->transmit(text_, len_, flush_);
160-
}
161+
delay((unsigned long int) ms);
161162
}
163+
162164
}
163165

164166
/***************************************************************************
@@ -191,7 +193,7 @@ Notecard::~Notecard (void)
191193
void Notecard::begin(uint32_t i2caddress, uint32_t i2cmax, TwoWire &wirePort)
192194
{
193195
NoteSetUserAgent((char *)"note-arduino");
194-
NoteSetFnDefault(malloc, free, delay, millis);
196+
NoteSetFnDefault(malloc, free, platform_delay, platform_millis);
195197
noteI2c = make_note_i2c(&wirePort);
196198

197199
NoteSetFnI2C(i2caddress, i2cmax, noteI2cReset,
@@ -213,7 +215,7 @@ void Notecard::begin(uint32_t i2caddress, uint32_t i2cmax, TwoWire &wirePort)
213215
void Notecard::begin(HardwareSerial &selectedSerialPort, int selectedSpeed)
214216
{
215217
NoteSetUserAgent((char *)"note-arduino");
216-
NoteSetFnDefault(malloc, free, delay, millis);
218+
NoteSetFnDefault(malloc, free, platform_delay, platform_millis);
217219
noteSerial = make_note_serial(&selectedSerialPort, selectedSpeed);
218220

219221
NoteSetFnSerial(noteSerialReset, noteSerialTransmit,

src/note-c/n_cjson_helpers.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ bool JBoolValue(J *item)
106106
char *JStringValue(J *item)
107107
{
108108
if (item == NULL) {
109-
return "";
109+
return (char *)"";
110110
}
111111
return item->valuestring;
112112
}

0 commit comments

Comments
 (0)