Enhance AI
This commit is contained in:
parent
26a0fd884f
commit
26e48fd997
6 changed files with 208 additions and 69 deletions
|
|
@ -38,6 +38,13 @@ void setDisplayContrast(uint8_t value) {
|
|||
dataMode();
|
||||
}
|
||||
|
||||
void turnDisplayOnOff(bool shouldBeOn) {
|
||||
commandMode();
|
||||
sendByteOnSPI(0x8D | shouldBeOn); // set charge pump on/off
|
||||
sendByteOnSPI(0x10 | shouldBeOn << 2); // set charge pump on/off
|
||||
sendByteOnSPI(0xAE | shouldBeOn); // turn display sleep on/off
|
||||
}
|
||||
|
||||
void initializeDisplay(DrawFunction drawEverything) {
|
||||
setOutputPin(DISPLAY_RESET_OUTPUT_PIN, false);
|
||||
for (volatile uint8_t i = 0; i != 255; i++)
|
||||
|
|
|
|||
|
|
@ -21,6 +21,8 @@ typedef void (*DrawFunction)(Rectangle);
|
|||
void initializeDisplay(DrawFunction drawEverything);
|
||||
void setDisplayContrast(uint8_t value);
|
||||
|
||||
void turnDisplayOnOff(bool shouldBeOn);
|
||||
|
||||
void startIntersectionTest();
|
||||
bool endIntersectionTest();
|
||||
|
||||
|
|
|
|||
|
|
@ -28,6 +28,7 @@ static struct {
|
|||
ProtocolState protocolState;
|
||||
CommandState commandState;
|
||||
OnCommandReceived onCommandReceived;
|
||||
OnReceiveStarted onReceiveStarted;
|
||||
} infra;
|
||||
|
||||
|
||||
|
|
@ -81,6 +82,8 @@ static inline uint8_t isIrOn() {
|
|||
}
|
||||
|
||||
ISR(PCINT0_vect) {
|
||||
infra.onReceiveStarted();
|
||||
|
||||
switch (infra.protocolState) {
|
||||
case idle:
|
||||
if (isIrOn()) {
|
||||
|
|
@ -136,9 +139,10 @@ ISR(TIM0_COMPB_vect) {
|
|||
}
|
||||
}
|
||||
|
||||
void initializeInfra(OnCommandReceived onCommandReceived) {
|
||||
void initializeInfra(OnCommandReceived onCommandReceived, OnReceiveStarted onReceiveStarted) {
|
||||
setBit(PORTB, IR_PIN); // enable pull-up
|
||||
setBit(PCMSK, IR_PIN); // specific pin change interrupt enable
|
||||
setBit(GIMSK, PCIE); // global on pin change interrupt enable;
|
||||
infra.onCommandReceived = onCommandReceived;
|
||||
infra.onReceiveStarted = onReceiveStarted;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -10,7 +10,8 @@
|
|||
#define REPEAT_CODE 1
|
||||
|
||||
typedef void (*OnCommandReceived)(uint8_t);
|
||||
typedef void (*OnReceiveStarted)();
|
||||
|
||||
void initializeInfra(OnCommandReceived onCommandReceived);
|
||||
void initializeInfra(OnCommandReceived onCommandReceived, OnReceiveStarted onReceiveStarted);
|
||||
|
||||
#endif
|
||||
|
|
|
|||
|
|
@ -20,6 +20,7 @@ void startFrameLoop(FrameFunction function, uint8_t frameLengthInMilliseconds) {
|
|||
previousFrameTime = milisecondsSinceFrameStart;
|
||||
|
||||
while (milisecondsSinceFrameStart < frameLengthInMilliseconds) {
|
||||
clearBit(MCUCR, SM1); // idle mode
|
||||
sleep_cpu();
|
||||
}
|
||||
|
||||
|
|
@ -27,6 +28,10 @@ void startFrameLoop(FrameFunction function, uint8_t frameLengthInMilliseconds) {
|
|||
}
|
||||
}
|
||||
|
||||
void powerOff() {
|
||||
setBit(MCUCR, SM1); // power-down mode
|
||||
sleep_cpu();
|
||||
}
|
||||
|
||||
ISR(TIM0_COMPA_vect) {
|
||||
milisecondsSinceFrameStart++;
|
||||
|
|
|
|||
|
|
@ -10,4 +10,6 @@ typedef bool (*FrameFunction)(uint8_t);
|
|||
// frameFunction gets previousFrameTime (in milliseconds) as argument
|
||||
void startFrameLoop(FrameFunction function, uint8_t frameLengthInMilliseconds);
|
||||
|
||||
void powerOff();
|
||||
|
||||
#endif
|
||||
|
|
|
|||
Loading…
Reference in a new issue