const char PSTR_ERROR[] PROGMEM = "ERROR";
const char PSTR_Done[] PROGMEM = "Done";
+uint8_t hardwareVersion = 0;
+
extern "C" {
void __cxa_pure_virtual () {}
int __cxa_guard_acquire(uint8_t *g) { return 0; }
Cc1101 cc1101Receive(Cc1101::Receive);
}
+uint8_t detectHardwareVersion () {
+ ADMUX = (1 << ADLAR) | (1 << REFS0) | 7; // ADC7, VREF=AVCC=3.3V
+ ADCSRA = (1 << ADEN) | 7; // ADC Enable, Prescaler 128
+ ADCSRA |= (1 << ADSC); // start ADC
+ while (ADCSRA & (1 << ADSC)) {} // wait for result
+ hardwareVersion = 0; // unknown board version
+ // printf("Hardware-Version: ADC7H = %d\n", ADCH);
+ if (ADCH >= 0xf0) {
+ hardwareVersion = 1;
+ } else if (ADCH >= 0xe0) {
+ hardwareVersion = 2;
+ } else {
+ printf("Invalid Hardware-Version: ADC7H = %d\n", ADCH);
+ }
+ ADMUX = 0;
+ ADCSRA = 0;
+ return hardwareVersion;
+}
+
void setTimer (uint32_t ms) {
ATOMIC_BLOCK(ATOMIC_FORCEON) {
timer1ms = ms;
};
#endif
+ detectHardwareVersion();
+
while (1) {
uint16_t i;
char s[4];
printf_P(MAIN_CPP_DATE); printf_P(PSTR(" / "));
printf_P(MAIN_CPP_TIME);
printf_P(PSTR_DIVIDER);
+ if (hardwareVersion >= 1 && hardwareVersion <= 2) {
+ printf_P(PSTR("Hardware: %d"), hardwareVersion);
+ } else {
+ printf_P(PSTR("ERROR: Invalid Hardware (%d)"), hardwareVersion);
+ for(;;);
+ }
+ printf_P(PSTR_DIVIDER);
printf_P(PSTR_LINEFEED);
printf_P(PSTR("Available units:\n\n"));
for (i = 0; i < sizeof(unit) / sizeof(unit[0]); i++) {