-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathlprintf.c
More file actions
83 lines (67 loc) · 1.31 KB
/
lprintf.c
File metadata and controls
83 lines (67 loc) · 1.31 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
#include <stdio.h>
#include <avr/io.h>
#include <util/delay.h>
#include <string.h>
#include <avr/pgmspace.h>
#include "lprintf.h"
#include "lib/i2c.h"
//LEDs on PB3 and PB4
#define STATUS_PORT PORTB
#define STATUS_LED1 3
#define STATUS_LED2 4
#define yellow_on() ( PORTB |= (1 << STATUS_LED1) )
#define red_on() ( PORTB |= (1 << STATUS_LED2) )
#define yellow_off() ( PORTB &= ~(1 << STATUS_LED1) )
#define red_off() ( PORTB &= ~(1 << STATUS_LED2) )
int lprintf(char *str, ...)
{
char lstr[301];
int chars;
va_list args;
va_start(args, str);
lstr[0] = 'F';
chars = vsnprintf(lstr+1, 300, str, args);
if(chars > 300)
{
va_end(args);
return 1;
} else {
uint8_t retVal = i2cMasterSendNI(0b00001110, chars+1, lstr);
if(retVal != I2C_OK)
{
yellow_on();
}
va_end(args);
return 0;
}
_delay_ms(100);
}
int lprintf_P(const char *str, ...)
{
char lstr[100];
uint8_t i2cSend[101];
int chars;
va_list args;
va_start(args, str);
chars = vsnprintf_P(lstr, 100, str, args);
if(chars > 100)
{
va_end(args);
return 1;
} else {
int i=0;
i2cSend[0] = 'F';
for(i=0; i <=chars; i++)
{
i2cSend[i+1] = (uint8_t)lstr[i];
}
uint8_t retVal = i2cMasterSendNI(0b00001110, chars+1, i2cSend);
if(retVal != I2C_OK)
{
yellow_on();
}
va_end(args);
return 0;
}
_delay_ms(100);
}