25 #include "LRFHardware.h"
26 #include "LRFSpeech.h"
28 #include "LRFSensors.h"
29 #include "LRFEvents.h"
30 #include "LRFInfrared.h"
32 #include "LRFExpressions.h"
33 #include "LRFPersonality.h"
34 #include "LRFMemory.h"
38 const char debug_title[] =
"lrf";
43 #pragma mark - Move these eventually?
46 void lrf_print_hardware_version(
void)
48 unsigned char major = lrf_memory_read(LRF_MEMORY_HARDWARE_VERSION_MAJOR_ADDR);
49 unsigned char minor = lrf_memory_read(LRF_MEMORY_HARDWARE_VERSION_MINOR_ADDR);
50 lrf_debug_tag(debug_title,
"hw:",
false);
51 lrf_debug_pair(major, minor);
54 void lrf_print_firmware_version(
void)
56 unsigned char major = lrf_memory_read(LRF_MEMORY_FIRMWARE_VERSION_MAJOR_ADDR);
57 unsigned char minor = lrf_memory_read(LRF_MEMORY_FIRMWARE_VERSION_MINOR_ADDR);
58 lrf_debug_tag(debug_title,
"fw:",
false);
59 lrf_debug_pair(major, minor);
62 void lrf_reset_test_memories(
void)
64 lrf_memory_write(LRF_MEMORY_HARDWARE_TEST_ADDR, 0);
65 lrf_memory_write(LRF_MEMORY_HAS_READ_SHOELACES_ADDR, 0);
68 void lrf_implant_memories(
bool isHoliday)
73 lrf_memory_write(LRF_MEMORY_HARDWARE_VERSION_MAJOR_ADDR, 0x01);
74 lrf_memory_write(LRF_MEMORY_HARDWARE_VERSION_MINOR_ADDR, 0x00);
78 lrf_memory_write(LRF_MEMORY_HARDWARE_VERSION_MAJOR_ADDR, 0x01);
79 lrf_memory_write(LRF_MEMORY_HARDWARE_VERSION_MINOR_ADDR, 0x01);
83 lrf_memory_write(LRF_MEMORY_FIRMWARE_VERSION_MAJOR_ADDR, LRF_FIRMWARE_MAJOR);
84 lrf_memory_write(LRF_MEMORY_FIRMWARE_VERSION_MINOR_ADDR, LRF_FIRMWARE_MINOR);
87 lrf_memory_write(LRF_MEMORY_HARDWARE_TEST_ADDR, LRF_MEMORY_HARDWARE_TEST_VALUE);
90 lrf_memory_write(LRF_MEMORY_HAS_READ_SHOELACES_ADDR, LRF_MEMORY_HAS_READ_SHOELACES_VALUE);
93 lrf_memory_write(LRF_MEMORY_PERSONALITY_START_ADDR, LRF_PERSONALITY_LEVEL_NORMAL);
94 lrf_memory_write(LRF_MEMORY_PERSONALITY_START_ADDR+1, LRF_PERSONALITY_LEVEL_NORMAL);
95 lrf_memory_write(LRF_MEMORY_PERSONALITY_START_ADDR+2, LRF_PERSONALITY_LEVEL_NORMAL);
96 lrf_memory_write(LRF_MEMORY_PERSONALITY_START_ADDR+3, LRF_PERSONALITY_LEVEL_NORMAL);
97 lrf_memory_write(LRF_MEMORY_PERSONALITY_START_ADDR+4, LRF_PERSONALITY_LEVEL_NORMAL);
98 lrf_memory_write(LRF_MEMORY_PERSONALITY_START_ADDR+5, LRF_PERSONALITY_LEVEL_NORMAL);
101 lrf_memory_write(LRF_MEMORY_SIGNATURE_ADDR, 1);
105 #pragma mark - Setup & Loop
114 lrf_hardware_setup();
117 unsigned int holiday = (lrf_memory_read(0x08) << 8) | lrf_memory_read(0x09);
118 if(holiday == 0xffff)
120 lrf_debug_tag(debug_title,
"holiday");
121 lrf_implant_memories(
true);
125 unsigned char major = lrf_memory_read(LRF_MEMORY_FIRMWARE_VERSION_MAJOR_ADDR);
126 unsigned char minor = lrf_memory_read(LRF_MEMORY_FIRMWARE_VERSION_MINOR_ADDR);
127 if(major != LRF_FIRMWARE_MAJOR || minor != LRF_FIRMWARE_MINOR)
129 lrf_memory_write(LRF_MEMORY_FIRMWARE_VERSION_MAJOR_ADDR, LRF_FIRMWARE_MAJOR);
130 lrf_memory_write(LRF_MEMORY_FIRMWARE_VERSION_MINOR_ADDR, LRF_FIRMWARE_MINOR);
134 lrf_print_hardware_version();
135 lrf_print_firmware_version();
139 if(LRF_FORCE_HARDWARE_TEST || (lrf_memory_read(LRF_MEMORY_HARDWARE_TEST_ADDR) != LRF_MEMORY_HARDWARE_TEST_VALUE))
141 #if LRF_ADVANCED_HARDWARE_TEST
142 lrf_hardware_test_advanced();
153 lrf_personality_setup();
154 lrf_expressions_setup();
167 #if LRF_DEBUG_CONSOLE_ENABLED
178 lrf_sensors_process();
181 lrf_events_process();
184 lrf_expressions_process();
195 #pragma mark - Expressing
200 lrf_eyes_play_pattern_and_block(pattern,
false);
205 lrf_eyes_play_pattern_duration_and_block(pattern,duration,
false);
210 lrf_speech_play_sound_and_block(sound,
false);
215 lrf_expressions_load_pattern_and_sounds_and_block(pattern, &sound, 1);
220 lrf_expressions_load_pattern_and_sounds_and_block(pattern, sounds, soundCount);
224 #pragma mark - Events
229 lrfEventHandlers[event] = handler;
233 #pragma mark - Infrared
238 return lrfIrda.message;
243 lrf_irda_write_message(message);
247 #pragma mark - Sensors
253 lrf_touch_read(&value);
260 lrf_light_read(&value);
267 lrf_mic_read(&value);
272 #pragma mark - Outputs
277 lrfEyes.currentLeft.red = (red < LRF_RGB_VALUE_MAX) ? red : LRF_RGB_VALUE_MAX;
278 lrfEyes.currentLeft.green = (green < LRF_RGB_VALUE_MAX) ? green : LRF_RGB_VALUE_MAX;
279 lrfEyes.currentLeft.blue = (blue < LRF_RGB_VALUE_MAX) ? blue : LRF_RGB_VALUE_MAX;
280 if(update) lrf_eyes_update();
285 lrfEyes.currentRight.red = (red < LRF_RGB_VALUE_MAX) ? red : LRF_RGB_VALUE_MAX;
286 lrfEyes.currentRight.green = (green < LRF_RGB_VALUE_MAX) ? green : LRF_RGB_VALUE_MAX;
287 lrfEyes.currentRight.blue = (blue < LRF_RGB_VALUE_MAX) ? blue : LRF_RGB_VALUE_MAX;
288 if(update) lrf_eyes_update();
295 if(update) lrf_eyes_update();
298 void LittleRobotFriend::setSpeaker(
unsigned int frequency,
unsigned int duration)
301 lrf_speaker_set_frequency(frequency);
307 #pragma mark - System
312 lrfEvents.boredTimeoutReload = timeout * 1000;
313 lrfEvents.boredCountReload = count;
unsigned char readLight(void)
Read the light sensor.
unsigned char readTouch(void)
Read the touch sensor.
void setBoredom(unsigned int timeout, unsigned char count)
Set how quickly and how often your robot gets bored.
void loop(void)
run the LRF library loop
Allows for access of sound data as a structure or raw integer.
void sleep(void)
Put the robot to sleep.
void setRightLED(unsigned char red, unsigned char green, unsigned char blue, bool update=true)
Set the RGB value of one or both LEDs.
The main class of the Little Robot Friends API.
LRFEvent
Constants for different interaction and system events.
void blink(LRFPattern pattern)
Blink a light pattern on the LED eyes.
This is the core API class for access LRF library functions.
void setBothLEDs(unsigned char red, unsigned char green, unsigned char blue, bool update=true)
Set the RGB value of one or both LEDs.
void setLeftLED(unsigned char red, unsigned char green, unsigned char blue, bool update=true)
Set the RGB value of one or both LEDs.
void sendIRMessage(LRFIRMessage message)
Send an IR message.
void say(LRFSound sound)
Speak a single sound.
LRFIRMessage readIRMessage(void)
Read the latest received IR message.
void(* LRFEventHandler)(void)
Function pointer with no parameters and no return value.
Just powered on (batteries in)
unsigned char readMicrophone(void)
Read the microphone.
void setup(void)
setup the LRF library
void blinkAndSay(LRFPattern pattern, LRFSound sound)
Blink and speak at the same time.
Allows for access of pattern data as a structure or raw integer.
void setEventHandler(LRFEvent event, LRFEventHandler handler)
Customize how your robot responds to particular events.