Fake input and bug fixes
* Press W in simulator to activate (pretty slow shit, do avoid unless compiling with optimisations) * Tiny improvement of the EEPROM simulation. * Fixed type typo for millis and micros
This commit is contained in:
parent
266b3334cb
commit
1be998153a
6 changed files with 58 additions and 45 deletions
|
@ -101,9 +101,9 @@ class Adafruit_MPR121 {
|
||||||
void setThreshholds(uint8_t touch, uint8_t release) __attribute__((deprecated));
|
void setThreshholds(uint8_t touch, uint8_t release) __attribute__((deprecated));
|
||||||
void setThresholds(uint8_t touch, uint8_t release);
|
void setThresholds(uint8_t touch, uint8_t release);
|
||||||
|
|
||||||
|
uint8_t _registers[48];
|
||||||
private:
|
private:
|
||||||
int8_t _i2caddr;
|
int8_t _i2caddr;
|
||||||
uint8_t _registers[24];
|
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // ADAFRUIT_MPR121_H
|
#endif // ADAFRUIT_MPR121_H
|
|
@ -73,8 +73,8 @@ extern SimSerial Serial;
|
||||||
|
|
||||||
//extern void putString(int row, int col, int color, const char* msg, const FONT_INFO fontInfo);
|
//extern void putString(int row, int col, int color, const char* msg, const FONT_INFO fontInfo);
|
||||||
|
|
||||||
uint16_t micros();
|
uint32_t micros();
|
||||||
uint16_t millis();
|
uint32_t millis();
|
||||||
void delay(uint32_t millis);
|
void delay(uint32_t millis);
|
||||||
void delayMicroseconds(uint32_t micros);
|
void delayMicroseconds(uint32_t micros);
|
||||||
|
|
||||||
|
|
|
@ -5,6 +5,7 @@
|
||||||
|
|
||||||
struct EEPROMClass
|
struct EEPROMClass
|
||||||
{
|
{
|
||||||
|
EEPROMClass();
|
||||||
//Basic user access methods.
|
//Basic user access methods.
|
||||||
// EERef operator[]( const int idx ) { return idx; }
|
// EERef operator[]( const int idx ) { return idx; }
|
||||||
uint8_t read( int idx ); // { return EERef( idx ); }
|
uint8_t read( int idx ); // { return EERef( idx ); }
|
||||||
|
@ -34,6 +35,10 @@ struct EEPROMClass
|
||||||
// #endif
|
// #endif
|
||||||
// return t;
|
// return t;
|
||||||
// }
|
// }
|
||||||
|
|
||||||
|
private:
|
||||||
|
char someFakeEEPROM_memory[4096];
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
static EEPROMClass EEPROM __attribute__ ((unused));
|
static EEPROMClass EEPROM __attribute__ ((unused));
|
||||||
|
|
|
@ -46,41 +46,6 @@ Adafruit_MPR121::Adafruit_MPR121() {
|
||||||
boolean Adafruit_MPR121::begin(uint8_t i2caddr) {
|
boolean Adafruit_MPR121::begin(uint8_t i2caddr) {
|
||||||
_i2caddr = i2caddr;
|
_i2caddr = i2caddr;
|
||||||
|
|
||||||
|
|
||||||
// writeRegister(MPR121_ECR, 0x0);
|
|
||||||
|
|
||||||
// uint8_t c = readRegister8(MPR121_CONFIG2);
|
|
||||||
|
|
||||||
// if (c != 0x24) return false;
|
|
||||||
|
|
||||||
|
|
||||||
// setThreshholds(12, 6);
|
|
||||||
// writeRegister(MPR121_MHDR, 0x01);
|
|
||||||
// writeRegister(MPR121_NHDR, 0x01);
|
|
||||||
// writeRegister(MPR121_NCLR, 0x0E);
|
|
||||||
// writeRegister(MPR121_FDLR, 0x00);
|
|
||||||
|
|
||||||
// writeRegister(MPR121_MHDF, 0x01);
|
|
||||||
// writeRegister(MPR121_NHDF, 0x05);
|
|
||||||
// writeRegister(MPR121_NCLF, 0x01);
|
|
||||||
// writeRegister(MPR121_FDLF, 0x00);
|
|
||||||
|
|
||||||
// writeRegister(MPR121_NHDT, 0x00);
|
|
||||||
// writeRegister(MPR121_NCLT, 0x00);
|
|
||||||
// writeRegister(MPR121_FDLT, 0x00);
|
|
||||||
|
|
||||||
// writeRegister(MPR121_DEBOUNCE, 0);
|
|
||||||
// writeRegister(MPR121_CONFIG1, 0x10); // default, 16uA charge current
|
|
||||||
// writeRegister(MPR121_CONFIG2, 0x20); // 0.5uS encoding, 1ms period
|
|
||||||
|
|
||||||
// // writeRegister(MPR121_AUTOCONFIG0, 0x8F);
|
|
||||||
|
|
||||||
// // writeRegister(MPR121_UPLIMIT, 150);
|
|
||||||
// // writeRegister(MPR121_TARGETLIMIT, 100); // should be ~400 (100 shifted)
|
|
||||||
// // writeRegister(MPR121_LOWLIMIT, 50);
|
|
||||||
// // enable all electrodes
|
|
||||||
// writeRegister(MPR121_ECR, 0x8F); // start with first 5 bits of baseline tracking
|
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -213,3 +178,9 @@ void Adafruit_MPR121::writeRegister(uint8_t reg, uint8_t value) {
|
||||||
// Wire.write((uint8_t)(value));
|
// Wire.write((uint8_t)(value));
|
||||||
// Wire.endTransmission();
|
// Wire.endTransmission();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
Simulator specifics code..
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
|
@ -4,6 +4,7 @@
|
||||||
|
|
||||||
#include <Adafruit_MPR121.h>
|
#include <Adafruit_MPR121.h>
|
||||||
#include <Adafruit_SSD1306.h>
|
#include <Adafruit_SSD1306.h>
|
||||||
|
#include <cmath>
|
||||||
#include "globals.h"
|
#include "globals.h"
|
||||||
#include "hardware.h"
|
#include "hardware.h"
|
||||||
|
|
||||||
|
@ -23,7 +24,7 @@ SimWire Wire;
|
||||||
SimSerial Serial;
|
SimSerial Serial;
|
||||||
|
|
||||||
|
|
||||||
static const int scale = 2;
|
static const int scale = 4;
|
||||||
|
|
||||||
static SDL_Window *window;
|
static SDL_Window *window;
|
||||||
static SDL_Surface *surface;
|
static SDL_Surface *surface;
|
||||||
|
@ -77,7 +78,6 @@ void delay(unsigned int ms)
|
||||||
|
|
||||||
void pinMode(uint8_t __attribute((unused)) pin, uint8_t __attribute((unused)) mode)
|
void pinMode(uint8_t __attribute((unused)) pin, uint8_t __attribute((unused)) mode)
|
||||||
{
|
{
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
int analogRead(uint8_t pin)
|
int analogRead(uint8_t pin)
|
||||||
|
@ -108,12 +108,35 @@ void analogWrite(uint8_t pin, int value)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
uint16_t micros()
|
bool animateAnalogs = false;
|
||||||
|
void analogUpdate(uint32_t time) {
|
||||||
|
|
||||||
|
const uint16_t touchMaxValue = 1023;
|
||||||
|
const uint16_t analogMax = 4095;
|
||||||
|
|
||||||
|
if(animateAnalogs) {
|
||||||
|
for( int i = 0 ; i < 32; ++i) {
|
||||||
|
analogInputs[i] = (sin(time*0.001f + i)*0.5f + 0.5f) * analogMax;
|
||||||
|
}
|
||||||
|
|
||||||
|
uint8_t *regs = touchSensor._registers;
|
||||||
|
|
||||||
|
for(int r = 4; r < (4+24); r += 2) {
|
||||||
|
uint16_t value = (sin(time * 0.005f + r)*0.5f + 0.5f) * touchMaxValue;
|
||||||
|
regs[r] = value & 0xffu;
|
||||||
|
regs[r+1] = (value >> 8) & 0x03u;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
uint32_t micros()
|
||||||
{
|
{
|
||||||
return SDL_GetTicks()*1000;
|
return SDL_GetTicks()*1000;
|
||||||
}
|
}
|
||||||
|
|
||||||
uint16_t millis()
|
uint32_t millis()
|
||||||
{
|
{
|
||||||
return SDL_GetTicks();
|
return SDL_GetTicks();
|
||||||
}
|
}
|
||||||
|
@ -156,6 +179,10 @@ static void GetDisplay(SDL_Surface* dest)
|
||||||
SDL_UnlockSurface(dest);
|
SDL_UnlockSurface(dest);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void toggleAnalogAnimation() {
|
||||||
|
animateAnalogs = !animateAnalogs;
|
||||||
|
printf("Analog input variations: %s\n", animateAnalogs ? "ON": "OFF");
|
||||||
|
}
|
||||||
|
|
||||||
static int doQuit = 0;
|
static int doQuit = 0;
|
||||||
|
|
||||||
|
@ -187,6 +214,7 @@ static void SimLoop(std::function<bool()> continue_predicate, std::function<void
|
||||||
case SDLK_RIGHT: digitalInputs[ePin] = 1; break;
|
case SDLK_RIGHT: digitalInputs[ePin] = 1; break;
|
||||||
case SDLK_UP: digitalInputs[uPin] = 1; break;
|
case SDLK_UP: digitalInputs[uPin] = 1; break;
|
||||||
case SDLK_DOWN: digitalInputs[dPin] = 1; break;
|
case SDLK_DOWN: digitalInputs[dPin] = 1; break;
|
||||||
|
case SDLK_w: toggleAnalogAnimation(); break;
|
||||||
}
|
}
|
||||||
fflush(stdout);
|
fflush(stdout);
|
||||||
}
|
}
|
||||||
|
@ -195,9 +223,12 @@ static void SimLoop(std::function<bool()> continue_predicate, std::function<void
|
||||||
if(doQuit)
|
if(doQuit)
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
time = SDL_GetTicks();
|
||||||
|
|
||||||
|
|
||||||
if(loopFunc) loopFunc();
|
if(loopFunc) loopFunc();
|
||||||
|
|
||||||
time = SDL_GetTicks();
|
analogUpdate(time);
|
||||||
|
|
||||||
// TODO: Get buffer from SSD1306 and copy to surface...
|
// TODO: Get buffer from SSD1306 and copy to surface...
|
||||||
|
|
||||||
|
|
|
@ -1,26 +1,32 @@
|
||||||
|
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <memory.h>
|
||||||
#include "EEPROM.h"
|
#include "EEPROM.h"
|
||||||
|
|
||||||
// TODO: Fake eeprom a bit better, maybe even save to file.
|
// TODO: Fake eeprom a bit better, maybe even save to file.
|
||||||
|
|
||||||
static char someFakeEEPROM_memory[4096];
|
EEPROMClass::EEPROMClass() {
|
||||||
|
memset(someFakeEEPROM_memory, 0xff, sizeof(someFakeEEPROM_memory));
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
uint8_t EEPROMClass::read( int idx )
|
uint8_t EEPROMClass::read( int idx )
|
||||||
{
|
{
|
||||||
|
printf("Reading EEPROM address %d: %d\n", idx, someFakeEEPROM_memory[idx]);
|
||||||
return someFakeEEPROM_memory[idx];
|
return someFakeEEPROM_memory[idx];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void EEPROMClass::write( int idx, uint8_t val )
|
void EEPROMClass::write( int idx, uint8_t val )
|
||||||
{
|
{
|
||||||
|
printf("Writing to EEPROM address %d = %d\n", idx, val);
|
||||||
someFakeEEPROM_memory[idx] = val;
|
someFakeEEPROM_memory[idx] = val;
|
||||||
}
|
}
|
||||||
|
|
||||||
void EEPROMClass::update( int idx, uint8_t val )
|
void EEPROMClass::update( int idx, uint8_t val )
|
||||||
{
|
{
|
||||||
someFakeEEPROM_memory[idx] = val;
|
write(idx, val);
|
||||||
}
|
}
|
||||||
uint16_t EEPROMClass::length()
|
uint16_t EEPROMClass::length()
|
||||||
{
|
{
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue