This is a code which generates the various zoomed versions of an image stored in an SD card and displays it on a Nokia LCD based on the keys pressed on a capacitive touch pad.
Dependencies: FatFileSystem mbed
Fork of Lab3 by
main.cpp@1:6048138606a0, 2012-10-11 (annotated)
- Committer:
- abarve9
- Date:
- Thu Oct 11 06:10:31 2012 +0000
- Revision:
- 1:6048138606a0
- Parent:
- 0:c546b51ecf0b
This is an image zooming program which reads an image stored in an SD card and displays the various zoomed versions of the image based on the key pressed in the capacitive touch sensor.
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
XkLi | 0:c546b51ecf0b | 1 | #include "mbed.h" |
XkLi | 0:c546b51ecf0b | 2 | #include "SDFileSystem.h" |
XkLi | 0:c546b51ecf0b | 3 | #include "NokiaLCD.h" |
XkLi | 0:c546b51ecf0b | 4 | #include "myBMP.h" |
XkLi | 0:c546b51ecf0b | 5 | #include "mpr121.h" |
XkLi | 0:c546b51ecf0b | 6 | #include <string> |
abarve9 | 1:6048138606a0 | 7 | #include <vector> |
XkLi | 0:c546b51ecf0b | 8 | #include <cctype> |
XkLi | 0:c546b51ecf0b | 9 | |
XkLi | 0:c546b51ecf0b | 10 | SDFileSystem sd(p5, p6, p7, p8, "sd"); |
XkLi | 0:c546b51ecf0b | 11 | NokiaLCD lcd(p11, p13, p14, p15, NokiaLCD::LCD6610); |
XkLi | 0:c546b51ecf0b | 12 | I2C i2c(p9,p10); |
abarve9 | 1:6048138606a0 | 13 | Mpr121 touch(&i2c, Mpr121::ADD_VSS); |
XkLi | 0:c546b51ecf0b | 14 | Serial pc(USBTX,USBRX); |
abarve9 | 1:6048138606a0 | 15 | InterruptIn interrupt(p26); |
abarve9 | 1:6048138606a0 | 16 | DigitalOut led1(LED1); |
abarve9 | 1:6048138606a0 | 17 | vector<string> f; |
XkLi | 0:c546b51ecf0b | 18 | string file; |
XkLi | 0:c546b51ecf0b | 19 | int value; |
abarve9 | 1:6048138606a0 | 20 | bool zoom= false; |
abarve9 | 1:6048138606a0 | 21 | bool select_pic[12]; |
XkLi | 0:c546b51ecf0b | 22 | |
abarve9 | 1:6048138606a0 | 23 | void fallInterrupt() |
abarve9 | 1:6048138606a0 | 24 | { // Interrupt service routine to display the image according to the key pressed |
abarve9 | 1:6048138606a0 | 25 | value=touch.read(0x00); |
abarve9 | 1:6048138606a0 | 26 | value +=touch.read(0x01)<<8; // value of the key pressed is assigned to the variable 'value' |
XkLi | 0:c546b51ecf0b | 27 | |
abarve9 | 1:6048138606a0 | 28 | pc.printf("%d\r\n",value); |
abarve9 | 1:6048138606a0 | 29 | switch (value) { |
abarve9 | 1:6048138606a0 | 30 | case 0: |
abarve9 | 1:6048138606a0 | 31 | break; |
XkLi | 0:c546b51ecf0b | 32 | |
abarve9 | 1:6048138606a0 | 33 | case 1: { |
abarve9 | 1:6048138606a0 | 34 | select_pic[0] = true; |
abarve9 | 1:6048138606a0 | 35 | zoom = true; |
abarve9 | 1:6048138606a0 | 36 | break; |
abarve9 | 1:6048138606a0 | 37 | } |
abarve9 | 1:6048138606a0 | 38 | case 2: { |
abarve9 | 1:6048138606a0 | 39 | select_pic[3] = true; |
abarve9 | 1:6048138606a0 | 40 | zoom = true; |
abarve9 | 1:6048138606a0 | 41 | break; |
abarve9 | 1:6048138606a0 | 42 | } |
abarve9 | 1:6048138606a0 | 43 | case 4: { |
abarve9 | 1:6048138606a0 | 44 | select_pic[5] = true; |
abarve9 | 1:6048138606a0 | 45 | zoom = true; |
XkLi | 0:c546b51ecf0b | 46 | break; |
abarve9 | 1:6048138606a0 | 47 | } |
abarve9 | 1:6048138606a0 | 48 | case 8: { |
abarve9 | 1:6048138606a0 | 49 | select_pic[2] = true; |
abarve9 | 1:6048138606a0 | 50 | zoom = true; |
XkLi | 0:c546b51ecf0b | 51 | break; |
abarve9 | 1:6048138606a0 | 52 | } |
abarve9 | 1:6048138606a0 | 53 | case 16: { |
abarve9 | 1:6048138606a0 | 54 | select_pic[1] = true; |
abarve9 | 1:6048138606a0 | 55 | zoom = true; |
XkLi | 0:c546b51ecf0b | 56 | break; |
abarve9 | 1:6048138606a0 | 57 | } |
abarve9 | 1:6048138606a0 | 58 | case 32: { |
abarve9 | 1:6048138606a0 | 59 | select_pic[4] = true; |
abarve9 | 1:6048138606a0 | 60 | zoom = true; |
XkLi | 0:c546b51ecf0b | 61 | break; |
abarve9 | 1:6048138606a0 | 62 | } |
XkLi | 0:c546b51ecf0b | 63 | |
XkLi | 0:c546b51ecf0b | 64 | default: |
XkLi | 0:c546b51ecf0b | 65 | |
XkLi | 0:c546b51ecf0b | 66 | break; |
abarve9 | 1:6048138606a0 | 67 | } |
XkLi | 0:c546b51ecf0b | 68 | |
XkLi | 0:c546b51ecf0b | 69 | } |
XkLi | 0:c546b51ecf0b | 70 | |
abarve9 | 1:6048138606a0 | 71 | void open_dir(char *dir) |
abarve9 | 1:6048138606a0 | 72 | { // Opening the SD card directory and pushing the files into the directory |
XkLi | 0:c546b51ecf0b | 73 | DIR *dp; |
XkLi | 0:c546b51ecf0b | 74 | struct dirent *dirp; |
XkLi | 0:c546b51ecf0b | 75 | dp = opendir(dir); |
abarve9 | 1:6048138606a0 | 76 | while((dirp = readdir(dp)) != NULL) { |
abarve9 | 1:6048138606a0 | 77 | f.push_back(string(dirp->d_name)); |
XkLi | 0:c546b51ecf0b | 78 | } |
XkLi | 0:c546b51ecf0b | 79 | } |
XkLi | 0:c546b51ecf0b | 80 | |
abarve9 | 1:6048138606a0 | 81 | int main() |
abarve9 | 1:6048138606a0 | 82 | { |
abarve9 | 1:6048138606a0 | 83 | |
XkLi | 0:c546b51ecf0b | 84 | interrupt.fall(&fallInterrupt); |
XkLi | 0:c546b51ecf0b | 85 | interrupt.mode(PullUp); |
XkLi | 0:c546b51ecf0b | 86 | lcd.background(0xFFFFFF); |
XkLi | 0:c546b51ecf0b | 87 | lcd.foreground(0xFFFFFF); |
XkLi | 0:c546b51ecf0b | 88 | lcd.cls(); |
abarve9 | 1:6048138606a0 | 89 | open_dir("/sd"); |
XkLi | 0:c546b51ecf0b | 90 | led1 = 1; |
abarve9 | 1:6048138606a0 | 91 | |
XkLi | 0:c546b51ecf0b | 92 | while(1) { |
abarve9 | 1:6048138606a0 | 93 | |
abarve9 | 1:6048138606a0 | 94 | if(zoom) { |
XkLi | 0:c546b51ecf0b | 95 | __disable_irq(); |
abarve9 | 1:6048138606a0 | 96 | for(int i =0; i <f.size(); i++) { |
abarve9 | 1:6048138606a0 | 97 | if (select_pic[i] == true) { |
abarve9 | 1:6048138606a0 | 98 | file = f[i]; |
abarve9 | 1:6048138606a0 | 99 | select_pic[i] = false; |
abarve9 | 1:6048138606a0 | 100 | } |
XkLi | 0:c546b51ecf0b | 101 | } |
abarve9 | 1:6048138606a0 | 102 | |
abarve9 | 1:6048138606a0 | 103 | RGBApixel *Colors = new RGBApixel [2]; |
abarve9 | 1:6048138606a0 | 104 | file = "/sd/" + file; |
abarve9 | 1:6048138606a0 | 105 | lcd.background(0x000000); |
abarve9 | 1:6048138606a0 | 106 | lcd.foreground(0x000000); |
abarve9 | 1:6048138606a0 | 107 | lcd.cls(); |
abarve9 | 1:6048138606a0 | 108 | ReadBMPFromFile(file.c_str(), Colors, &lcd); // Function to display image on the nokia LCD. Refer myBMP.cpp for complete functionality. |
abarve9 | 1:6048138606a0 | 109 | |
abarve9 | 1:6048138606a0 | 110 | |
abarve9 | 1:6048138606a0 | 111 | zoom = false; |
XkLi | 0:c546b51ecf0b | 112 | __enable_irq(); |
XkLi | 0:c546b51ecf0b | 113 | } |
abarve9 | 1:6048138606a0 | 114 | |
XkLi | 0:c546b51ecf0b | 115 | led1 = !led1; |
abarve9 | 1:6048138606a0 | 116 | wait(0.2); |
XkLi | 0:c546b51ecf0b | 117 | } |
XkLi | 0:c546b51ecf0b | 118 | } |